SerialTimeoutException while flashing firmware to a esp8266 nodeMCU board using esptool - esp8266

I have been working on a project that involves controlling a 4 channel relay using micropython on a esp8266 nodeMCU board. I have been using esptool to flash the latest micropython firmware bin file to the board. Everything went well at first, and I continued to upload my code file to the board. Things started going sideways on me at that point. I issue had to do with the com3 port being busy. So, I again used esptool to erase the original flash, and then reflash the board. But this time I received a serial timeout exception several seconds after esptool started to write to the board. I tried again with two other identical (and brand new) boards, but I still get the same error every time. Below is the esptool output starting from the command line arguments.
(base) PS C:\development\python> esptool --port com3 --baud 9600 write_flash --flash_size detect --flash_mode dio -z 0x0000 esp8266-20210902-v1.17.bin
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0d:50:04
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x0009afff...
Flash params set to 0x0240
Compressed 633688 bytes to 416263...
Writing at 0x00000000... (3 %)Traceback (most recent call last):
File "c:\users\billa\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\billa\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\billa\Anaconda3\Scripts\esptool.exe\__main__.py", line 7, in <module>
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 5136, in _main
main()
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 4602, in main
operation_func(esp, args)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 3873, in write_flash
esp.flash_defl_block(block, seq, timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 154, in inner
return func(*args, **kwargs)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 919, in flash_defl_block
self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 495, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 458, in command
self.write(pkt)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 421, in write
self._port.write(buf)
File "c:\users\billa\anaconda3\lib\site-packages\serial\serialwin32.py", line 323, in write
raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout
(base) PS C:\development\python> esptool --port com3 --baud 9600 erase_flash
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0e:3f:ce
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.7s
Hard resetting via RTS pin...
(base) PS C:\development\python> esptool --port com3 --baud 9600 write_flash --flash_size detect --flash_mode dio -z 0x0000 esp8266-20210902-v1.17.bin
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0e:3f:ce
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x0009afff...
Flash params set to 0x0240
Compressed 633688 bytes to 416263...
Writing at 0x00000000... (3 %)Traceback (most recent call last):
File "c:\users\billa\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\billa\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\billa\Anaconda3\Scripts\esptool.exe\__main__.py", line 7, in <module>
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 5136, in _main
main()
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 4602, in main
operation_func(esp, args)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 3873, in write_flash
esp.flash_defl_block(block, seq, timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 154, in inner
return func(*args, **kwargs)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 919, in flash_defl_block
self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 495, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 458, in command
self.write(pkt)
File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 421, in write
self._port.write(buf)
File "c:\users\billa\anaconda3\lib\site-packages\serial\serialwin32.py", line 323, in write
raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout
(base) PS C:\development\python>
I have re-downloaded the firmware bin file just incase it had become corrupt somehow. I also attempted the same process on three different boards.
-----------------UPDATE 12/03/21-------------------------------
I tried using the Arduino IDE to upload a test sketch that operates a 4 channel relay. I connected using the same com port (com3) and everything works perfectly! This does not explain why both the Thonny IDE and the esptool fail to connect to com3.
So, here are some conclusions. The issue is not with the esp8266, or the com port in my PC. Both the esptool and Thonny IDE worked in the beginning, and both failed to upload data to the board at roughly the same time, it is unlikely the issue is with either of those tools.
What does that leave to be investigated??
Thanks
Bill

Related

Getting an upload error of ESP8266 using Arduino IDE with this report

The report is like this :
Executable segment sizes:
ICACHE : 32768 - flash instruction cache
IROM : 252980 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 28261 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)
DATA : 1560 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 2484 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 26704 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 285285 bytes (27%) of program storage space. Maximum is 1044464 bytes.
Global variables use 30748 bytes (37%) of dynamic memory, leaving 51172 bytes for local variables. Maximum is 81920 bytes.
"C:\Users\hp\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1/python3" "C:\Users\hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1/tools/upload.py" --chip esp8266 --port "COM4" --baud "115200" "" --before default_reset --after hard_reset write_flash 0x0 "C:\Users\hp\AppData\Local\Temp\arduino-sketch-A88D8C3CC17CAE2361CEB8CD194D0EE6/sketch_dec24a.ino.bin"
esptool.py v3.0
Serial port COM4
Connecting...
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1/tools/upload.py", line 66, in <module>
esptool.main(cmdline)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 3552, in main
esp.connect(args.before, args.connect_attempts)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 519, in connect
last_error = self._connect_attempt(mode=mode, esp32r0_delay=False)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 499, in _connect_attempt
self.sync()
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 438, in sync
timeout=SYNC_TIMEOUT)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 376, in command
self.write(pkt)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/esptool\esptool.py", line 339, in write
self._port.write(buf)
File "C:/Users/hp/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.1/tools/pyserial\serial\serialwin32.py", line 325, in write
raise SerialTimeoutException('Write timeout')
serial.serialutil.SerialTimeoutException: Write timeout
Failed uploading: uploading error: exit status 1
I already installed all drivers and needed libraries.

