Send user message after webrepl connection

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Patrice
Posts: 13
Joined: Mon Feb 10, 2020 3:34 am

Send user message after webrepl connection

Post by Patrice » Thu Jun 10, 2021 5:18 am

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

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Send user message after webrepl connection

Post by davef » Thu Jun 10, 2021 7:29 am

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.

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Send user message after webrepl connection

Post by marcidy » Thu Jun 10, 2021 8:22 pm

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.

Patrice
Posts: 13
Joined: Mon Feb 10, 2020 3:34 am

Re: Send user message after webrepl connection

Post by Patrice » Fri Jun 11, 2021 6:20 am

Tanks, I'll try that !

Post Reply