Board Needs a Soft reboot to start to work

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
dsaad
Posts: 6
Joined: Wed Sep 22, 2021 11:06 am

Board Needs a Soft reboot to start to work

Post by dsaad » Thu Sep 23, 2021 2:23 pm

I have an ESP32 board connected to a DHT22.

Every time I turn the board off and on by the plug, it doesn't boot.
I need to go to rshell and then repl to soft reboot it to start to work and transmit to mosquitto_sub.

I have 2 files on the board, boot.py, main.py.

I have added my code here.

Thanks a lot in advance, for any help.

On boot.py:

Code: Select all

import network
import time

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)

while not sta_if.isconnected():
    sta_if.connect("WiFi", "PassWord")
    time.sleep(3)
on main.py:

Code: Select all

import time
import machine
import dht
from umqtt.simple import MQTTClient

# set the time between measurements
sleep_time = 10

# IP address of Raspberry Pi, working as MQTT broker
mqtt_server = "192.168.0.48"

# setup pin 23 for DHT22 connection
PIN23 = machine.Pin(23, machine.Pin.IN, machine.Pin.PULL_UP)
sensor = dht.DHT22(PIN23)

# define MQTT client ID and topic
CLIENT_ID = "outside_sensor"
TOPIC = "outside"

# infinite loop to collect sensor reading and publish
while True:
    try:
        sensor.measure()
        temp = sensor.temperature()
        humid = sensor.humidity()
        message = ("{0:3.1f}, {1:3.1f}".format(temp, humid))
        client.publish(TOPIC, message)
        print(message)
    except OSError as ose:
        print("Failed to read sensor")
        print(ose)

    time.sleep(sleep_time)

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Board Needs a Soft reboot to start to work

Post by davef » Thu Sep 23, 2021 6:26 pm

off and on by the plug
The USB plug?

Provide a link to your board.

After applying power does the boot button do it's job?

dsaad
Posts: 6
Joined: Wed Sep 22, 2021 11:06 am

Re: Board Needs a Soft reboot to start to work

Post by dsaad » Fri Sep 24, 2021 7:03 pm

I have tried everything, but none of them helped.

Finally, I have entered the REPL and entered this code and everything started to work fine:

Code: Select all

import machine
machine.reset()

Post Reply