🛠 Se connecter au Wi-Fi et publier des événements cloud

Particle Photon · intermediaire · Schéma : IMG-particle-photon-intermediaire-1-photon-wifi-publish.svg — Photon connecté en Wi-Fi au Particle Cloud via un routeur, événements publish diffusés vers d'autres appareils

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials