Problemi di riavvio

Spazio dedicato agli utenti Italiani
Post Reply
landreal
Posts: 3
Joined: Thu May 13, 2021 8:50 pm
Been thanked: 2 times

Problemi di riavvio

Post by landreal »

Ciao a tutti,
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
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Problemi di riavvio

Post by cicciocb »

Buongiorno,
non ho risposto rapidamente aspettando che qualcun'altro potesse confermare il comportamento.

Per quanto mi riguarda posso solo dire tre cose :

1- Il comando WLOG puo' essere inibito usando il comando OPTION.WLOG [Local Link Removed for Guests]; puoi quindi semplificare il tuo codice

2 - Se stai usando il chip ESP32 (sicuramente), i pin 16 e 17 sono normalmente dedicati alla PSRAM e quindi, se il tuo modulo la possiede, non puoi usarli

3 - Potresti usare direttamente i comandi TELEGRAM... al posto di usare WGET$
landreal
Posts: 3
Joined: Thu May 13, 2021 8:50 pm
Been thanked: 2 times

Re: Problemi di riavvio

Post by landreal »

Buongiorno,
Nella mia applicazione non ho utilizzato i comandi telegram perché devo avere la possibilità di utlizzare più bot di telegram in base al tipo di messaggio.
Se prima di inviare il messaggio seleziono il settoken e poi mando il messaggio crea dei problemi??
Grazie.
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Problemi di riavvio

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Dec 27, 2022 9:10 am Buongiorno,
Nella mia applicazione non ho utilizzato i comandi telegram perché devo avere la possibilità di utlizzare più bot di telegram in base al tipo di messaggio.
Se prima di inviare il messaggio seleziono il settoken e poi mando il messaggio crea dei problemi??
Grazie.
Ciao,
pardon per la risposta tardiva ma in questi giorni di vacanza é difficile trovare un po' di tempo libero.

