xerbot-arduino/examples/04-ble-capteur/04-ble-capteur.ino

15 lines
755 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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); 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(); }
}