2026-02-09 22:30:38 +01:00
|
|
|
#include "LichessBoard.h"
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
LichessBoard::LichessBoard(const char *token)
|
|
|
|
|
: apiToken(token), streaming(false), lastHeartbeat(0)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
client.setInsecure();
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
void LichessBoard::setMoveCallback(std::function<void(String, String, String, String)> callback)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
|
|
|
|
onMoveReceived = callback;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
void LichessBoard::setGameStateCallback(std::function<void(String)> callback)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
|
|
|
|
onGameStateChanged = callback;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
bool LichessBoard::connectToGame(const char *gameId)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
currentGameId = String(gameId);
|
2026-02-09 07:38:28 +01:00
|
|
|
Serial.println("Connexion à Lichess...");
|
2026-02-09 22:30:38 +01:00
|
|
|
|
2026-02-09 07:38:28 +01:00
|
|
|
if (!client.connect("lichess.org", 443))
|
|
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Échec connexion SSL");
|
2026-02-09 07:38:28 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
String request = String("GET /api/board/game/stream/") + gameId + " HTTP/1.1\r\n" +
|
|
|
|
|
"Host: lichess.org\r\n" +
|
|
|
|
|
"Authorization: Bearer " + apiToken + "\r\n" +
|
|
|
|
|
"Connection: keep-alive\r\n\r\n";
|
2026-02-09 07:38:28 +01:00
|
|
|
|
|
|
|
|
client.print(request);
|
|
|
|
|
Serial.println("Requête envoyée, attente réponse...");
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Lire les headers HTTP
|
|
|
|
|
while (client.connected())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
|
|
|
|
String line = client.readStringUntil('\n');
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("Header: " + line);
|
|
|
|
|
|
2026-02-09 07:38:28 +01:00
|
|
|
if (line == "\r" || line.length() == 0)
|
|
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
break;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streaming = true;
|
|
|
|
|
lastHeartbeat = millis();
|
|
|
|
|
Serial.println("Stream démarré!");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
void LichessBoard::loop()
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
if (!streaming)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
return;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (millis() - lastHeartbeat > heartbeatTimeout)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("⏱️ Timeout stream!");
|
2026-02-09 07:38:28 +01:00
|
|
|
stop();
|
2026-02-09 22:30:38 +01:00
|
|
|
return;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
while (client.available())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
|
|
|
|
String line = client.readStringUntil('\n');
|
2026-02-09 22:30:38 +01:00
|
|
|
line.trim();
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// ✅ Ligne vide = heartbeat
|
|
|
|
|
if (line.length() == 0)
|
|
|
|
|
{
|
|
|
|
|
lastHeartbeat = millis();
|
|
|
|
|
Serial.println("💓 Heartbeat");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// ✅ Ignorer chunks HTTP
|
|
|
|
|
if (isHexString(line))
|
|
|
|
|
{
|
|
|
|
|
Serial.println("🔸 Chunk HTTP ignoré: " + line);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// ✅ Traiter JSON
|
|
|
|
|
if (line[0] == '{')
|
|
|
|
|
{
|
|
|
|
|
parseLine(line);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Serial.println("⚠️ Ligne ignorée: " + line);
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (!client.connected())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Connexion perdue");
|
2026-02-09 07:38:28 +01:00
|
|
|
stop();
|
|
|
|
|
}
|
2026-02-09 22:30:38 +01:00
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
void LichessBoard::stop()
|
|
|
|
|
{
|
|
|
|
|
if (streaming)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
client.stop();
|
|
|
|
|
streaming = false;
|
|
|
|
|
currentGameId = "";
|
|
|
|
|
Serial.println("⏹️ Stream arrêté");
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
2026-02-09 22:30:38 +01:00
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
LichessBoard::Move LichessBoard::parseMove(const String &uci)
|
|
|
|
|
{
|
|
|
|
|
Move move;
|
|
|
|
|
move.uci = uci;
|
|
|
|
|
move.from = uci.substring(0, 2);
|
|
|
|
|
move.to = uci.substring(2, 4);
|
|
|
|
|
move.isCastling = false;
|
|
|
|
|
move.isKingSide = false;
|
|
|
|
|
move.display = uci; // Par défaut, afficher l'UCI
|
|
|
|
|
|
|
|
|
|
// Détecter les roques
|
|
|
|
|
if ((move.from == "e1" || move.from == "e8") &&
|
|
|
|
|
(move.to == "g1" || move.to == "g8" ||
|
|
|
|
|
move.to == "c1" || move.to == "c8"))
|
|
|
|
|
{
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
move.isCastling = true;
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (move.to[0] == 'g')
|
|
|
|
|
{
|
|
|
|
|
// Petit roque
|
|
|
|
|
move.isKingSide = true;
|
|
|
|
|
move.display = "O-O";
|
|
|
|
|
Serial.println("🏰 PETIT ROQUE (O-O)");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Grand roque
|
|
|
|
|
move.isKingSide = false;
|
|
|
|
|
move.display = "O-O-O";
|
|
|
|
|
Serial.println("🏰 GRAND ROQUE (O-O-O)");
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
return move;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
void LichessBoard::parseLine(const String &line)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
lastHeartbeat = millis();
|
|
|
|
|
|
|
|
|
|
StaticJsonDocument<2048> doc;
|
|
|
|
|
DeserializationError error = deserializeJson(doc, line);
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (error)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.print("❌ Erreur JSON: ");
|
|
|
|
|
Serial.println(error.c_str());
|
2026-02-09 07:38:28 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.print("📦 JSON reçu (");
|
|
|
|
|
Serial.print(line.length());
|
|
|
|
|
Serial.println(" bytes)");
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (!doc.containsKey("type"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("⚠️ Pas de champ 'type'");
|
2026-02-09 07:38:28 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *type = doc["type"];
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.print("✅ Type: ");
|
|
|
|
|
Serial.println(type);
|
2026-02-09 07:38:28 +01:00
|
|
|
|
|
|
|
|
if (strcmp(type, "gameFull") == 0)
|
|
|
|
|
{
|
|
|
|
|
Serial.println("=== Partie complète reçue ===");
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (doc.containsKey("id"))
|
|
|
|
|
{
|
|
|
|
|
const char *gameId = doc["id"];
|
|
|
|
|
if (gameId)
|
|
|
|
|
{
|
|
|
|
|
Serial.print("Game ID: ");
|
|
|
|
|
Serial.println(gameId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (doc["state"].containsKey("status"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
const char *state = doc["state"]["status"];
|
|
|
|
|
if (state)
|
|
|
|
|
{
|
|
|
|
|
Serial.print("État: ");
|
|
|
|
|
Serial.println(state);
|
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
|
|
if (onGameStateChanged)
|
|
|
|
|
{
|
|
|
|
|
onGameStateChanged(String(state));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("📢 État partie: " + String(doc["state"]["status"].as<const char *>()));
|
|
|
|
|
|
|
|
|
|
if (doc["state"].containsKey("moves"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
String moves = doc["state"]["moves"].as<String>();
|
2026-02-09 07:38:28 +01:00
|
|
|
Serial.print("Coups joués: ");
|
|
|
|
|
Serial.println(moves);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (doc.containsKey("initialFen"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
|
|
|
|
Serial.print("FEN: ");
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println(doc["initialFen"].as<String>());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Serial.println("FEN: startpos");
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(type, "gameState") == 0)
|
|
|
|
|
{
|
|
|
|
|
Serial.println("=== Nouveau coup ===");
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (doc.containsKey("moves"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
String allMoves = doc["moves"].as<String>();
|
|
|
|
|
Serial.print("Tous les coups: ");
|
|
|
|
|
Serial.println(allMoves);
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (allMoves.length() > 0)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
int lastSpace = allMoves.lastIndexOf(' ');
|
|
|
|
|
String lastMoveUci = (lastSpace >= 0) ? allMoves.substring(lastSpace + 1) : allMoves;
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (lastMoveUci.length() >= 4)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
// ✅ Parser le coup
|
|
|
|
|
lastMove = parseMove(lastMoveUci);
|
|
|
|
|
|
|
|
|
|
// Affichage avec notation standard
|
|
|
|
|
Serial.print("🎯 Coup: ");
|
|
|
|
|
Serial.println(lastMove.display);
|
|
|
|
|
|
|
|
|
|
if (lastMove.isCastling)
|
|
|
|
|
{
|
|
|
|
|
Serial.print(" Détails: ");
|
|
|
|
|
Serial.print(lastMove.from);
|
|
|
|
|
Serial.print(" -> ");
|
|
|
|
|
Serial.print(lastMove.to);
|
|
|
|
|
Serial.print(" (");
|
|
|
|
|
Serial.print(lastMove.isKingSide ? "petit roque" : "grand roque");
|
|
|
|
|
Serial.println(")");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Serial.println("\n🎯 NOUVEAU COUP:");
|
|
|
|
|
Serial.println(" De: " + lastMove.from);
|
|
|
|
|
Serial.println(" À: " + lastMove.to);
|
|
|
|
|
Serial.println(" Notation: " + lastMove.display);
|
|
|
|
|
|
|
|
|
|
if (doc.containsKey("status"))
|
|
|
|
|
{
|
|
|
|
|
Serial.print("État: ");
|
|
|
|
|
Serial.println(doc["status"].as<String>());
|
|
|
|
|
Serial.println();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (onMoveReceived)
|
|
|
|
|
{
|
|
|
|
|
String fen = doc.containsKey("fen") ? doc["fen"].as<String>() : "";
|
|
|
|
|
onMoveReceived(lastMove.from, lastMove.to, lastMove.uci, fen);
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (doc.containsKey("status"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
const char *status = doc["status"];
|
|
|
|
|
Serial.println("📢 État partie: " + String(status));
|
|
|
|
|
|
|
|
|
|
if (onGameStateChanged)
|
|
|
|
|
{
|
|
|
|
|
onGameStateChanged(String(status));
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-09 22:30:38 +01:00
|
|
|
else if (strcmp(type, "chatLine") == 0)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("💬 Message chat reçu");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Serial.println("⚠️ Type inconnu: " + String(type));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
bool LichessBoard::isHexString(const String &str)
|
|
|
|
|
{
|
|
|
|
|
if (str.length() == 0 || str.length() > 8)
|
|
|
|
|
return false;
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
for (char c : str)
|
|
|
|
|
{
|
|
|
|
|
if (!isxdigit(c))
|
|
|
|
|
return false;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
2026-02-09 22:30:38 +01:00
|
|
|
return true;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
bool LichessBoard::streamCurrentGame()
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("🔍 Recherche de la partie en cours...");
|
|
|
|
|
|
|
|
|
|
WiFiClientSecure tempClient;
|
|
|
|
|
tempClient.setInsecure();
|
|
|
|
|
|
|
|
|
|
if (!tempClient.connect("lichess.org", 443))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Échec connexion pour récupérer les parties");
|
|
|
|
|
return false;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Requête pour obtenir les parties en cours
|
|
|
|
|
String request = "GET /api/account/playing HTTP/1.1\r\n" +
|
|
|
|
|
String("Host: lichess.org\r\n") +
|
|
|
|
|
"Authorization: Bearer " + apiToken + "\r\n" +
|
|
|
|
|
"Accept: application/json\r\n" +
|
|
|
|
|
"Connection: close\r\n\r\n";
|
|
|
|
|
|
|
|
|
|
tempClient.print(request);
|
|
|
|
|
|
|
|
|
|
// Lire les headers
|
|
|
|
|
while (tempClient.connected())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
String line = tempClient.readStringUntil('\n');
|
|
|
|
|
if (line == "\r" || line.length() == 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Lire le body JSON
|
|
|
|
|
String jsonResponse = "";
|
|
|
|
|
while (tempClient.available())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
jsonResponse += tempClient.readString();
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
2026-02-09 22:30:38 +01:00
|
|
|
tempClient.stop();
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("📥 Réponse API:");
|
|
|
|
|
Serial.println(jsonResponse);
|
|
|
|
|
|
|
|
|
|
// ⚠️ ALLOCATION DYNAMIQUE SUR LE HEAP
|
|
|
|
|
DynamicJsonDocument *doc = new DynamicJsonDocument(4096);
|
|
|
|
|
DeserializationError error = deserializeJson(*doc, jsonResponse);
|
|
|
|
|
|
|
|
|
|
if (error)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.print("❌ Erreur parsing JSON: ");
|
|
|
|
|
Serial.println(error.c_str());
|
|
|
|
|
return false;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Vérifier s'il y a des parties en cours
|
|
|
|
|
if (!(*doc).containsKey("nowPlaying") || (*doc)["nowPlaying"].size() == 0)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Aucune partie en cours");
|
|
|
|
|
return false;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Récupérer la première partie (la plus récente)
|
|
|
|
|
JsonObject firstGame = (*doc)["nowPlaying"][0];
|
|
|
|
|
const char *gameId = firstGame["gameId"];
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (!gameId)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Impossible de récupérer l'ID de partie");
|
2026-02-09 07:38:28 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.print("✅ Partie trouvée: ");
|
|
|
|
|
Serial.println(gameId);
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Afficher infos supplémentaires
|
|
|
|
|
if (firstGame.containsKey("opponent"))
|
|
|
|
|
{
|
|
|
|
|
const char *opponent = firstGame["opponent"]["username"];
|
|
|
|
|
Serial.print(" Adversaire: ");
|
|
|
|
|
Serial.println(opponent);
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (firstGame.containsKey("isMyTurn"))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
bool myTurn = firstGame["isMyTurn"];
|
|
|
|
|
Serial.print(" Mon tour: ");
|
|
|
|
|
Serial.println(myTurn ? "Oui" : "Non");
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
// Se connecter au stream de cette partie
|
|
|
|
|
return connectToGame(gameId);
|
|
|
|
|
}
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
bool LichessBoard::streamMyGames()
|
|
|
|
|
{
|
|
|
|
|
Serial.println("🎮 Démarrage du stream de toutes mes parties...");
|
2026-02-09 07:38:28 +01:00
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
if (!client.connect("lichess.org", 443))
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
Serial.println("❌ Échec connexion SSL");
|
2026-02-09 07:38:28 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
String request = "GET /api/board/game/stream/incoming HTTP/1.1\r\n" +
|
|
|
|
|
String("Host: lichess.org\r\n") +
|
|
|
|
|
"Authorization: Bearer " + apiToken + "\r\n" +
|
|
|
|
|
"Connection: keep-alive\r\n\r\n";
|
|
|
|
|
|
|
|
|
|
client.print(request);
|
|
|
|
|
Serial.println("📡 Stream de toutes les parties démarré");
|
|
|
|
|
|
|
|
|
|
// Lire les headers
|
|
|
|
|
while (client.connected())
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
String line = client.readStringUntil('\n');
|
|
|
|
|
Serial.println("Header: " + line);
|
|
|
|
|
|
|
|
|
|
if (line == "\r" || line.length() == 0)
|
2026-02-09 07:38:28 +01:00
|
|
|
{
|
2026-02-09 22:30:38 +01:00
|
|
|
break;
|
2026-02-09 07:38:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 22:30:38 +01:00
|
|
|
streaming = true;
|
|
|
|
|
lastHeartbeat = millis();
|
|
|
|
|
Serial.println("✅ Stream actif!");
|
|
|
|
|
|
2026-02-09 07:38:28 +01:00
|
|
|
return true;
|
|
|
|
|
}
|