Log entire REPL prompt to SD
Log entire REPL prompt to SD
Is there a way to log the entire REPL prompt to SD? I want to log the entire prompt rather than just an individual event/error. I am using the PYBD-SF6W with an SD card.
Re: Log entire REPL prompt to SD
Can you explain what you mean by "log the entire REPL prompt".
If what you mean is something like: create a text file, the contents of which look exactly like the interactive REPL session, then yes you can do this with dupterm.
I haven't tested this, but the rough idea is to make a stream that you pass to os.dupterm, and every time MicroPython writes to stdout, it also will be sent to your stream. See https://github.com/micropython/micropyt ... rt_repl.py for an example of how we use this to make a REPL over BLE.
This is untested, but this is a sketch of a stream that only handles writes and could log all the writes to a file, and how to register it with dupterm.
If what you mean is something like: create a text file, the contents of which look exactly like the interactive REPL session, then yes you can do this with dupterm.
I haven't tested this, but the rough idea is to make a stream that you pass to os.dupterm, and every time MicroPython writes to stdout, it also will be sent to your stream. See https://github.com/micropython/micropyt ... rt_repl.py for an example of how we use this to make a REPL over BLE.
This is untested, but this is a sketch of a stream that only handles writes and could log all the writes to a file, and how to register it with dupterm.
Code: Select all
import os
class LoggingStream(io.IOBase):
def __init__(self, path):
# open file
def read(self, sz=None):
return None
def readinto(self, buf):
return 0
def ioctl(self, op, arg):
return 0
def write(self, buf):
# write buf to file
os.dupterm(LoggingStream(path))
Re: Log entire REPL prompt to SD
Thank you providing this information. I am a bit novice with respect to micropython, so I was wondering if you might be able to show me how this could be implemented? I read through the link you attached, but I'm not sure how much of that code would translate to my issue.
Re: Log entire REPL prompt to SD
Basically, I am experiencing errors with my device (which is being used to control a couple of Dynamixel motors) exclusively when I am running from an external power supply and not connected to my PC via the microUSB port. So when an error/failure occurs, I cannot view it in real time since I cannot see the REPL prompt. So, I want to record/store on SD everything that would have been printed to the REPL prompt had I been connected via microUSB to the PC.
Re: Log entire REPL prompt to SD
Is there the ability to view the REPL prompt wirelessly on the PYBD-SF6W? I am noticing that an error gets returned on my PYBD-SF6W saying that os module has no module dupterm. I've tried both os and uos. I noticed that others had a similar issue on ESP32 boards: viewtopic.php?t=3997.
Re: Log entire REPL prompt to SD
With WebREPL, yes.
That's weird. Can you check what firmware version you have?
If you connect to the REPL, you should see something like (except likely a different build of v1.13).
Code: Select all
MPY: sync filesystems
MPY: soft reboot
MicroPython v1.13-160-ga9ed9e58d-dirty on 2020-11-04; PYBD-SF6W with STM32F767IIK
Type "help()" for more information.
>>> import os
>>> os.dupterm(None)
Yeah, this sounds like a good idea and definitely should be possible.kbrenner wrote: ↑Wed Nov 04, 2020 7:42 pmBasically, I am experiencing errors with my device (which is being used to control a couple of Dynamixel motors) exclusively when I am running from an external power supply and not connected to my PC via the microUSB port. So when an error/failure occurs, I cannot view it in real time since I cannot see the REPL prompt. So, I want to record/store on SD everything that would have been printed to the REPL prompt had I been connected via microUSB to the PC.
The other simpler option is just to use try/except handlers and write any exception details directly to a file:
Code: Select all
try:
...
except ...:
with open('error.log', 'w') as f:
f.write(...)
Here's a full example: https://gist.github.com/jimmo/a96f8cde2 ... 15c85e25ddkbrenner wrote: ↑Wed Nov 04, 2020 7:42 pmThank you providing this information. I am a bit novice with respect to micropython, so I was wondering if you might be able to show me how this could be implemented? I read through the link you attached, but I'm not sure how much of that code would translate to my issue.
Code: Select all
>>>
MPY: sync filesystems
MPY: soft reboot
MicroPython v1.13-160-ga9ed9e58d-dirty on 2020-11-04; PYBD-SF6W with STM32F767IIK
Type "help()" for more information.
>>> 1+1
2
>>> import log_sd
>>> 2+2
4
>>> log_sd.enable_logging('stdout.log')
>>> 3+3
6
>>> print('hello')
hello
>>> log_sd.disable_logging()
>>>
Code: Select all
$ pyboard --device /dev/ttyACM0 -f cat stdout.log
cat :stdout.log
>>> 3+3
6
>>> print('hello')
hello
>>> log_sd.disable_logging()
Re: Log entire REPL prompt to SD
What I normally do in a scenario like this is to log to a UART, which can also be done by using os.dupterm
Re: Log entire REPL prompt to SD
Thanks. I'm able to access the REPL prompt from WebREPL and write various python commands that I then see show up on the local REPL prompt; however, I do not see it working in the opposite direction. For example, I have a main script that looks like:
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
count = 0
while(False):
count = count + 1
if count == 100000:
print('hello world')
count = 0
However, I do not see the print outs of 'hello world' on the WebREPL. I do see them on my local REPL.
Also, I am running v1.12.
Additionally, I have written try/except handlers; however, occasionally the Pyboard will show errors in the REPL prompt that don't come from the try/except such as:
failed 0 3 4 c (or some other combination of numbers/letters)
some memoryview error
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
count = 0
while(False):
count = count + 1
if count == 100000:
print('hello world')
count = 0
However, I do not see the print outs of 'hello world' on the WebREPL. I do see them on my local REPL.
Also, I am running v1.12.
Additionally, I have written try/except handlers; however, occasionally the Pyboard will show errors in the REPL prompt that don't come from the try/except such as:
failed 0 3 4 c (or some other combination of numbers/letters)
some memoryview error