|
9 | 9 | status = True |
10 | 10 | led = Pin("LED", Pin.OUT) |
11 | 11 |
|
12 | | -async def example_func(writer, param1, param2): |
| 12 | +async def example_func(response, param1, param2): |
13 | 13 | print("example_func") |
14 | 14 | print("param1: " + param1) |
15 | 15 | print("param2: " + param2) |
16 | | - writer.write('HTTP/1.0 200 OK\r\nContent-type: application/json\r\n\r\n') |
17 | | - response = json.dumps({"param1": param1, "param2": param2}) |
18 | | - writer.write(response) |
19 | | - await writer.drain() |
20 | | - await writer.wait_closed() |
| 16 | + response_string = json.dumps({"param1": param1, "param2": param2}) |
| 17 | + await response.send("200 OK", "application/json", response_string) |
| 18 | + |
21 | 19 |
|
22 | 20 |
|
23 | | -async def send_status(writer): |
24 | | - writer.write('HTTP/1.0 200 OK\r\nContent-type: application/json\r\n\r\n') |
| 21 | +async def send_status(response): |
25 | 22 | # send boolean status and number frequency |
26 | | - response = json.dumps({"status": status, "delay": delay}) |
27 | | - writer.write(response) |
28 | | - await writer.drain() |
29 | | - await writer.wait_closed() |
| 23 | + response_string = json.dumps({"status": status, "delay": delay}) |
| 24 | + await response.send("200 OK", "application/json", response_string) |
| 25 | + |
30 | 26 |
|
31 | | -async def set_delay(writer, new_delay): |
| 27 | +async def set_delay(response, new_delay): |
32 | 28 | print("new delay: " + new_delay) |
33 | 29 | global delay |
34 | 30 | delay = float(new_delay) |
35 | | - await send_status(writer) |
| 31 | + await send_status(response) |
36 | 32 |
|
37 | | -async def stop_flashing(writer): |
| 33 | +async def stop_flashing(response): |
38 | 34 | global status |
39 | 35 | status = False |
40 | | - await send_status(writer) |
| 36 | + await send_status(response) |
41 | 37 |
|
42 | | -async def start_flashing(writer): |
| 38 | +async def start_flashing(response): |
43 | 39 | global status |
44 | 40 | status = True |
45 | | - await send_status(writer) |
| 41 | + await send_status(response) |
46 | 42 |
|
47 | 43 | async def main(): |
48 | 44 | await server.start_server() |
|
0 commit comments