Puoi effettivamente cambiare "al volo" i parametri perché Annex compone la chiamata dinamicamente (crea un POST + json).
Questo vale per tutte le versioni (incluso l'esp8266)
landreal
Posts: 3
Joined: Thu May 13, 2021 8:50 pm
Been thanked: 2 times

Re: Problemi di riavvio

Post by landreal »

Ciao,
ho fatto ulteriori prove e tra una mangiata e l'altra ho riscritto un po' meglio il codice ma non riesco a farlo funzionare correttamete lo stesso.
Ho notato che dopo un po' di tempo che è acceso non colloquia più con telegram e se mando i messaggi con il telefono non li riceve, ma il micro non è bloccato perchè il led che faccio lampeggiare se normalmente connesso lampeggia correttamente.
Se cerco di connetterlo con il browsernon riesco a vederlo fino a quando non lo sconnetto dall'alimentazione.
Esiste qualche modo più elegante per far riconnettere l'esp al router se perde la connessione di quella che ho fatto io??
Altra cosa che ho visto è che io faccio scrivere in un file di testo "avvio" quando il programma si avvia e "riavvio" quando stò per resettare il micro perchè ho perso la connessione con il router, leggendo questo file ho riscontrato che vi sono parecchi voci di "avvio" senza essere preceduti da "riavvio" come se qualcosa lo avesse resettato.
I piedini che utilizzo per la seriale funzionano correttamente per l'rs485 infatti comunica regolarmente.
Premetto che tutte queste prove le ho fatte su 2 esp diversi e con più alimentatori ma non è cambiato nulla.

Se qualcuno ha qualche idea è ben accetto.

Code: [Local Link Removed for Guests]


BOT_TOKEN_Al$ = "xxx"
BOT_TOKEN_Wo$ = "xxx"
BOT_TOKEN_Co$ = "xxx"

CHAT_ID_And$ = "xxx"
CHAT_ID_Bar$ = "xxx"

PIN.MODE 2, OUTPUT
telegram.settoken "xxx"
telegram.setwait 30
telegram.setmode 0
onudp goudp
udp.begin 1335
serial2.mode 19200, 16,17

WIFI.POWER 0.1


onwgetasync asynco
onserial2 RxBMS
timer0 5000, Tim5Sec
timer1 1000, Tim1Sec
DisChk = 0
CntTimeOutESP_PC = 0
CntSconnWIFI = 0
next_id$ = ""
option.wlog 0'Att/Dis Log

              'Avvio del programma
  Mess$ = " avvio  " & str$(WIFI.STATUS) & "  "
  file.append "/riavvio.txt",  Mess$
  msg$ = "Avvio sistema!!"
  Temp$ = telegram.sendmessage$(val(CHAT_ID_And$),  msg$)
  wlog Temp$
  wlog "Avvio ESP"

wait

goudp:                      'Ricezione pacchetti dal PC
  BufferRx$ = udp.read$
  wlog "Rx dal PC : " & BufferRx$
  
  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
    wlog "Invio Feed verso il PC"
    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 Priorita$ = "1" then
      telegram.settoken "xxx"
    end if
    if Priorita$ = "2" then
      telegram.settoken "xxx"
    end if
    if Priorita$ = "3" then
      telegram.settoken "xxx"  
    end if
    Temp$ = telegram.sendmessage$(val(CHAT_ID_Bar$),  msgSend$)
    wlog Temp$    
    Temp$ = telegram.sendmessage$(val(CHAT_ID_And$),  msgSend$)
    wlog Temp$   
    telegram.settoken "xxx"
  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!"
    Temp$ = telegram.sendmessage$(val(CHAT_ID_Bar$),  msg$)
    wlog Temp$    
    Temp$ = telegram.sendmessage$(val(CHAT_ID_And$),  msg$)
    wlog Temp$
    CntTimeOutESP_PC = 0
  end if

  'Controllo dello stato della connessione
  if WIFI.STATUS <> 3 then
    CntSconnWIFI = CntSconnWIFI + 1
    PIN(2) = 1
  else
    CntSconnWIFI = 0
    PIN(2) = 1 - PIN(2)
  end if
  wlog CntSconnWIFI
  if CntSconnWIFI > 30  then
    Mess$ = time$ & " + riavvio " & str$(WIFI.STATUS) & "  "
    file.append "/riavvio.txt",  Mess$ 
    REBOOT
  end if
return

Tim5Sec:                          'Timer 5 secondi
  telegram.GetUpdatesAsync 
  wlog "Invio comando al BMS"
  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$
  wlog MessBMS$
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")
    wlog "Message : "; msg$
    wlog "Next ID : "; next_id$
    wlog "From :"; json$(MessRx$, "username")
    wlog "ID :"; next_id$
    wlog "ori:" ; MessRx$
    '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
      Temp$ = telegram.sendmessage$(val(CHAT_ID$), "You sent me : " + msg$)
      wlog Temp$
    end if
  end if
return

Utlizzando la seriale come debug ho riscontrato questo:

Rebooting...

ets Jun 8 2016 00:22:57



rst:0xc (SW_CPU_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:1216

ho 0 tail 12 room 4

load:0x40078000,len:9720

ho 0 tail 12 room 4

load:0x40080400,len:6364

entry 0x400806b8

Annex initializing...

BLE support enabled

module Type 0 Display 93 SD_Card 1
display res 240 320 orientation 1
OK

No SD cards found. Reverts to FFAT



Annex32 BLE CAN 1.48.22

(C) ciccioCB 2022

Personal use only, commercial use strictly prohibited


Chip revision 1 Freq 240
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.

Memory dump at 0x401ecf3c: 0008a2f0 48a29b5f 0020c005

Core 0 register dump:

PC : 0x401ecf40 PS : 0x00060230 A0 : 0x801ea2cd A1 : 0x3ffd8e70

A2 : 0x00000002 A3 : 0x3ffccd10 A4 : 0x00100000 A5 : 0x0c7d006c

A6 : 0x00ad2018 A7 : 0x00000003 A8 : 0x3ffccd7c A9 : 0x00000006

A10 : 0x000000f3 A11 : 0x0000003b A12 : 0x3ffccd21 A13 : 0x3ffc0720

A14 : 0x0000003d A15 : 0x00000000 SAR : 0x00000007 EXCCAUSE: 0x00000000

EXCVADDR: 0x00000000 LBEG : 0x401ecf35 LEND : 0x401ecf48 LCOUNT : 0x00000005

Backtrace: 0x401ecf3d:0x3ffd8e70 0x401ea2ca:0x3ffd8e90 0x401ead46:0x3ffd8eb0 0x4019f502:0x3ffd8ee0 0x4019f579:0x3ffd8f10 0x401cd47e:0x3ffd8f30 0x401cdc51:0x3ffd8f50 0x401cc240:0x3ffd8f70 0x402050e5:0x3ffd8f90

ELF file SHA256: 0000000000000000

Saluti.
Post Reply