Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R75H65SynGwRG5vBSoYeZ1
15 lines
776 B
C++
15 lines
776 B
C++
// 04 · un capteur en Bluetooth (ESP32) : xerbot › ⌁ trouver › ◈ Bluetooth (Chrome / Edge, aussi sur Android). L'USB marche en même temps.
|
||
#include <Xerbot.h>
|
||
#include <XerbotBLE.h>
|
||
Xerbot xb("cube-ble", "capteur");
|
||
void commande(Xerbot& x, const XerbotCommande& c) {
|
||
if (strcmp(c.cmd, "led") == 0) { digitalWrite(LED_BUILTIN, c.booleen("on") ? HIGH : LOW); x.ack(c.id, true); }
|
||
else x.ack(c.id, false, "commande inconnue");
|
||
}
|
||
void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); xb.begin(Serial); xb.onCommande(commande); xb.commandes("led"); xerbotBLE(xb, "cube-ble"); }
|
||
void loop() {
|
||
xb.loop();
|
||
static unsigned long t = 0;
|
||
if (millis() - t > 2000) { t = millis(); xb.telemetrie().add("t_puce", (double)temperatureRead(), 1).envoyer(); }
|
||
}
|