io ho fatto un piccolo programmino che invia dei pacchetti da UDP verso telegram e viceversa ma ho notato che se non ci sono dei pacchetti di wlog verso l'interfaccia di programmazione l'esp si riavvia.
Ho creato la variabile "LogDeb" che mi permette di attivare/disattivare tutti i log e ho notato che nel momento in cui lo disattivo il micro si riavvia.
E' già capitato a qualcuno?
Grazie.
Code: [Local Link Removed for Guests]
BOT_TOKEN_Al$ = "xxxx"
BOT_TOKEN_Wo$ = "xxxx"
BOT_TOKEN_Co$ = "xxxx"
CHAT_ID_And$ = "xxxx"
CHAT_ID_Bar$ = "xxxx"
PIN.MODE 5, OUTPUT
onudp goudp
udp.begin 1335
serial2.mode 19200, 16,17
WIFI.POWER 0.5
onwgetasync asynco
onserial2 RxBMS
timer0 5000, Tim5Sec
timer1 1000, Tim1Sec
DisChk = 0
CntTimeOutESP_PC = 0
CntSconnWIFI = 0
next_id$ = ""
LogDeb = 1'Att/Dis Log
'Avvio del programma
Mess$ = " avvio " & str$(WIFI.STATUS) & " "
file.append "/riavvio.txt", Mess$
msg$ = "Avvio sistema!!"
if LogDeb = 1 then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msg$)
'wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msg$)
wlog "Avvio ESP"
else
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msg$)
'tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msg$)
end if
while 1
wend
wait
goudp: 'Ricezione pacchetti dal PC
BufferRx$ = udp.read$
if LogDeb = 1 then
wlog "Rx dal PC : " & BufferRx$
end if
if BufferRx$ = "2550255" then 'Feed con il programma di casa se ricevo questa stringa rispondo al pc di casa
udp.write "255.255.255.255", 1336, "255" 'Invio feed al pc di casa
if LogDeb = 1 then
wlog "Invio Feed verso il PC"
end if
CntTimeOutESP_PC = 0 'Azzero il contatore del TimeOut connessione con PC
goto Ex
end if
msgU$ = json$(BufferRx$, "Priorita") 'Se il messaggio ricevuto dal PC non contiene "Priorità" non lo invio con
telegram
if (msgU$ <> "not found") then
msgSend$ = json$(BufferRx$,"DescrizioneOggetto") 'Leggo l'oggetto
msgSend$ = msgSend$ & " " & json$(BufferRx$,"DescrizioneTesto") 'Compongo il messaggio da inviare
Priorita$ = json$(BufferRx$,"Priorita") 'Leggo la priorità
if LogDeb = 1 then
if Priorita$ = "1" then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Al$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Al$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
if Priorita$ = "2" then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
if Priorita$ = "3" then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
else
if Priorita$ = "1" then
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Al$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Al$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
if Priorita$ = "2" then
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
if Priorita$ = "3" then
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msgSend$)
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msgSend$)
end if
end if
end if
Ex:
return
Tim1Sec:
if DisChk = 0 then
CntTimeOutESP_PC = CntTimeOutESP_PC + 1
else
if TIMEUNIX(time$) < 120 then 'Alle ore 2 di notte riabilito il Feed con il PC
DisChk = 0
end if
end if
if CntTimeOutESP_PC > 250 then
msg$ = "Perso connessione PC!"
if LogDeb = 1 then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msg$)
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msg$)
else
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_And$ + "&text=" + msg$)
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Wo$ + "/sendMessage?chat_id=" + CHAT_ID_Bar$ + "&text=" + msg$)
end if
CntTimeOutESP_PC = 0
end if
'Controllo dello stato della connessione
if WIFI.STATUS <> 3 then
CntSconnWIFI = CntSconnWIFI + 1
PIN(5) = 1
else
CntSconnWIFI = 0
PIN(5) = 1 - PIN(5)
end if
if LogDeb = 1 then
wlog CntSconnWIFI
end if
' wlog "0"
if CntSconnWIFI > 30 then
Mess$ = time$ & " + riavvio " & str$(WIFI.STATUS) & " "
file.append "/riavvio.txt", Mess$
REBOOT
end if
return
Tim5Sec: 'Timer 5 secondi
wgetasync "https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/getUpdates?offset=" + next_id$
if LogDeb = 1 then
wlog "Invio comando al BMS"
end if
print2 "~20004642E00200FD37"
return
RxBMS:
Rx485$ = serial2.input$
MessBMS$ = ""
for Cnt = 0 to ( len(Rx485$) - 1 )
MessBMS2$ = left$(Rx485$ , Cnt + 1 )
MessBMS1$ = right$(MessBMS2$,1)
MessBMS$ = MessBMS$ & "," & MessBMS1$
next Cnt
MessBMS$ = MessBMS$ & ","
udp.write "255.255.255.255", 1336, MessBMS$
if LogDeb = 1 then
wlog MessBMS$
end if
return
asynco: 'Lettura dei messaggi da Telegram
MessRx$ = WGETRESULT$
msg$ = json$(MessRx$, "message.text")
if (msg$ <> "not found") then 'Controllo se vi sono nuovi messaggi.
id$ = json$(MessRx$, "update_id")
next_id$ = trim$(str$(val(id$) + 1, "%11.0f")) ' set the id for the next message
CHAT_ID$ = json$(MessRx$, "chat.id")
if LogDeb = 1 then
wlog "Message : "; msg$
wlog "Next ID : "; next_id$
wlog "From :"; json$(MessRx$, "username")
wlog "ID :"; next_id$
wlog "ori:" ; MessRx$
end if
'Risposta del messaggio
if CHAT_ID$ = CHAT_ID_And$ or CHAT_ID$ = CHAT_ID_Bar$ then 'Controllo che sia inviato da mittenti noti
udp.write "255.255.255.255",1336,msg$
mess$ = "You sent me: " + msg$
if msg$ = "Dis" then
mess$ = "Controllo pc disabilitato"
DisChk = 1
end if
if msg$ = "Att" then
mess$ = "Controllo pc abilitato"
DisChk = 0
end if
if LogDeb = 1 then
wlog wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID$ + "&text=" + mess$)
else
tmp$ = wget$("https://api.telegram.org/bot" + BOT_TOKEN_Co$ + "/sendMessage?chat_id=" + CHAT_ID$ + "&text=" + mess$)
end if
end if
end if
return