Bonjour à tous, j'ai encore un problème que je ne sais résoudre:
J'ai développé un circuit et une appli pour contrôler la présence secteur et démarrer un groupe électrogène.
Ceci est piloté par un XIAO ESP32C3.
Tout cela fonctionne parfaitement.
Pour améliorer mon système, j'envisage d'envoyer des notifications sur mon portable pour être informé des évènements.
Et c'est là que mes ennuis commencent: une fois sur deux la routine d'envoi se plante en TIMEOUT.
N'arrivant pas à m'en sortir, j'ai fait une maquette élémentaire avec un ESP32 et le programme suivant:
monitoring après démarrage et le premier enfoncement de touche:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 #include <Arduino.h> #include <WiFiClientSecure.h> #include <WiFi.h> #include "mesData" #define BTN 26 const char *ssid = SECRET_SSID; const char *password = SECRET_PASS; const char *APIKEY = API_KEY; const char* HOST = API_HOST; const uint16_t timeout = 1000; WiFiClientSecure sClient; //******************************Routine d'envoi de notifications********************************* bool envoiNotif(const String &msg) { // Push Envoyer un message String messagebody = R"({"type": "note", "title": "Push du ESP 32", "body": ")" + msg + R"("})"; uint32_t broadcastingTime = millis(); sClient.setInsecure(); //sans protocol https if (!sClient.connect(HOST, 443)) { Serial.println("La connexion a echoue !"); return false; } else { sClient.printf("POST /v2/pushes HTTP/1.1\r\nHost: %s\r\nAuthorization: Bearer %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s\r\n"\ , HOST, APIKEY, messagebody.length(), messagebody.c_str()); broadcastingTime=millis(); Serial.println("Push émis"); } while (!sClient.available()) { uint32_t x = millis() - broadcastingTime; Serial.println(x); if (x > timeout) { Serial.println("Client Timeout !"); sClient.stop(); return false; } } while (sClient.available()) { //Réception d'une réponse Serial.printf("Pushbullet Repond en: %4ld ms\n", millis() - broadcastingTime); //affiche le temps jusqu'à la réponse -> ajustez le délai d'attente en conséquence String line = sClient.readStringUntil('\n'); if (line.startsWith("HTTP/1.1 200 OK")) { sClient.stop(); return true; } } return false; } //*******************Après enfoncement de la touche*************** void testBouton(){ byte tt = digitalRead(BTN); if (tt == LOW){ Serial.println("Bouton enfoncé"); envoiNotif((String)"Hello from ESP32!"); } } //*********************Paramétrage ********************* void setup() { Serial.begin(9600); pinMode(BTN,INPUT_PULLUP); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); //pushbullet((String)"Systemstart "); } //*****************boucle principale void loop(){ testBouton(); delay(500); }
Tout s'est bien passé, j'ai reçu la notification.Connecting to WiFi...
Connected to WiFi
Bouton enfoncé
Push émis
1
1
.
.
.
.
254
254
254
254
254
254
Pushbullet Repond en: 379 ms
Pushbullet Repond en: 379 ms
Pushbullet Repond en: 379 ms
Pushbullet Repond en: 380 ms
Pushbullet Repond en: 502 ms
Pushbullet Repond en: 503 ms
Pushbullet Repond en: 503 ms
Pushbullet Repond en: 503 ms
Pushbullet Repond en: 625 ms
Pushbullet Repond en: 626 ms
Pushbullet Repond en: 626 ms
J'enfonce à nouveau le bouton et là Timeout! :
Je ne sais vraiment pas d'où vient le problème.Bouton enfoncé
[ 32072][E][ssl_client.cpp:37] _handle_error(): [send_ssl_data():382]: (-27136) SSL - A buffer is too small to receive or write a message
Push émis
123
123
123
123
123
.
.
.
.
984
984
984
984
984
984
984
984
984
1106
Client Timeout !
Merci
Partager