Convert pcap to csv: CICFlowmeter throwing - scapy.error.Scapy_Exception: tcpdump is not available error when trying to convert pcap file to csv

I am following the steps as mentioned in https://pypi.org/project/cicflowmeter/ to convert a pcap to csv cicflowmeter -f example.pcap -c flows.csv and this error is thrown
(pcap) C:\Users\learner3\Anaconda3\envs\pcap\Scripts>cicflowmeter.exe -f test_pcap.pcap -c test_pcap.csv
WARNING: WinPcap is now deprecated (not maintained). Please use Npcap instead
Exception in thread AsyncSniffer:
Traceback (most recent call last):
File "C:\Users\learner3\Anaconda3\envs\pcap\lib\threading.py", line 980, in _bootstrap_inner
self.run()
File "C:\Users\learner3\Anaconda3\envs\pcap\lib\threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\learner3\Anaconda3\envs\pcap\lib\site-packages\scapy\sendrecv.py", line 1072, in _run
sniff_sockets.update((PcapReader(
File "C:\Users\learner3\Anaconda3\envs\pcap\lib\site-packages\scapy\sendrecv.py", line 1074, in <genexpr>
tcpdump(fname,
File "C:\Users\learner3\Anaconda3\envs\pcap\lib\site-packages\scapy\utils.py", line 2095, in tcpdump
raise Scapy_Exception(
scapy.error.Scapy_Exception: tcpdump is not available
However the UI of CICFLOWmeter worked fine and the pcap was converted to csv.
How can I fix this?
Any other approach using python code will also be very helpful, though I want all the fields that are specified here https://github.com/ahlashkari/CICFlowMeter/blob/master/ReadMe.txt
I actually want to be able to do this inside a linux/ubuntu VM, that's why the UI approach wont be feasible, hence I was trying with the command based approach, that gave the above error.
Any help is greatly appreciated!

Ros2 not finding executables running in Docker

I'm trying to run a python script with ros2 in my docker container, and everything up to running the Script works, I can even run Gazebo via a launch file, and it works.
The Error ROS gives me is the following:
root#86d8bf3a6eb9:/# ros2 run field_robot robot_spawner.py
Traceback (most recent call last):
File "/opt/ros/foxy/bin/ros2", line 11, in <module>
load_entry_point('ros2cli==0.9.11', 'console_scripts', 'ros2')()
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2run/command/run.py", line 70, in main
return run_executable(path=path, argv=args.argv, prefix=prefix)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2run/api/__init__.py", line 61, in run_executable
process = subprocess.Popen(cmd)
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py'
And yes, I checked, the File actually exists:
root#86d8bf3a6eb9:/# ls -l /field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py
-rwxr-xr-x 1 root root 1964 Apr 12 14:37 /field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py
Also, I'm running the Host system on Windows, so it could be that something with windows is fucked up, so if you have an Idea what could be the Problem there, that also might be it
Based on the comments it appears you're running into this issue because of the file type. If they're being edited in Windows first it is likely they are DOS files and not UNIX files. I know this causes issues with ROS1 so I assume it's the case in ROS2 as well. To fix this, you have a couple of options.
Usually the easiest would be to use dos2unix. This isn't installed by default but you can get it via apt install dos2unix assuming your image is Ubuntu. The files can be converted by running dos2unix <filename> inside your container.

NodeMCU ESP8266 cannot upload sketch - timeout error

Using arduino-cli, the arduino-ide, or directly the esptool.py (from https://github.com/espressif/esptool) I obtain the following error when uploading a simple (correct) sketch.
x#y:~/blink$ ~/tools/arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2
esptool.py v3.1
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/upload.py", line 66, in <module>
esptool.main(cmdline)
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 4074, in main
esp = esp or get_default_connected_device(ser_list, port=args.port, connect_attempts=args.connect_attempts,
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 121, in get_default_connected_device
_esp.connect(before, connect_attempts)
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 639, in connect
raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
Error during Upload: Failed uploading: uploading error: exit status 1
esptool.py v3.1
The problem was that my last apt upgrade updated the kernel from the 5.4.0-86-generic to 5.4.0-88-generic (I checked the update in /var/log/apt/history.log.1.gz). The driver CH341 in 5.4.0-88 is not working properly (the ESP I'm using require CH340G drivers). The solution is to go back to the 5.4.0-86 drivers and in the following I list what I've done.
disconnect any ESP or board connected to any USB. Then test that the CH341 module (which allows the serial communication with the EPS) is loaded. You can use this code to test the correct unload/load of the module in steps 2, 3.
x#y:~$ lsmod | egrep serial
usbserial 53248 2 cp210x,ch341
here is where modules of the current (5.4.0-88) and previous (5.4.0-86) kernel are
x#y:~$ ls -larh /lib/modules/
total 164K
drwxr-xr-x 6 root root 4,0K set 29 09:19 5.4.0-88-generic
drwxr-xr-x 6 root root 4,0K set 23 09:45 5.4.0-86-generic
[...]
unload current (5.4.0-88) CH341 module with the command
sudo rmmod /lib/modules/5.4.0-88-generic/kernel/drivers/usb/serial/ch341.ko
load previous (5.4.0-86) CH341 module with the command
sudo insmod /lib/modules/5.4.0-86-generic/kernel/drivers/usb/serial/ch341.ko
That's it :) You should now be able to upload a new sketch to your ESP8266.

How to retrieve the flashed binary in ESP8266

I was able to flash a micropython binary which I'd cross compiled some 6 months ago, and it was working fine. It was built from master branch at that point of time, and I did not save the code, nor the binary.
Today, when I again compiled, the binary is having problem at a point. So I want to revert back to the old binary, only problem is I'm not sure what commitID/build the master was at at that point of time ~6 months ago when my compiled binary which works fine was created.
I do have an ESP which has that binary flashed into it. So I was thinking if there is a way to retrieve the binary from the ESP?
Please let me know if this can be done somehow via ampy, etc..
Or suggest me some workaround. I'm already trying to find out the approximate commit around that time, and would cross compile again, which I'm not sure if would work as expected.
Regardless of which firmware you loaded onto your ESP8266 module (NodeMCU, MicroPython, Arduino, etc.) you can use esptool.py to dump the flash content to a file like so:
./esptool.py -p PORT -b 460800 read_flash 0 0x200000 flash_contents.bin
read_flash is the command, 0x200000 the argument for the upper memory bound (2MB).
For reading the firmware as a BIN file
For reading the firmware as a BIN file you need FIRST to connect correct the FTDI with the pins on the IR module
FTDI to IR Module as follows
FTDI 3.3 V to IR 3.3 V,
FTDI GND to IR GND,
FTDI GND to IR IO0 (flash mode - IMPORTANT otherwise it will not work),
FTDI RX to IR TXD,
FTDI TX to IR RXD
Then run the command (if the COM port is 5 and the name to extract the bin is flash-contents, otherwise you replace them to match your COM and the name you wish to have) – important the baud rate to be 9600
esptool.py -p COM5 -b 9600 read_flash 0 0x200000 flash_contents.bin
Below is the outcome for me (running under python 3.10.2 on windows 11):
PS F:\> esptool.py -p COM5 -b 9600 read_flash 0 0x200000 flash_contents.bin
esptool.py v3.2
Serial port COM5
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying
again...
Connecting...
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 10:52:1c:f8:b7:c7
Stub is already running. No upload is necessary.
2097152 (100 %)
2097152 (100 %)
Read 2097152 bytes at 0x0 in 2215.2 seconds (7.6 kbit/s)...
Hard resetting via RTS pin...
PS F:\>
Remember the esptool.py -p COM5 -b 9600 read_flash 0 0x200000 flash_contents.bin is for 2MB memory
but it is well run with esptool.py -p COM5 -b 9600 read_flash 0 0x100000 flash_contents.bin for 1MB memory as it was in my IR Module
I reduced the speed of reading the flash memory of my esp8266
460800 for "46080" I took a zero.
and successful
My system is a windows 10
C:\Users\POSITIVO\Downloads\esptool-master\esptool-master>esptool.py -p COM6 -b 46080 read_flash 0 0x400000 flash_contents3.bin
esptool.py v3.0-dev
Serial port COM6
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:3a:e8:42:b9:f7
Uploading stub...
Running stub...
Stub running...
4194304 (100 %)
4194304 (100 %)
Read 4194304 bytes at 0x0 in 937.7 seconds (35.8 kbit/s)...
Hard resetting via RTS pin...

Resources