🛠 Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1

Arduino GIGA R1 · intermediaire · Schéma : IMG-giga-r1-i3-1-mqtt-wifi.svg — Le module Wi-Fi Murata 1DX embarqué du GIGA R1 relié sans fil à un routeur, puis à un courtier MQTT et un serveur HTTP sur Internet.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials