🛠 Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1
Objectives
Connect the GIGA R1 to the Internet using its embedded Wi-Fi + Bluetooth LE module (Murata LBEE5KL1DX-883, external antenna). You will implement a robust HTTP request by applying the documented workaround for TCP blocking (bug #937: read the entire response body, otherwise one in five connections fails with -3005) and you will avoid the crash caused by a global WiFiClient object (bug #753).
Hardware
- 1 Arduino GIGA R1 WiFi board
- A 2.4 GHz Wi-Fi network with SSID and password
- A PC with Arduino IDE and the ArduinoHttpClient library (Libraries > Library Manager)
- Optional: a public MQTT broker to test publishing
Complete Code
// GIGA R1 WiFi — HTTP GET robuste (contournement du blocage TCP, bogue #937)
#include <Arduino.h>
#include <WiFi.h>
#include <ArduinoHttpClient.h>
const char* SSID = "votre-ssid";
const char* PASS = "votre-pass";
void connexionWifi {
WiFi.begin(SSID, PASS);
unsigned long debut = millis;
while (WiFi.status != WL_CONNECTED && millis - debut < 20000) delay(200);
if (WiFi.status == WL_CONNECTED) Serial.println(WiFi.localIP);
}
void setup {
Serial.begin(115200);
connexionWifi;
}
void loop {
// Client en variable locale : un objet global a provoque un crash de l'OS (bogue #753)
WiFiClient wifi;
HttpClient client(wifi, "example.com", 80);
client.get("/");
// Vider entierement le corps de reponse, sinon ~1 connexion sur 5 echoue (-3005)
while (client.available) Serial.write(client.read);
client.stop;
Serial.println("\n--- requete terminee ---");
delay(10000);
}
For MQTT, replace the HttpClient layer with the PubSubClient library: client.connect("giga", "user", "pass") then client.publish("home/temp", "21.5") to port 1883 of your broker.
Expected Verification
The Serial Monitor displays the IP address obtained via DHCP, then the HTML content of the retrieved page every 10 seconds, without a 30-second block. In MQTT, the broker receives the message published to the chosen topic.
Common Errors
- Response body not drained: random -3005 blocks every ~5 connections (bug #937, workaround: always read everything or space out requests).
WiFiClient wifi;declared globally: documented OS crash (bug #753); declare it inside the function.- 5 GHz Wi-Fi only: the 1DX module works on networks supported by the core; verify that the SSID is visible.
- Corrupted radio firmware after updates: Wi-Fi becomes unusable (bug #650); with the Zephyr core, rerun the FlashFormat sketch to restore the 1DX module firmware.
- SSID/password with accented characters in the source code: authentication failure.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino GIGA R1
- Bouton poussoir et console série sur le GIGA R1
- Potentiomètre et sortie DAC sur la prise audio du GIGA R1
- Piloter un micro-servo avec la PWM du GIGA R1
- Connecter un capteur I2C sur le GIGA R1
- Programmer les deux cœurs M7 et M4 du GIGA R1 et les faire communiquer
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino