Page 1 of 1
Send user message after webrepl connection
Posted: Thu Jun 10, 2021 5:18 am
by Patrice
Hi,
I want to send some user and informations messages on WebREPL as soon as the connection is done, just after the message "WebREPL connected".
Is it possible ?
Thanks
Re: Send user message after webrepl connection
Posted: Thu Jun 10, 2021 7:29 am
by davef
Code: Select all
webrepl.start()
utime.sleep(20)
print('hi there')
The problem I see is that you need the user to login first and before the 20 seconds are up! Maybe, there is a way that you can login with a stored or no password.
Re: Send user message after webrepl connection
Posted: Thu Jun 10, 2021 8:22 pm
by marcidy
If you look at extmod/webrepl.py, you'll see how the webrepl is set up with a callback on connection.
Since this is just python code, you can duplicate it into you're own version of the webrepl, and you won't need to recompile the firmware to modify it.
just copy extmod/webrepl.py to your own module, let's say "mywebrepl". Then you can use
Code: Select all
>>> import mywebrepl
>>> mywebrepl.start(password="whatever")
Then you can modify the accept_conn to send whatever you'd to the websocket on connection after the handshake.
Re: Send user message after webrepl connection
Posted: Fri Jun 11, 2021 6:20 am
by Patrice
Tanks, I'll try that !