How can I reset ESP8266 MicroPython after main.py crashes?

Internet of Things IoT Frameworks 2 years ago

0 1 0 0 0

_x000D_ _x000D_ I have a NodeMCU ESP8266 board running MicroPython. I'm running a web server on my ESP8266. This is my first IoT project based on one of these boards. The below is a snippet of the code. This is being executed within main.py. Every now and then, something causes the code to crash (perhaps timing and request based). When main.py exits, for whatever reason, I'm dropped back at the python CLI. I'd like for the board to reset when this happens (if there isn't a better way). What is the best method of restarting/reseting the ESP8266? addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(addr) s.listen(5) print('listening on', addr) while True: cl, addr = s.accept() print('client connected from', addr) cl_file = cl.makefile('rwb', 0) print("Request:") while True: line = cl_file.readline() print("Line:" , line) if not line or line == b'\r\n': print("breaking") break if line == b'GET /active HTTP/1.1\r\n':

Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ You could execute your code (which should be outside of the main.py -> other file) from the boot or the main.py. if it drops out it should execute the following code, which could trigger a reset. You may have to catch the error first. I hope I helped
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum


Q

Azure IoT hub and sending messages with mosquitto_pub

_x000D_ _x000D_ I'm trying to send some simple message with mosquitto_pub to Azure IoT HUB but faced...
Q

How to generate AWS bootstrap certificates with java SDK?

_x000D_ _x000D_ According to this docs I need to generate so-called bootstrap certificates for my Io...
Q

is it possible to do 3way handshake only one time with mqtt communication?

_x000D_ _x000D_ I am using mosquitto_pub to publish the data with TLS using a topic. I am using mosq...

Important Internet of Things Links