Adhoc WiFi broadcast?
-
I was hopeful of using a simple http server to send diagnostic messages from code running on a gpy to a browser on my mobile phone via the default adhoc network the gpy sets up on power up. The idea works but the code on the gpy stops running if the phone looses it's connection to the gpy wlan. Is there some sort of wifi broadcast mode whereby the gpy could belt out diagnostics regardless of if a device is connected or not?
-
That's the problem, I tried to use sockets but the wrong way. I think I should be trying for a UDP broadcast? So the diagnostics go out regardless of the phone being connected or not
import socket; import time addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] s = socket.socket(); s.bind(addr); s.listen(1) print('listening on', addr) while 1: cl, addr = s.accept() print('client connected from', addr) cl.send('a diagnostic print \r') time.sleep(2) cl.send('another diagnostic print \r') time.sleep(2) cl.close()
If the phone looses the adhoc wifi connection the program just sits there waiting for a client to connect.
-
@kjm Are you sure the code on the GPy actually stops? That would seem surprising.
How do you "send" the messages from the GPy to the browser? Unless you are using web sockets (not sure if there's an implementation for this on micropython?), it's more probably the browser polling the GPy, and you just need to make sure it continues to do so after a disconnect/reconnect.
Can you share details of you actual setup, including the relevant code, and any errors, logs and traces (both on the GPy and in the browser)?