Skip to content

Commit d8114d6

Browse files
committed
add ovo_robot.py
1 parent 03adc2f commit d8114d6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

11.app/ovo_robot.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import wifi
2+
wifi.try_connect()
3+
4+
# 返回数据response header
5+
headers = {'Access-Control-Allow-Origin': '*'}
6+
7+
from microbit import *
8+
from microWebSrv import MicroWebSrv
9+
10+
@MicroWebSrv.route('/get_temp')
11+
def _httpHandlerTestGet(httpClient, httpResponse):
12+
params = httpClient.GetRequestQueryParams()
13+
tmp = temperature() # get temperature ℃
14+
obj = {
15+
'temperature': str(tmp),
16+
}
17+
httpResponse.WriteResponseJSONOk(obj=obj, headers=headers)
18+
19+
@MicroWebSrv.route('/SAD')
20+
def _httpHandlerTestGet(httpClient, httpResponse):
21+
params = httpClient.GetRequestQueryParams()
22+
display.show(Image.SAD)
23+
24+
@MicroWebSrv.route('/scroll')
25+
def _httpHandlerTestGet(httpClient, httpResponse):
26+
params = httpClient.GetRequestQueryParams()
27+
display.scroll(str(params['text']))
28+
29+
if __name__ == '__main__':
30+
if 'srv' in locals():
31+
reset()
32+
pin13.write_digital(0)
33+
import time
34+
while True:
35+
time.sleep(2)
36+
if wifi.isconnected():
37+
srv = MicroWebSrv(webPath='www/')
38+
srv.Start(True)
39+
pin13.write_digital(1)
40+
else:
41+
pin13.write_digital(0)

0 commit comments

Comments
 (0)