ESP8266-12 non risponde al bot

Spazio dedicato agli utenti Italiani
Post Reply
MarioL
Posts: 20
Joined: Sun Mar 21, 2021 8:38 am
Has thanked: 250 times
Been thanked: 33 times

ESP8266-12 non risponde al bot

Post by MarioL »

Salve popolo di Annex,
Il trittico ESP, Annex e Telegram potrebbe rivelare una piacevole sorpresa nel campo del telecontrollo interattivo con interfaccia grafica.
Purtroppo mi sono blocccato al primo tentativo di test delle funzioni di Telegram con ESP8266.
Il programma usato è tratto dall'Help on line denominato "Example of echo bot (reply the command received)", di seguito il listato con piccole modifiche.

Code: [Local Link Removed for Guests]

wlog time$

telegram.settoken "5827984672:AAENEvX7k6YsjsH6bhAI-Rh80Pnmnnnmmmmmhhh"
telegram.setwait 10
wlog telegram.getMe$ 'get the user’s informations

timer0 5000, getmessages
wait

getmessages:
'Receive the messages
r$ = telegram.getUpdates$ 'get the new messages
wlog r$, time$
text$ = json$(r$, "text")
if (text$ <> "not found") then
  c$ = json$(r$, "chat.id")   'get the chat_id
  c = val(c$) 'return chat id into a numeric value
  wlog telegram.sendmessage$(c, "echo : " + text$)
end if

return
Cosa succede: ESP8266 interroga il bot e riceve correttamente il messaggio (nello screen dell'IDE è evidenziato il testo CIAO ricevuto.
Cosa NON succede: ESP8266 non riesce ad inviare il messaggio di "echo" al bot col comando "wlog telegram.sendmessage$(c, "echo : " + text$)", infatti, ritorna il messaggio {"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

ho provato ad indagare sulla variabile "chat.id" con la funzione "Get Variable", prima nella forma stringa (c$) che mi pare corretta, poi nella forma trasformata in numerica (c) dove, forse, c'è il troncamento di qualche unità.
Cosa ne pensate? O potrebbe dipendere dalle impostazioni del bot e/o telegram?
grazie e buone feste
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 1899
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1269 times
Contact:

Re: ESP8266-12 non risponde al bot

Post by cicciocb »

Salve,
é probabile che ci sia un errore nella conversione del chat.id.

Appena posso ci daro' un'occhiata.
User avatar
cicciocb
Site Admin
Posts: 1899
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1269 times
Contact:

Re: ESP8266-12 non risponde al bot

Post by cicciocb »

Ho appena dato un occhiata rapidamente e, effettivamente, penso sia un errore nella conversione del numero in string.
In effetti il numero del chat_id ( 5788824931) diventa 01 59 0A 75 63 in esadecimale e quindi supera i 32bits della variabile che ho usato internamente.

Dovro' fare una piccola update per correggere.
MarioL
Posts: 20
Joined: Sun Mar 21, 2021 8:38 am
Has thanked: 250 times
Been thanked: 33 times

Re: ESP8266-12 non risponde al bot

Post by MarioL »

Bene, nel frattempo, per iniziare a sperimentare ho ripiegato sulla funzione di stringa WGET$ per ottenere l'echo dal bot di telegram.
Di seguito condivido il codice modificato.
Presto, nella sezione "Code tips" condividerò un esempio di comandi preformattati dall'ESP per l'ESP.

Code: [Local Link Removed for Guests]

'hardware: ESP8266-12  
'firmware: Annex WiFi 1.44.2

wlog time$
token$ =  "58276565672:AAENEvX7k6YsklklklbhAI-Rh80Pnmnnnmmmmmhhh"
telegram.settoken token$
telegram.setwait 10
wlog telegram.getMe$ 'get the user’s informations
timer0 5000, getmessages
wait

getmessages:
'Receive the messages
r$ = telegram.getUpdates$ 'get the new messages
wlog r$, time$
text$ = json$(r$, "text")
if (text$ <> "not found") then
  c$ = json$(r$, "from.chat.id")   'get the chat_id
'  c = val(c$) 'return chat id into a numeric value
'  wlog telegram.sendmessage$(c, "echo : " + text$)
  wlog wget$("https://api.telegram.org/bot"+token$+"/sendMessage?chat_id="+c$+"&text="+ text$)

end if
return

auguro buon lavoro
Post Reply