Can I somehow know in my script when someone is connected via webrepl?
My use case is a sensor node that measures and then deep sleeps for a minute, and repeats. I would like to check if someone has connected via webrepl before the node goes to deep sleeps and if there is a connection then stop and wait for user input. For example update script or something.
(using ESP8266 if that matters.)
Can a python script know when webrepl is open?
Re: Can a python script know when webrepl is open?
Hi, i'm having similar problem with a sensor board in development.
I use the following approach to get into webrepl when i need to.
I have connected Pin 12 to ground normally and when i need to update the board i connect the pin to high.
This would not work if the sensor is no longer accessible.
I use the following approach to get into webrepl when i need to.
I have connected Pin 12 to ground normally and when i need to update the board i connect the pin to high.
Code: Select all
flag = Pin(12, Pin.IN)
if flag.value() == 1:
print("starting webrepl")
import webrepl as wr
wr.start()
else:
print("importing _main")
import _main
Re: Can a python script know when webrepl is open?
That's similar how I currently do it. But it does requires to physically go to the sensor, which I would very much like to avoid:)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can a python script know when webrepl is open?
Is it not possible to use the webrepl to set a global boolean which is tested by the script before it goes to sleep?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Can a python script know when webrepl is open?
It should be relatively easy to tell, if someone is connected, by calling uos.dupterm(). That's what webrepl does. If someone is connected, it will return True. That assume showever, that the only two possible REPL connections are USB and webrepl.
Update: Just tested that. On REPL,returns False if no one is connected, and True if someone is connected. So in your script you can simply use:
to tell. But on the other hand - if your device is at sleep, no one can connect anyhow. So the only chance to connect would be during the short measuring time slot.
Update: Just tested that. On REPL,
Code: Select all
not not uos.dupterm()
Code: Select all
if uos.dupterm():
# do not sleep
Re: Can a python script know when webrepl is open?
I'll have to test that, thanks.Roberthh wrote:It should be relatively easy to tell, if someone is connected, by calling uos.dupterm(). That's what webrepl does. If someone is connected, it will return True. That assume showever, that the only two possible REPL connections are USB and webrepl.
Update: Just tested that. On REPL,returns False if no one is connected, and True if someone is connected. So in your script you can simply use:Code: Select all
not not uos.dupterm()
to tell.Code: Select all
if uos.dupterm(): # do not sleep
True, this is just some theoretical thinking at this stage.Roberthh wrote: But on the other hand - if your device is at sleep, no one can connect anyhow. So the only chance to connect would be during the short measuring time slot.