veille-cloud.ino
SEMI_AUTOMATIC mode takes back control of the cloud link: the script blinks fast when the cloud is lost, slow when fine, and retries every minute. The deployment reflex for a battery board or moody Wi-Fi.
Hardware
A Particle Boron module (nRF52840, Wi-Fi + Bluetooth LE, cellular variant where applicable) with on-board antenna. None (D7 LED built in).
Wiring
Nothing to wire. Power: USB, LiPo or 3.6-5.5 V on VIN.
How it works
Particle.connected() reflects the link state; Particle.process() feeds the cloud state machine without blocking. After a long outage, WiFi.connect + Particle.connect restart the session.
Running it
Install the Particle CLI (particle setup), flash with particle flash --serial or OTA (particle flash <name> firmware.bin). The Device Cloud app or REST API complete the deployment.
Variants
Add a hardware watchdog (System.reset) if the link does not return after N minutes, or publish an alert event on disconnect.
veille-cloud.ino
// Indicateur de sante reseau : LED + Particle.process() manuel.
// Utile quand le module doit survivre a des coupures Wi-Fi.
unsigned long derniereVerif = 0;
bool etaitConnecte = false;
void setup() {
pinMode(D7, OUTPUT);
Serial.begin(9600);
// Mode SEMI_AUTOMATIC : a nous de maintenir le lien.
Particle.process();
}
void loop() {
bool connecte = Particle.connected();
if (connecte != etaitConnecte) {
etaitConnecte = connecte;
Serial.println(connecte ? "CLOUD: connecte" : "CLOUD: perdu");
}
// Feux de circulation : rapide si nuage perdu, fixe sinon.
bool clignote = (millis() / (connecte ? 1000 : 150)) % 2;
digitalWrite(D7, clignote);
// Battee du lien cloud (non bloquant, a appeler souvent).
Particle.process();
if (millis() - derniereVerif >= 60000) {
derniereVerif = millis();
if (!connecte) {
Serial.println("Tentative de reconnexion...");
WiFi.connect();
Particle.connect();
}
}
}
// En AUTOMATIC (defaut), le framework fait deja tout seul :
// ce montage sert aux builds SEMI/MANUAL ou tres occupes.