Skip to content

Commit

Permalink
add ovo_robot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
junhuanchen committed Apr 20, 2019
1 parent 03adc2f commit d8114d6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 11.app/ovo_robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import wifi
wifi.try_connect()

# 返回数据response header
headers = {'Access-Control-Allow-Origin': '*'}

from microbit import *
from microWebSrv import MicroWebSrv

@MicroWebSrv.route('/get_temp')
def _httpHandlerTestGet(httpClient, httpResponse):
params = httpClient.GetRequestQueryParams()
tmp = temperature() # get temperature ℃
obj = {
'temperature': str(tmp),
}
httpResponse.WriteResponseJSONOk(obj=obj, headers=headers)

@MicroWebSrv.route('/SAD')
def _httpHandlerTestGet(httpClient, httpResponse):
params = httpClient.GetRequestQueryParams()
display.show(Image.SAD)

@MicroWebSrv.route('/scroll')
def _httpHandlerTestGet(httpClient, httpResponse):
params = httpClient.GetRequestQueryParams()
display.scroll(str(params['text']))

if __name__ == '__main__':
if 'srv' in locals():
reset()
pin13.write_digital(0)
import time
while True:
time.sleep(2)
if wifi.isconnected():
srv = MicroWebSrv(webPath='www/')
srv.Start(True)
pin13.write_digital(1)
else:
pin13.write_digital(0)

0 comments on commit d8114d6

Please sign in to comment.