🛠 Se connecter au Wi-Fi et publier des événements cloud
Objectives
Configure the Photon's Wi-Fi (Soft AP procedure, not Smart Config as on the older Spark Core), check the connection status via the RGB LED, then publish and receive events using Particle.publish and Particle.subscribe — without writing a single line of networking code, as everything is integrated into the Device OS.
Hardware
- 1 Particle Photon (2.4 GHz Wi-Fi only: Broadcom BCM43362 802.11b/g/n chip, no 5 GHz support)
- a smartphone or computer for Soft AP configuration
- ideally a second Photon to test subscriptions
Complete Code
// photon-wifi-publish.ino — publication d'événements toutes les 10 s
unsigned long derniere = 0;
void setup {
Serial.begin(9600);
Particle.subscribe("door/opened", onDoor); // événement d'un autre appareil
}
void loop {
if (millis - derniere > 10000) {
derniere = millis;
bool ok = Particle.publish("salle/temperature", "21.5", PRIVATE);
Serial.print("publish ok=");
Serial.println(ok ? "1" : "0");
}
delay(50);
}
void onDoor(const char *event, const char *data) {
Serial.print("evenement recu: ");
Serial.print(event);
Serial.print(" data=");
Serial.println(data);
}
Expected Verification
After configuration (long press on SETUP, then connect to the Photon's Soft AP network and enter the Wi-Fi password), the RGB LED breathes cyan: connected to the cloud. particle subscribe my/salle/temperature displays private events. The PRIVATE flag is confirmed by the sample code in the guide.
Common Errors
- 5 GHz Router: the BCM43362 only sees 2.4 GHz, causing the Photon to get stuck.
- Publishing too fast: the cloud limits event throughput, causing publish calls to fail (returning false).
- Unstable Wi-Fi during an OTA update: users report getting stuck in magenta (no cloud connection) after a failed OTA.
- Forgetting that the old api.spark.io endpoint is closed: everything must go through api.particle.io.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino