Problems when using Micropython and Blynk

Hi,

I am new to Blynk but have managed to get my first project running (well for a while anyway). I am using an ESP32 which is reading data from a DH22 temperature and humidity sensor and RTC, then displaying it to an LCD display. The Micropython code has been running well until I connected it to Blynk which now causes the following error and stops the code: - (Code runs for intermittent periods before coming up with this error 1 - 4 hours)

rst:0x8 (TG1WDT_SYS_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:5008

ho 0 tail 12 room 4

load:0x40078000,len:11608

ho 0 tail 12 room 4

load:0x40080400,len:6120

entry 0x400806bc

W (65) boot: PRO CPU has been reset by WDT.

W (65) boot: WDT reset info: PRO CPU PC=0x400983ab

W (65) boot: WDT reset info: APP CPU PC=0x400945a6

E (647) spiram: SPI RAM enabled but initialization failed. Bailing out.

E (391) spiram: SPI RAM not initialized

MicroPython v1.14 on 2021-02-02; ESP32 module (spiram) with ESP32

import dht
import machine
import time
import network
from ds1307 import DS1307
from machine import I2C, Pin
from lcd_driver import I2cLcd
import BlynkLibESP32 as BlynkLib 
import _thread as thread

# Setup LCD I2C driver
LCD_DEFAULT_I2C_ADDR = 0x27 # Address for LCD display
lcd_i2c = I2C(scl=Pin(23), sda=Pin(22), freq=400000)
lcd = I2cLcd(lcd_i2c, LCD_DEFAULT_I2C_ADDR, 2, 16) # Object for LCD

# Create sensor object
dht22 = dht.DHT22(machine.Pin(16))

# Create RTC obect
RTC_DEFAULT_I2C_ADDR = 0x68 # Address for RTC module
rtc_i2c = I2C(scl=Pin(23), sda=Pin(22), freq=400000)
rtc = DS1307(rtc_i2c, RTC_DEFAULT_I2C_ADDR) # Object for RTC

# Function to setup / display and check wifi connection - returns "FAILED" or "SUCCESS")
wifi = network.WLAN(network.STA_IF) # WLAN setup as station
wifi.active(True) # Turn wifi ON
wifi.connect("*******", "********") # Connect to router
wifi_test = wifi.isconnected() # Check wifi is connected

# Blynk token
blynk = BlynkLib.Blynk("*************")

while True:
    
    if wifi_test == False:
            
        time.sleep(1)
        wifi_test = wifi.isconnected
        print("Trying to connect to WIFI")
               
    else:
                         
        print ("SUCCESS")
        break

# Fuction to keep display updated
def update_display(none):
    
        while True:
        
            timeno = rtc.datetime()
            lcd.move_to(0,1)
            lcd.putstr(str(timeno[4]) + ":" + str(timeno[5]))
            dht22.measure()
            temperature = round(float(dht22.temperature()),0)
            temperature = str(temperature)
            humidity = round(float(dht22.humidity()),0)
            humidity = str(humidity)
            lcd.move_to(0,0)
            lcd.putstr("TP=" +temperature + " " + "%RH=" + humidity)
            time.sleep(1)
            #blynk.virtual_write(2, 0)
            time.sleep(1)
            #print(temperature + '-----' + humidity)
             blynk.virtual_write(0, temperature)
             blynk.virtual_write(1, humidity)
             blynk.virtual_write(2, 255)

thread.start_new_thread(update_display, (None,))

while True:
    blynk.run()
    


Any help would be appreciated
Dave

Are you sure that you are using a board that has SPI RAM ?

Pete

Hi Pete,

Thanks for the reply, I have just checked the ESP32 board and it has the 25032 flash memory IC on it which I’m guessing is not SPIRAM… I’ve not noticed it complaining about not being able to initialise SPIRAM before I started getting this issue… Perhaps I need to look at reflashing ESP with non SPIRAM firmware.

Thanks for your help
Dave

So I have now reflashed ESP32 with the non SPIRAM firmware and started my script… it has lasted approximately 2 hours before stopping due to the following error: -

Pro CPU has been stopped by WDT

I have done some Googling around this error but not really come up with much apart from maybe issues using Threading and Blynk???

Any help would be much appreciated

Regards Dave

My suggestion is to get a pycom wipy

Pycom had done an amazing job. System and boards have amazing stability and good documentation with heaps of examples

Pycom has OTA updates and a ota coding system from the browser

World wide certified and reliable with as much flash and ram you could need
If you want your project to last years
Either go Pycom or pyboard for micropython

Or adafruit boards for circuit python

You get what you pay for uP boards

Watch Dog Timer

I suspect you were just running too-much-too-fast-long-enough that something got overrun in the thread?

Instead of a delay, try looking at non-blocking timer options to monitor every few minutes instead of seconds.

Non blocking timer option

setup

import time
start_message = time.ticks_ms() + 150 #sets timer for later use  
while True:
    if start_message < time.ticks_ms(): # read delay 
         print('_',end='')
         RUN CODE HERE check temps

Blynk.run()

I also place Blynk.run() in a timer. I set it to update every 400ms as not to eat all of my LTE data

Blynk Python has a blynktimer function…

Same as always and shown each time you create a help topic.

Triple backticks (NOT commas or apostrophes) before and after the code.
I find adding the cpp after the first backticks helps with displaying everything properly

``` cpp
<CODE>

```

1 Like

Hi Everyone,

Thanks so much for your comments it’s appreciated!

I’ve had a look at the BlynkLibESP32.py library I am using to connect to Blynk and see that it sets a watchdog timer for 10 seconds so guess by Thread is getting stuck somewhere and stopping the watchdog being fed?

I will have a look for a Blynk Timer library and try to implement that…

Thanks again