@maximealive ho messo su anche io un ESP32 di prova.
Ho fatto solo alcune piccole modifiche al tuo sketch originario e mi sono reso conto che nel tuo sketch, tu non hai configurato l'ESP32 per recuperare l'ora corretta dai server NTP.
Non ne sono certo, ma la data di sistema credo venga usata dalla libreria ClientSSL che si occupa dell'encrypt SSL per la verifica del certificato.
Purtroppo le librerie incluse nel core non funzionano con l'ethernet (e mi pare una grande stupidaggine
).
Comunque, vediamo se anche il mio si blocca ed eventualmente aggiungo la gestione della data.
Questo lo sketch (ho aggiunto solo un comando per vedere lo stato dell'heap ed implementato la funzione per la verifica dell'id)
#include <SPI.h>
#include <Ethernet.h>
#include <SSLClient.h>
#include <WiFi.h>
#include <AsyncTelegram2.h>
#include <tg_certificate.h>
const char* token = "xxxxxx";
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 2, 177);
IPAddress myDns(192, 168, 2, 1);
EthernetClient base_client;
SSLClient client(base_client, TAs, (size_t)TAs_NUM, A0, 1, SSLClient::SSL_ERROR );
AsyncTelegram2 myBot(client);
ReplyKeyboard myReplyKbd;
#define RELAY_CANCELLO 17
#define RELAY_PEDONALE 16
#define RELAY_BOX_LETTERE 33
#define RELAY_TRASFORMATORE 25
#define CHAT_ID_1 123456789
#define CHAT_ID_2 -726659123
int64_t chat_ids[] = {CHAT_ID_1, CHAT_ID_2} ;
bool isAuthorized(int64_t theId) {
for (int i = 0; i < sizeof(chat_ids) / sizeof(int64_t ); i++) {
if (chat_ids[i] == theId)
return true;
}
return false;
}
void setup() {
pinMode(RELAY_CANCELLO, OUTPUT);
pinMode(RELAY_PEDONALE, OUTPUT);
pinMode(RELAY_BOX_LETTERE, OUTPUT);
pinMode(RELAY_TRASFORMATORE, OUTPUT);
digitalWrite(RELAY_CANCELLO, LOW);
digitalWrite(RELAY_PEDONALE, LOW);
digitalWrite(RELAY_BOX_LETTERE, LOW);
digitalWrite(RELAY_TRASFORMATORE, LOW);
// spegnimento modulo wifi
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
SPI.begin();
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(5); // Most Arduino shields
// Open serial communications and wait for port to open:
Serial.begin(115200);
// start the Ethernet connection:
//Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
delay(1000);
// Set the Telegram bot properies
myBot.setUpdateTime(1000);
myBot.setTelegramToken(token);
// Check if all things are ok
Serial.print("\nTest Telegram connection... ");
myBot.begin() ? Serial.println("OK") : Serial.println("NOK");
myReplyKbd.addButton("/cancello");
myReplyKbd.addButton("/pedonale");
myReplyKbd.addButton("/box_lettere");
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg)) {
if (isAuthorized(msg.sender.id)) {
String msgText = msg.text;
if (msgText.equals("/cancello")) {
// apertura - chiusura cancello
digitalWrite(RELAY_CANCELLO, HIGH);
myBot.sendMessage(msg, "Cancello aperto/chiuso");
delay(500);
digitalWrite(RELAY_CANCELLO, LOW);
}
else if (msgText.equals("/pulsanti")) {
// mostra pulsanti anzichè tastiera
myBot.sendMessage(msg, "Pulsanti attivati", myReplyKbd);
}
else if (msgText.equals("/pedonale")) {
// apertura cancello pedonale
digitalWrite(RELAY_PEDONALE, HIGH);
myBot.sendMessage(msg, "Cancello pedonale aperto");
delay(500);
digitalWrite(RELAY_PEDONALE, LOW);
}
else if (msgText.equals("/box_lettere")) {
// apertura scatola
// accensione trasformatore 24V DC- 12V DC
digitalWrite(RELAY_TRASFORMATORE, HIGH);
delay(1000);
myBot.sendMessage(msg, "Box lettere aperto");
// impulso per elettroserratura a 12V
digitalWrite(RELAY_BOX_LETTERE, HIGH);
delay(500);
digitalWrite(RELAY_BOX_LETTERE, LOW);
delay(500);
// spegnimento trasformatore
digitalWrite(RELAY_TRASFORMATORE, LOW);
}
else if (msgText.equals("/heap")) {
snprintf(buf, sizeof(buf), "Total free: %6d - Max block: %6d\n", heap_caps_get_free_size(0), heap_caps_get_largest_free_block(0));
myBot.sendMessage(msg, buf);
}
else {
String reply;
reply = "Welcome " ;
reply += msg.sender.username;
reply += ".\nProva /cancello, /pedonale, o /box_lettere";
reply += ".\nOppure /pulsanti per attivare i pulsanti";
myBot.sendMessage(msg, reply);
}
}
else {
myBot.sendMessage(msg, "Accesso non autorizzato");
}
}
}