micropython / webrepl

WebREPL client and related tools for MicroPython
MIT License
633 stars 297 forks source link

A python library talking to WebREPL. #67

Closed xg590 closed 1 year ago

xg590 commented 3 years ago

I prototyped a python library for my raspberry pi that can talk to WebREPL on an ESP8266 dev board. This helps me do home automation. Is this helpful?

beyonlo commented 2 years ago

Hi, great work. Do you plan to support the SSL (secure websocket)?

xg590 commented 2 years ago

Hi, great work. Do you plan to support the SSL (secure websocket)?

I don't have a WebREPL service using wss so I don't intend to play with SSL.

LesniakM commented 2 years ago

@xg590 Thank you very much for sharing pyWebREPL! It's super useful!

I have encountered one problem though. I've got micropython app on esp8266 which continuously print's some data.

I can read them without problem with browser webrepl, but I cannot achieve that with your lib. I've tried to use while loops on my PC app with webrepl.recv(), but after running script on ESP, I only got >>> and silence. Could you give me a tip how to workaround that? I just need to continuously receive data on PC, that ESP prints.

xg590 commented 2 years ago

@LesniakM

webrepl = WEBREPL(host=sys.argv[1], password='123456')

code = ''' while 1: print("You should not use pyWebREPL like this") '''

for cmd in code.splitlines(): webrepl.send(cmd) webrepl.send('\r') print(webrepl.recv())

webrepl.close()

* Do this

from pyWebREPL import WEBREPL

webrepl = WEBREPL(host=sys.argv[1], password='123456')

code = ''' print("You should use pyWebREPL like this") '''

while 1: webrepl.send(code) webrepl.send('\r') print(webrepl.recv())

webrepl.close()

LesniakM commented 2 years ago

@xg590 Thank you for very fast and detailed reply.

I will share code and raise issue in your repo then.

"Third, you may wrongfully use WebREPL." - That's probably main issue here. I do loop on PC, pretty much like you posted as "Do this", but I do also loop on ESP. My script was intended to run continously, communicate by serial with other device and printout parsed data. That's works perfectly with micropython browser webrepl, but with your webrepl there is nothing printed until script is running and then all data is received at once after script is terminated. "The third action (printing) keeps running." - That's correct. But somehow browser webrepl print data in terminal in real time. Is it possible to achieve with your script?

Anyway, again thank you for your reply and your time, I really appreciate that. I will raise an issue in your repo in the evening with much more details and all the code.