my script gets blocked when there's a watchdog
Posted: Sat Aug 10, 2019 9:02 am
I have a recurring problem with my script despite the watchdog found on one of the topics on this forum.
I'm trying to do the following operations:
this is my script:
relaunch my script like this
I reboot the esp, I do lose some ping but the scipt does not restart.
I have to physically restart the nodemcu.
I have however the rst pin connected with the D0 pin.
Do you have any idea where my problem comes from.
I'm trying to do the following operations:
this is my script:
Code: Select all
#station meteo
#import standard library
import machine
import time
import urequests
# import special library
import bme280
import veml7700
#start configuration machine
#machine.freq(160000000) # set the CPU frequency to 160 MHz
# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
#end of configurartion machine
# address of external captor
bme280_addr = 0x76
vmle7700_addr = 0x10
# variable pour jeedom
apiKey = "ezrz"
idPa = "1551"
idTemp = "1552"
idHumidity = "1553"
idLux = "1562"
host = "192.168.8.204"
nbrReset = "1713"
port = 80
baseurl = "http://"+host+"/core/api/jeeApi.php?apikey="
baseurl += apiKey
baseurl += "&type=virtual&id="
#variable des mesure
t_old = 0;
lux_old = 0.0;
h_old = 0;
pa_old = 0.0;
#mise en place du watchdog
# issus de https://forum.micropython.org/viewtopic.php?f=16&t=5517&hilit=esp8266+sleep+and+reset&start=10
# second exemple de watchdod
# issus de https://forum.micropython.org/viewtopic.php?f=16&t=6376
class WDT:
def __init__(self, id=0, timeout=600):
self._timeout = timeout / 10
self._counter = 0
self._timer = machine.Timer(id)
self.init()
def _wdt(self, t):
self._counter += self._timeout
if self._counter >= self._timeout * 10:
machine.reset()
def feed(self):
self._counter = 0
def init(self, timeout=None):
timeout = timeout or self._timeout
self._timeout = timeout
self._timer.init(period=int(self._timeout * 1000),
mode=machine.Timer.PERIODIC, callback=self._wdt)
def deinit(self): # will not stop coroutine
self._timer.deinit()
# fin du watch dog
## END Simple software WDT implementation
# activate i2c port
i2c = machine.I2C(scl=machine.Pin(5),sda=machine.Pin(4))
#create capteur "object"
capteur2_lumiere = veml7700.VEML7700(vmle7700_addr,
i2c,
"confValues25_18",
"gain25_18")
capteur_bme = bme280.BME280(i2c=i2c)
wdt = WDT()
#start software
def main():
#start scan i2c buss
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
#end scan i2c bus
boucle=0
cptReset = 0
print("debut calcul")
#while boucle<5:
while True:
wdt.feed()
i=0
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print("s'est réveillé d'un profond sommeil")
while i<50:
# programmation du capteur
#lecture de la valeur du capteur
mesure_lux = capteur2_lumiere.read_lux()
#print("valeur multiplicateur: ",capteur2_lumiere.confValues)
#print("valeur gain : ", capteur2_lumiere.gain)
#print("Valeur VLME7700 : ")
#print("la mesure est de ", mesure_lux, " lux")
time.sleep(1)
# affichage des infos BME280
#print("température , pression, higronometrie :")
temperature = capteur_bme.values[0]
temperature = temperature[:-1]
#print(temperature)
pression = capteur_bme.values[1]
pression = pression[:-3]
#print(pression[:-3])
humidite = capteur_bme.values[2]
humidite= humidite[:-3]
#print(humidite[:-1])
i=i+1
print("Fin boucle de prise de mesure, tour numero :", i)
#print("Valeurs deniere mesure")
#print("la mesure est de luminosité est de ", mesure_lux, " lux")
#print(temperature)
#print(pression[:-3])
#print(humidite[:-1])
print("J'envoie les données à jeedom")
print("Tempreature envoyé",temperature)
print("Pression envoyé",pression[:-3])
print("Taux d'humidité envoyé",humidite[:-1])
print("taux de lumiére envoyé",mesure_lux)
# constitution base du get pour envoie a jeedom
#baseurl = "http://"+host+"/core/api/jeeApi.php?apikey="
#baseurl += apiKey
#baseurl += "&type=virtual&id="
# constitution url d'envoie
url = baseurl + idTemp # id jeedom objet
url += "&value="
url += temperature; # valeur récuperer du capteur
response = urequests.get(url)
#pression
url = baseurl + idPa # id jeedom objet
url += "&value="
url += pression[:-3]; # valeur récuperer du capteur
response = urequests.get(url)
#humidite
url = baseurl + idHumidity # id jeedom objet
url += "&value="
url += humidite[:-1] # valeur récuperer du capteur
response = urequests.get(url)
# lux
url = baseurl + idLux # id jeedom objet
url += "&value="
url += str(mesure_lux); # valeur récuperer du capteur
response = urequests.get(url)
print("transmission faite")
#print(type(mesure_lux))
#print("je m'endors pour quelques minutes")
#mise en place du deepsleep
# set RTC.ALARM0 to fire after 10 seconds (waking the device)
#print("nous en sommes a la boucle: ",boucle )
wdt_timer = machine.Timer(-1)
wdt_timer.init(period=275000, mode=machine.Timer.PERIODIC,
callback=lambda t: wdt_callback())
if __name__ =="__main__":
main()
relaunch my script like this
Code: Select all
Meteo import >>> Meteo import
>>> Meteo.main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError:'module' object has no attribute' main
I have to physically restart the nodemcu.
I have however the rst pin connected with the D0 pin.
Do you have any idea where my problem comes from.