main.py loop runs in REPL but not on Boot
main.py loop runs in REPL but not on Boot
My main.py script is quire simple, it just imports time a script to connect to WiFi and a script to publish sensor readings through MQTT. When I enter REPL I can reset the board and see that it connects to WiFi and publishes a value. It will then successfully wait 15 minutes (900s) before publishing the next value.
However, when I reset the board outside REPL, for example by power cycling, no values are published through MQTT. Not even an initial value at the time of boot. The text of my main.py loop is below. Any ideas why this could be happening? I'm a real novice at Python and very new to Micropython so hopefully this is just me being thick!
import ConnectWiFi
import time
import dht_publish
ConnectWiFi.connect()
while True:
dht_publish.publish()
time.sleep(900)
However, when I reset the board outside REPL, for example by power cycling, no values are published through MQTT. Not even an initial value at the time of boot. The text of my main.py loop is below. Any ideas why this could be happening? I'm a real novice at Python and very new to Micropython so hopefully this is just me being thick!
import ConnectWiFi
import time
import dht_publish
ConnectWiFi.connect()
while True:
dht_publish.publish()
time.sleep(900)
Re: main.py loop runs in REPL but not on Boot
Which device are you using? ESP32 or ESP8266?
Re: main.py loop runs in REPL but not on Boot
I'm using an ESP32.
Re: main.py loop runs in REPL but not on Boot
Which baord, how do you connect the board, and what is the Level of GPIO0 and GPIO2, when you do not used REPL?
Re: main.py loop runs in REPL but not on Boot
I bought a 'dev' board off AliExpress. See the link below. I connect to the board via the micro USB port using rshell on a Raspberry Pi. I have also used adafruit-ampy but find it less intuitive than rshell. One thing I've noticed is that when I exit rshell by hitting Ctrl + D, I have to power cycle the board to be able to reconnect. Could that connectivity issue be a symptom of the same issue?
https://www.aliexpress.com/item/ESP32-E ... 4c4df4VNhp
I'm not sure about the Level of GPIO0 and GPIO2. How would I go about measuring this? With a multimeter to Gnd? Or is it a software measurement?
I'm sure this is very basic stuff so I'm sorry for taking up your time with it. Thank you for your help.
https://www.aliexpress.com/item/ESP32-E ... 4c4df4VNhp
I'm not sure about the Level of GPIO0 and GPIO2. How would I go about measuring this? With a multimeter to Gnd? Or is it a software measurement?
I'm sure this is very basic stuff so I'm sorry for taking up your time with it. Thank you for your help.
Re: main.py loop runs in REPL but not on Boot
Yes, I was wondering if the modem control lines have some impact. Can you power the board w/o USB data, either by a charging only USB cable, or powering through Vin and GND with 5V.
The levels are to be measured with respect to GND. GPIO2 should be at TX0, GPIO0 should be one side of the boot switch. For proper opration, both should be at a level of about 3.3V. The same for reset, which is at the EN pin.
The levels are to be measured with respect to GND. GPIO2 should be at TX0, GPIO0 should be one side of the boot switch. For proper opration, both should be at a level of about 3.3V. The same for reset, which is at the EN pin.
Re: main.py loop runs in REPL but not on Boot
Thanks Robert, I'll test them this evening and get back to you. I'll test them with and without a data connection to help narrow down the issue.
Re: main.py loop runs in REPL but not on Boot
I've now measured from the pins you've suggested. Regardless of whether measured when powered with or without a data connection they all measure between 3.22V and 3.26V to GND.
To measure without data, I have used the same USB cable but have plugged it directly into a USB power supply (i.e. a mobile phone charger). I have also used the official Raspberry Pi power supply, which I understand does not have a data connection. Hopefully at least one of these is equivalent to using a data only cable or powering through the 5V and GND pins
To measure without data, I have used the same USB cable but have plugged it directly into a USB power supply (i.e. a mobile phone charger). I have also used the official Raspberry Pi power supply, which I understand does not have a data connection. Hopefully at least one of these is equivalent to using a data only cable or powering through the 5V and GND pins
Re: main.py loop runs in REPL but not on Boot
That looks as if there is no problem with the strapping pins. When you power the device and push the EN button, the device should reset. Do you have a simple piece of code like LED blink which you can use for testing?
b.t.w.: how did you upload main.py and boot.py to the devices file system?
b.t.w.: how did you upload main.py and boot.py to the devices file system?
Re: main.py loop runs in REPL but not on Boot
I used rshell to copy the scripts over to the boards initially and to edit them since then.
I added the following to my main.py and the LED blinks when resetting or powering on the ESP32. I was able to piece that together quickly thanks to a post that you responded to on this board, so thank again!
So that suggests to me that the script is being executed on boot.
counter = 0
while counter < 3:
led.value(1)
time.sleep(0.1)
led.value(0)
time.sleep(0.1)
counter += 1
I have also set the LED to do a single long blink after it successfully publishes data to the MQTT server. This blink is also happening. I reduced the timer between publishes to be 9 seconds to see if it would continue to publish data and so far it has blinked repeatedly. I will increase the timer back up to 15 minutes (900s) and see if it works over night.
Thanks again for your help and patience.
I added the following to my main.py and the LED blinks when resetting or powering on the ESP32. I was able to piece that together quickly thanks to a post that you responded to on this board, so thank again!
So that suggests to me that the script is being executed on boot.
counter = 0
while counter < 3:
led.value(1)
time.sleep(0.1)
led.value(0)
time.sleep(0.1)
counter += 1
I have also set the LED to do a single long blink after it successfully publishes data to the MQTT server. This blink is also happening. I reduced the timer between publishes to be 9 seconds to see if it would continue to publish data and so far it has blinked repeatedly. I will increase the timer back up to 15 minutes (900s) and see if it works over night.
Thanks again for your help and patience.