main.py does not appear to working after boot

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
dhylands
Posts: 3240
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: main.py does not appear to working after boot

Post by dhylands » Wed Jul 17, 2019 1:04 am

I normally put prints in boot.py and main.py if I'm trying to verify what's getting executed.

rpr
Posts: 75
Joined: Sat Oct 27, 2018 5:17 pm

Re: main.py does not appear to working after boot

Post by rpr » Wed Jul 17, 2019 1:43 am

This maybe a silly suggestion. Put 'import main' as the last line of your boot.py. Or rename it as a different file.

Can you post your (redacted/reduced) boot.py and main.py scripts?

Edit: Other suggestions

Remove your 'boot.py' and just leave 'main.py' that blinks an LED.

User avatar
dhylands
Posts: 3240
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: main.py does not appear to working after boot

Post by dhylands » Wed Jul 17, 2019 2:49 am

Just as a sanity test, I compiled the latest MicroPython for ESP32 and flashed my SparkFun ESP32 Thng. I edited the default boot.py to be:

Code: Select all

# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
print('Executing boot.py')
and I created a main.py with the single statment:

Code: Select all

print('Executing main.py')
If I then drop into the REPL and press Control-D then I see:

Code: Select all

MPY: soft reboot
Executing boot.py
Executing main.py
MicroPython v1.11-153-gbaea43bba on 2019-07-16; ESP32 module with ESP32
Type "help()" for more information.
>>> 
SImilarly, while in the REPL, if I press the RESET button on the ESP32 board then I see:

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4936
load:0x40078000,len:9404
load:0x40080400,len:6228
entry 0x400806ec
I (444) cpu_start: Pro cpu up.
I (444) cpu_start: Application information:
I (444) cpu_start: Compile time:     Jul 16 2019 19:39:20
I (448) cpu_start: ELF file SHA256:  0000000000000000...
I (454) cpu_start: ESP-IDF:          v3.3-beta1-694-g6b3da6b18
I (460) cpu_start: Starting app cpu, entry point is 0x40082b54
I (0) cpu_start: App cpu up.
I (471) heap_init: Initializing. RAM available for dynamic allocation:
I (478) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (484) heap_init: At 3FFB9CA8 len 00026358 (152 KiB): DRAM
I (490) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (496) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (503) heap_init: At 400921FC len 0000DE04 (55 KiB): IRAM
I (509) cpu_start: Pro cpu start user code
I (80) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Executing boot.py
Executing main.py
MicroPython v1.11-153-gbaea43bba on 2019-07-16; ESP32 module with ESP32
Type "help()" for more information.
>>> 
In either case it seems to be executing both boot.py and main.py.

User avatar
Roberthh
Posts: 1703
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: main.py does not appear to working after boot

Post by Roberthh » Wed Jul 17, 2019 6:22 am

@dhylands. The poster told above that when connected to a terminal, and booted via reset button or Ctrl_D, main.py is executed. It fails on pure power on. That's indeed strange: executing boot.py, but not main.py. As if that powering sets the device into RAW_REPL mode.
I tested two devices, Wemos LOLIN32 pro and sparkfun esp32 thing, here with a simple smart phone charger, and it runs main.py. Little script here. Pin 5 is connected to a LED

Code: Select all

from machine import Pin
from time import sleep
p = Pin(5, Pin.OUT)
for _ in range(10):
    p(0)
    sleep(1)
    p(1)
    sleep(1)

User avatar
Roberthh
Posts: 1703
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: main.py does not appear to working after boot

Post by Roberthh » Wed Jul 17, 2019 6:25 am

@smith.randallscott did we ask which ESP32 device you are using, and which firmware version?

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Wed Jul 17, 2019 12:49 pm

These are images of the ESP32 I am attempting to use.
esp32.jpg
esp32.jpg (144.62 KiB) Viewed 287 times
esp32_1.jpg
esp32_1.jpg (86.14 KiB) Viewed 287 times

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Wed Jul 17, 2019 12:51 pm

@dhylands Thanks for all your suggestions. I will begin trying to implement.

User avatar
Roberthh
Posts: 1703
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: main.py does not appear to working after boot

Post by Roberthh » Wed Jul 17, 2019 1:22 pm

This module type should be fine. Which version of the firmware did you install, and did you try to
- erase the flash and
- reload the firmware?
Also, what happens if you just power the device (w/o terminal) and push the reset button (eventually labeled as EN).

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Wed Jul 17, 2019 1:44 pm

This is my boot.py and main.py code

boot.py

Code: Select all

#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()

import network
from time import sleep
from umqtt.robust import MQTTClient
from machine import Pin
import onewire
import ds18x20

main_running_led = Pin(25, Pin.OUT)
main_running_led.on()

watch_dog_counter = 0
watch_dog_count_up = True

sta_if = network.WLAN(network.STA_IF)           #sta_if is setup outside the function so that global access is possible

client = MQTTClient('poolMQTT_client', 'xxx.xxx.xxx.xxx')



def wifi_connect():
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('ssid', 'pass')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
sleep(3)

main_running_led.off()
#client.connect()

sleep(1)

boot_end_var = True
main.py

Code: Select all

ow = onewire.OneWire(Pin(15))
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
if len(roms)>0:
    print("roms > 0")
    rom1 = roms[0]
else:
    print("roms = {}".format(roms))

test_var = True                                     # see if main is running

def read_temp():
    ds.convert_temp()
    sleep(0.8)
    temp_c = ds.read_temp(rom1)
    temp_f = 1.8*temp_c +32
    if temp_f > -200 and temp_f < 300:
        client.publish('garage/temperature', str(temp_f))
        print('publishing temperature {} F'.format(temp_f))
    return temp_f

wifi_connect()
client.connect()

while True:
    read_temp()

    if ((watch_dog_count_up is True) and watch_dog_counter < 20):
        watch_dog_counter = watch_dog_counter + 1
    elif watch_dog_counter >= 20:
        watch_dog_count_up = False
        watch_dog_counter = watch_dog_counter - 1
    elif ((watch_dog_count_up is False) and watch_dog_counter > 0):
        watch_dog_counter = watch_dog_counter - 1
    elif (watch_dog_counter <= 0):
        watch_dog_count_up = True
        watch_dog_counter = watch_dog_counter + 1
    else:
        print('Problem with counter')

    print('counter = {}'.format(watch_dog_counter))
    if watch_dog_counter%2 == 0:
        main_running_led.on()
    else:
        main_running_led.off()


    client.publish('garage/watchdog', str(watch_dog_counter))
    sleep(5)

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Wed Jul 17, 2019 1:46 pm

Firmware is v1.11, I have recently (with the last 5 days) erased and re flashed with esptool

Post Reply