u/Arduino_lab64

Arduino

En l'occasion de la coupe du monde 2026, j'ai eu l'idée de créer un système automatisé avec un ESP8266 qui récupère les scores des matchs en cours via une clé API.

Cependant, j'ai des problèmes au niveau du parsing du Json.J'ai l'erreur : "IncompliteJson" dans le moniteur série.

Pouvez-vous m'aider svp, voici mon programme :

#include <ESP8266WiFi.h>

#include <WiFiClientSecureBearSSL.h>

#include <ESP8266HTTPClient.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <ArduinoJson.h>

#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const char* ssid = "#######";

const char* password = "######";

const char* apiHost = "https://v3.football.api-sports.io/fixtures?live=all";

const char* apiKey = "#########";

String chunk = "";

bool franceMatch = false;

String homeTeam = "";

String awayTeam = "";

String homeGoals = "";

String awayGoals = "";

String elapsed = "";

String franceJson = "";

bool capture = false;

void printCentered(String text, int y) {

int16_t x1, y1;

uint16_t w, h;

display.getTextBounds(text, 0, y, &x1, &y1, &w, &h);

int x = (SCREEN_WIDTH - w) / 2;

display.setCursor(x, y);

display.print(text);

}

void setup() {

Serial.begin(115200);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

display.clearDisplay();

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0,0);

display.println("Boot...");

display.display();

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

}

display.clearDisplay();

display.println("WiFi OK");

display.display();

delay(1000);

}

void loop() {

getLiveMatch();

delay(15000);

}

void getLiveMatch() {

std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);

client->setInsecure();

HTTPClient https;

if (!https.begin(*client, apiHost)) {

Serial.println("Erreur connexion API");

return;

}

https.addHeader("x-apisports-key", apiKey);

int httpCode = https.GET();

if (httpCode != 200) {

Serial.println("Erreur HTTP");

https.end();

return;

}

String payload = https.getString();

https.end();

DynamicJsonDocument doc(4096);

DeserializationError error = deserializeJson(doc, payload);

if(error) {

Serial.println(error.c_str());

return;

}

JsonArray response = doc["response"];

if (response.size() == 0) {

showNoMatch();

return;

}

bool found = false;

for (JsonObject match : response) {

String home = match["teams"]["home"]["name"].as<String>();

String away = match["teams"]["away"]["name"].as<String>();

if(home == "France" || away == "France") {

homeTeam = home;

awayTeam = away;

homeGoals = String((int)match["goals"]["home"]);

awayGoals = String((int)match["goals"]["away"]);

if(match["fixture"]["status"]["elapsed"].isNull())

elapsed = "HT";

else

elapsed = String((int)match["fixture"]["status"]["elapsed"]);

found = true;

break;

}

}

if(!found) {

showNoMatch();

return;

}

String homeTeam = response[0]["teams"]["home"]["name"];

String awayTeam = response[0]["teams"]["away"]["name"];

int homeGoals = response[0]["goals"]["home"];

int awayGoals = response[0]["goals"]["away"];

String minute = response[0]["fixture"]["status"]["elapsed"];

display.clearDisplay();

display.setTextSize(1);

printCentered(homeTeam, 0);

display.setTextSize(2);

printCentered(homeGoals + " - " + awayGoals, 20);

display.setTextSize(1);

printCentered(awayTeam, 46);

printCentered(elapsed + "'", 56);

display.display();

}

void showNoMatch() {

display.clearDisplay();

display.setCursor(0,0);

display.println("Aucun match live");

display.display();

}

reddit.com
u/Arduino_lab64 — 3 days ago