#include <Arduino.h>
#include <WiFi.h>
#include <WebSocketsClient.h> // pour la connexion WebSocket
#include <SocketIOclient.h> // pour le client Socket.IO
// Instance du client Socket.IO
SocketIOclient socketIO;
// Remplacez par vos informations réseau
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Définissez l'adresse du serveur et le port
const char* host = "speech-development-tools.glitch.me";
const int port = 443; // Port par défaut pour WSS/HTTPS
// Empreinte numérique du certificat SSL du serveur (SHA1)
const char* fingerprint = "f507bad8424ecae70454effb811f5f12b4c29b4bf58be370a68f19f7e7dd2071";
void eventHandler(socketIOmessageType_t type, uint8_t * payload, size_t length) {
// Gestionnaire d'événements...
switch(type) {
case sIOtype_DISCONNECT:
Serial.printf("[socket] disconnected!\n");
break;
case sIOtype_CONNECT:
Serial.printf("[socket] Connected to url: %s\n", payload);
// socketIO.send(sIOtype_CONNECT, "/");
break;
case sIOtype_EVENT:
Serial.printf("[socket] get event: %s\n", payload);
break;
case sIOtype_ERROR:
Serial.printf("[socket] get error: %u\n", length);
break;
}
}
void setup() {
Serial.begin(115200);
// Connectez-vous au réseau WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Paramétrage de la connexion sécurisée WebSocket (WSS)
socketIO.beginSSL(host, port, "/", fingerprint);
// Définir les gestionnaires d'événements Socket.IO
socketIO.onEvent(eventHandler);
}
void loop() {
// Maintien de la connexion ouverte
socketIO.loop();
}