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)
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)