From d8114d62fe3c2f4cf02380cafcad616e4bbe0683 Mon Sep 17 00:00:00 2001 From: Juwan Date: Sat, 20 Apr 2019 14:33:16 +0800 Subject: [PATCH] add ovo_robot.py --- 11.app/ovo_robot.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 11.app/ovo_robot.py diff --git a/11.app/ovo_robot.py b/11.app/ovo_robot.py new file mode 100644 index 0000000..82f963f --- /dev/null +++ b/11.app/ovo_robot.py @@ -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) \ No newline at end of file