@@ -213,7 +213,7 @@ its associated RAM saving.
213
213
This repository is a python package, consequently on the client the directory
214
214
structure must be retained. The following installs all demos on the target.
215
215
216
- Clone the repository after moving to a directory of your choice:
216
+ On your PC move to a directory of your choice and clone the repository there :
217
217
```
218
218
git clone https://github.com/peterhinch/micropython-iot
219
219
```
@@ -381,7 +381,7 @@ class App:
381
381
async def start (self ):
382
382
await self .cl # Wait until client has connected to server
383
383
asyncio.create_task(self .reader())
384
- asyncio.create_task( self .writer())
384
+ await self .writer() # Wait forever
385
385
386
386
def state (self , state ): # Callback for change in connection status
387
387
print (" Connection state:" , state)
@@ -405,9 +405,14 @@ class App:
405
405
def close (self ):
406
406
self .cl.close()
407
407
408
- app = App(True )
408
+ app = None
409
+ async def main ():
410
+ global app # For closure by finally clause
411
+ app = App(True )
412
+ await app.start() # Wait forever
413
+
409
414
try :
410
- loop.run_forever( )
415
+ asyncio.run(main() )
411
416
finally :
412
417
app.close() # Ensure proper shutdown e.g. on ctrl-C
413
418
asyncio.new_event_loop()
@@ -489,7 +494,7 @@ awaiting incoming data.
489
494
490
495
When an application instantiates a ` Client ` it attemps to connect to WiFi and
491
496
then to the server. Initial connection is handled by the following ` Client `
492
- asynchronous bound methods:
497
+ asynchronous bound methods (which may be modified by subclassing) :
493
498
494
499
1 . ` bad_wifi ` No args.
495
500
2 . ` bad_server ` No args. Awaited if server refuses an initial connection.
@@ -579,12 +584,15 @@ class App:
579
584
await self .conn.write(json.dumps(self .data)) # May pause in event of outage
580
585
await asyncio.sleep(5 )
581
586
582
- def run ():
587
+ async def main ():
583
588
clients = {1 , 2 , 3 , 4 }
584
589
apps = [App(n) for n in clients] # Accept 4 clients with ID's 1-4
590
+ await server.run(clients, True , local.PORT , local.TIMEOUT ) # Verbose
591
+
592
+ def run ():
585
593
try :
586
- asyncio.run(server.run(clients, False , local. PORT , local. TIMEOUT ))
587
- except KeyboardInterrupt : # Skip this if you want a traceback
594
+ asyncio.run(main( ))
595
+ except KeyboardInterrupt : # Delete this if you want a traceback
588
596
print (' Interrupted' )
589
597
finally :
590
598
server.Connection.close_all()
0 commit comments