webrepl icon indicating copy to clipboard operation
webrepl copied to clipboard

A python library talking to WebREPL.

Open xg590 opened this issue 3 years ago • 5 comments

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?

xg590 avatar Nov 07 '21 10:11 xg590

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

beyonlo avatar Jan 13 '22 22:01 beyonlo

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.

xg590 avatar Jan 18 '22 19:01 xg590

@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.

LesniakM avatar Sep 04 '22 19:09 LesniakM

@LesniakM

  • First, If you got problem, welcome to raise the issue in my repo instead of here.
  • Second, please share you code so I can repeat the problem.
  • Third, you may wrongfully use WebREPL. REPL stands for read-eval-print-loop. "continuously print's some data" means REPL never reached the fourth stage "loop". The third action (printing) keeps running.
  • You shall do a looping on your PC instead of ESP8266.
  • Don't do this
from pyWebREPL import WEBREPL

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()

xg590 avatar Sep 05 '22 06:09 xg590

@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.

LesniakM avatar Sep 05 '22 08:09 LesniakM