from microbit import *
import radio
radio.config(group=17)
compass.calibrate()
radio.on()
while True:
if button_a.was_pressed():
display.scroll(compass.get_field_strength())
if compass.get_field_strength() < 100000:
display.show(Image.DIAMOND_SMALL)
radio.send('door open')
else:
display.clear()
radio.send('door closed')
sleep(2000)
报警端代码:
from microbit import *
import music
import radio
radio.config(group=17)
radio.on()
while True:
message = radio.receive()
if message:
if message == 'door open':
display.show(Image.NO)
music.play(["C4:4"])
if message == 'door closed':
display.show(Image.YES)
# Python uses nanoteslas to measure magnetism.
# Experiment with different numbers depending on the
# strength of your magnet, which you can read by
# pressing button A.
from microbit import *
while True:
if button_a.was_pressed():
display.scroll(compass.get_field_strength())
if compass.get_field_strength() < 200000:
display.show(Image.ANGRY)
确保wlansvc服务启动中,没有无线网络的台式机,该服务未启动 $ sc query wlansvc | findstr STATE STATE : 4 RUNNING
查看曾经连接过的无线网络 $ netsh wlan show profiles … User profiles All User Profile : any All User Profile : some All User Profile : meeting_5GHz All User Profile : meeting_2.4GHz
若wlansvc服务未启动,上述命令报错 $ netsh wlan show profiles The Wireless AutoConfig Service (wlansvc) is not running.
After flashing connect to “PowerControlESP | Offline” pass is “PowerControlPass” then go to 192.168.4.1 (WI-Fi manager) and connect to your Wi-Fi router.
Power server is at 192.168.x.x:8089 (port is 8089)
Very unusual authorization that I implemented
If it says “The file exists, but you are not authorized!” – is a simple safety feature that I implemented, so in order to access files you need to go to a secret URL first http://192.168.x.x:8089/me (you can program another one) When you go to http://192.168.x.x:8089/me it puts a cookie in your browser and you become an authorized user
to make it work right set it to false in the sketch
// set it to false, and then get auth cookie by going to 192.168.x.x:8089/me
bool PublicAccess = true; // authorization