Files not showing up
siliconwitch opened this issue · 6 comments
The main.py file is uploaded but doesn't show up.
Full log:
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬇️: \r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>
Raw REPL ⬆️: import device;print(device.VERSION)\x04
Raw REPL ⬇️: OKv23.150.1818\r\n��>
Raw REPL ⬆️: print(device.GIT_REPO);del(device)\x04
Raw REPL ⬇️: OKhttps://github.com/brilliantlabsAR/monocle-micropython\r\n��>
Raw REPL ⬆️: import fpga;print(fpga.read(2,12));del(fpga)\x04
Raw REPL ⬇️: OKb'v23.110.0855'\r\n��>
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Raw REPL ⬇️: \r\nMicroPython v1.20.0-117-ged7a3b11d on 2023-05-30; Monocle on nRF52832\r\nType "help()" for more information.\r\n>>>
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬇️: \r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>
Raw REPL ⬆️: import os,ujson;\nd="/"\nl =[]\nif os.stat(d)[0] & 0x4000:\n for f in os.ilistdir(d):\n if f[0] not in ('.', '..'):\n l.append({"name":f[0],"file":not f[1] & 0x4000})\nprint(ujson.dumps(l))\ndel(os,l,d)\x04
Raw REPL ⬇️: OK[]\r\n��>
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Raw REPL ⬇️: \r\nMicroPython v1.20.0-117-ged7a3b11d on 2023-05-30; Monocle on nRF52832\r\nType "help()" for more information.\r\n>>>
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬇️: \r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>
Raw REPL ⬆️: f=open('main.py', 'w');f.write('''import bluetooth\nimport time\nimport urandom\n\n\ndef choices(rng, k=1):\n l = []\n for _ in range(k):\n l.append(urandom.choice(rng))\n return l\n\n\nwhile True:\n if bluetooth.connected():\n mtu = bluetooth.max_length()\n for i in range(10):\n choices(range(0, 256), k=mtu)\n''');f.close()\x04
Raw REPL ⬇️: OK��>
Raw REPL ⬆️: \x03\x04
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Raw REPL ⬇️: OK\r\nTraceback (most recent call last):\r\n File "main.py", in <module>\r\n File "main.py", in choices\r\nKeyboardInterrupt: \r\nraw REPL; CTRL-B to exit\r\n>\r\nMicroPython v1.20.0-117-ged7a3b11d on 2023-05-30; Monocle on nRF52832\r\nType "help()" for more information.\r\n>>>
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬇️: \r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>
Raw REPL ⬆️: f=open('main.py', 'w');f.write('''import bluetooth\nimport time\nimport urandom\n\n\ndef choices(rng, k=1):\n l = []\n for _ in range(k):\n l.append(urandom.choice(rng))\n return l\n\n\nwhile True:\n if bluetooth.connected():\n mtu = bluetooth.max_length()\n start = time.ticks_ms()\n i = 0\n while i < 10:\n try:\n bluetooth.send(choices(range(0, 256), k=mtu))\n i += 1\n except:\n pass\n end = time.ticks_ms()\n print(f"Sent {i-1*mtu} bytes in {time.ticks_diff(start , ed)}")\n''');f.close()\x04
Raw REPL ⬇️: OK��>
Raw REPL ⬆️: \x03\x04
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬆️: import os,ujson;\nd="/"\nl =[]\nif os.stat(d)[0] & 0x4000:\n for f in os.ilistdir(d):\n if f[0] not in ('.', '..'):\n l.append({"name":f[0],"file":not f[1] & 0x4000})\nprint(ujson.dumps(l))\ndel(os,l,d)\x04
Raw REPL ⬆️: f=open('main.py', 'w');f.write('''import bluetooth\nimport time\nimport urandom\n\n\ndef choices(rng, k=1):\n l = []\n for _ in range(k):\n l.append(urandom.choice(rng))\n return l\n\n\nwhile True:\n if bluetooth.connected():\n mtu = bluetooth.max_length()\n start = time.ticks_ms()\n i = 0\n while i < 10:\n try:\n bluetooth.send(choices(range(0, 256), k=mtu))\n i += 1\n except:\n pass\n end = time.ticks_ms()\n print(f"Sent {i-1*mtu} bytes in {time.ticks_diff(start , end)}")\n''');f.close()\x04
Raw REPL ⬆️: f=open('main.py', 'w');f.write('''import bluetooth\nimport time\nimport urandom\n\n\ndef choices(rng, k=1):\n l = []\n for _ in range(k):\n l.append(urandom.choice(rng))\n return l\n\n\nwhile True:\n if bluetooth.connected():\n mtu = bluetooth.max_length()\n start = time.ticks_ms()\n i = 0\n while i < 10:\n try:\n bluetooth.send(choices(range(0, 256), k=mtu))\n i += 1\n except:\n pass\n end = time.ticks_ms()\n print(f"Sent {i-1*mtu} bytes in {time.ticks_diff(start , end)}")\n''');f.close()\x04
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Raw REPL ⬆️: \x03\x04
Raw REPL ⬆️: \x03\x04
Leaving raw REPL mode
Leaving raw REPL mode
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬆️: import os\ndef md(p):\n c=""\n for d in p.split("/"):\n c += "/"+d\n try:\n os.mkdir(c)\n except:\n pass\nmd('');del(os,md)\x04
Raw REPL ⬆️: f=open('/main.py', 'w');f.write('''import bluetooth\nimport time\nimport urandom\n\n\ndef choices(rng, k=1):\n l = []\n for _ in range(k):\n l.append(urandom.choice(rng))\n return l\n\n\nwhile True:\n if bluetooth.connected():\n mtu = bluetooth.max_length()\n start = time.ticks_ms()\n i = 0\n while i < 10:\n try:\n bluetooth.send(choices(range(0, 256), k=mtu))\n i += 1\n except:\n pass\n end = time.ticks_ms()\n print(f"Sent {i-1*mtu} bytes in {time.ticks_diff(start , end)}")\n''');f.close()\x04
Raw REPL ⬆️: \x03\x04
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
Entering raw REPL mode
Raw REPL ⬆️: \x03\x01
Raw REPL ⬆️: import os,ujson;\nd="/"\nl =[]\nif os.stat(d)[0] & 0x4000:\n for f in os.ilistdir(d):\n if f[0] not in ('.', '..'):\n l.append({"name":f[0],"file":not f[1] & 0x4000})\nprint(ujson.dumps(l))\ndel(os,l,d)\x04
Leaving raw REPL mode
Raw REPL ⬆️: \x03\x02
I might have caused this bug by blocking the bluetooth 🤔
import bluetooth
import time
import urandom
def choices(rng, k=1):
l = []
for _ in range(k):
l.append(urandom.choice(rng))
return l
while True:
if bluetooth.connected():
mtu = bluetooth.max_length()
start = time.ticks_ms()
i = 0
while i < 10:
try:
bluetooth.send(choices(range(0, 256), k=mtu))
i += 1
except:
pass
end = time.ticks_ms()
print(f"Sent {i-1*mtu} bytes in {time.ticks_diff(start , end)}")
I think I found a way to brick Monocle from micropython @josuah 😅
This was a MicroPython bug. Issue at micropython/micropython#11682
It appear to be a desired feature of MicroPython
Should we implement our own Ctrl-C? Or maybe a separate Ctrl-\
that always causes a full firmware reset when hit, directly caught on the bluetooth driver before it reaches MicroPython?
That way, regardless what happens on MicroPython level, we could always recover.
Well, a full firmware reset doesn't work either if it's a saved python file. Ctrl+/ could work, if there's a way we can break the execution loop and return to the REPL
If we try to make use of a keyboard interrupt, we would have implemented the same behavior as Ctrl+C, and would be back to square 1, I suppose...
So maybe we would have to fork micropython or maybe patch it?
Or could we implement a fail-safe reboot mechanism that skips startup files execution.
A bit how in Linux, if something goes wrong in the boot process, passing init=/bin/sh
to the kernel command line gives a way to fix it manually.
Open to suggestions!