Re: main.py does not appear to working after boot
Posted: 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.
Please see the new forum at
https://forum.micropython.org/
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')
Code: Select all
print('Executing main.py')
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.
>>>
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.
>>>
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)
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
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)