Can not flash SonOff with MP

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
hansp@kollerod.com
Posts: 2
Joined: Sun Feb 10, 2019 4:43 pm

Can not flash SonOff with MP

Post by hansp@kollerod.com » Sun Feb 10, 2019 5:21 pm

Hello Forum
This is my first post on this forum. I have problem flashing the Micropytyhon firmware to a SonOff board with a ESP8266 with 1M flash
running the flowing commands on a Raspberry pi 3+

Erasing
esptool.py --port /dev/ttyUSB0 erase_flash
Returns
esptool.py v2.6
Serial port /dev/ttyUSB0
Connecting........_____....._
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: b4:e6:2d:24:9f:74
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 2.6s
Hard resetting via RTS pin...

Flashing
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20190125-v1.10.bin
Returns
190125-v1.10.bin
esptool.py v2.6
Serial port /dev/ttyUSB0
Connecting........_
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: b4:e6:2d:24:9f:74
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 1MB
Flash params set to 0x0020
Compressed 615388 bytes to 399928...
Wrote 615388 bytes (399928 compressed) at 0x00000000 in 10.8 seconds (effective 454.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...

Starting rshell
rshell --buffer-size=30 -p /dev/ttyUSB0
Returns
Using buffer-size of 30
Connecting to /dev/ttyUSB0 (buffer-size 30)...
Testing if ubinascii.unhexlify exists ... b'\x00'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1249, in connect
ip_address = socket.gethostbyname(port)
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/rshell", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/rshell/command_line.py", line 4, in main
rshell.main.main()
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 2815, in main
real_main()
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 2777, in real_main
connect(args.port, baud=args.baud, wait=args.wait, user=args.user, password=args.password)
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1255, in connect
connect_serial(port, baud=baud, wait=wait)
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1279, in connect_serial
dev = DeviceSerial(port, baud, wait)
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1537, in __init__
Device.__init__(self, pyb)
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1333, in __init__
unhexlify_exists = self.remote_eval(test_unhexlify)
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1453, in remote_eval
return eval(self.remote(func, *args, **kwargs))
File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1431, in remote
self.pyb.enter_raw_repl()
File "/usr/local/lib/python3.5/dist-packages/rshell/pyboard.py", line 187, in enter_raw_repl
raise PyboardError('could not enter raw repl')
rshell.pyboard.PyboardError: could not enter raw repl

Doing exactly the same on a ESP-12F here I get the same result but the next time I start rshell everything works byt not on the SonOff board
is there a explanation for his and is it possible to correct it?
Thanks Hans

theMusicMan
Posts: 23
Joined: Mon Feb 11, 2019 12:16 am

Re: Can not flash SonOff with MP

Post by theMusicMan » Mon Feb 11, 2019 12:22 am

This is very interesting, as on the exact same day, I get the very same error, though not on a Sonoff, but when trying to flash MicroPython to an ESP8266 using my RPi 3B+

I have looked through the main.py file in rshell, and I see several references to unhexlify, but I am not a programmer and can't seem to fathom out why the ubinascii.unhexlify is not being found.

I have even done a

pip install micropython-cpython-ubinascii==0.0

... just in case, alas no joy. Hoping someone can help.

John

User avatar
dhylands
Posts: 3113
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Can not flash SonOff with MP

Post by dhylands » Mon Feb 11, 2019 3:34 am

I would first verify that you can connect using a regular serial comm program like picocom.

You can then also verify that ubinascii.unhexlify is available.

theMusicMan
Posts: 23
Joined: Mon Feb 11, 2019 12:16 am

Re: Can not flash SonOff with MP

Post by theMusicMan » Mon Feb 11, 2019 8:06 am

[quote=dhylands post_id=34039 time=1549856088 user_id=81]
I would first verify that you can connect using a regular serial comm program like picocom.

You can then also verify that ubinascii.unhexlify is available.
[/quote]

OK, thanks. I am not a coder, So I installed picocom, and get this when I run it... not right ?

[code]picocom /dev/ttyUSB0
picocom v1.7

port is : /dev/ttyUSB0
flowcontrol : none
baudrate is : 9600
parity is : none
databits are : 8
escape is : C-a
local echo is : no
noinit is : no
noreset is : no
nolock is : no
send_cmd is : sz -vv
receive_cmd is : rz -vv
imap is :
omap is :
emap is : crcrlf,delbs,

Terminal ready
!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A4��*����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9ECOs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9�COs!��:��@��0�~?�4�!��A$2:����O�:9ECOs!��:�@��0�~?�4�!��A$2:����O�:9�CO
Thanks for using picocom[/code]

How do I verify that unbinascii.unhexlify is available?

Thanks

User avatar
Roberthh
Posts: 1311
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Can not flash SonOff with MP

Post by Roberthh » Mon Feb 11, 2019 8:41 am

You have to set the baudrate to 115200, calling it with

picocom -b 115200 /dev/ttyUSB0

theMusicMan
Posts: 23
Joined: Mon Feb 11, 2019 12:16 am

Re: Can not flash SonOff with MP

Post by theMusicMan » Mon Feb 11, 2019 8:45 am

Roberthh wrote:
Mon Feb 11, 2019 8:41 am
You have to set the baudrate to 115200, calling it with

picocom -b 115200 /dev/ttyUSB0
Many thanks Robert.

OK, so I did this and what I get is a much faster version of what I posted earlier. The same strange characters are scrolling up my terminal window at a faster rate of knots!!

Really appreciate you getting back to me so quickly, much appreciated.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Can not flash SonOff with MP

Post by platforma » Mon Feb 11, 2019 8:54 am

I am not super familiar with the Sonoff boards but I'm fairly certain the baud rate should be 115200 after you flashed the board. If you're getting some output, even if it's garbled, at least something is happing. Perhaps try a couple of other "standard" rates, e.g. 19200.

theMusicMan
Posts: 23
Joined: Mon Feb 11, 2019 12:16 am

Re: Can not flash SonOff with MP

Post by theMusicMan » Mon Feb 11, 2019 9:01 am

platforma wrote:
Mon Feb 11, 2019 8:54 am
I am not super familiar with the Sonoff boards but I'm fairly certain the baud rate should be 115200 after you flashed the board. If you're getting some output, even if it's garbled, at least something is happing. Perhaps try a couple of other "standard" rates, e.g. 19200.
Alas... same characters, just at a different rate. Many thanks for replying though.

User avatar
Roberthh
Posts: 1311
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Can not flash SonOff with MP

Post by Roberthh » Mon Feb 11, 2019 9:13 am

The first output of the ESP8266 is at 74880 Baud, then it should change to 115200. if it does not, then the image is not loaded. AFAIK, you have to use the option "-fm dout" during flashing. You may find that in a search of the Forum.

hansp@kollerod.com
Posts: 2
Joined: Sun Feb 10, 2019 4:43 pm

Re: Can not flash SonOff with MP

Post by hansp@kollerod.com » Mon Feb 11, 2019 9:42 am

Hi Forum
Thanks for the response.
I have got it working.
Wha's made it work I don't relay know
I changed to Windows, added -fm dout
>esptool.py -p COM5 --baud 460800 write_flash --flash_size=detect -fm dout 0 esp8266-20190125-v1.10.bin
and changed to an other power source
The -fm dout I tried on the Rpi earlier with no luck
I will try to go back to RPi keeping the rest, to se if that was the issue.
/HansP

Post Reply