xerbot 0.1.0 : le contrat xerbot v1 pour Arduino / PlatformIO (USB, ESP-NOW, Bluetooth), 6 exemples dont RuView CSI, test natif 8/8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R75H65SynGwRG5vBSoYeZ1
This commit is contained in:
cloudion
2026-11-04 19:32:55 +00:00
commit 5452df71a7
16 changed files with 560 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// 01 · un capteur en USB (n'importe quelle carte Arduino : ESP32, ESP8266, Pico, Uno…)
// Branche en USB, ouvre le ploxion xerbot › ⌁ trouver › ⎍ USB : « cube-capteur » apparaît, sa télémétrie arrive, « ◎ ping » répond.
#include <Xerbot.h>
Xerbot xb("cube-capteur", "capteur");
const int LED = LED_BUILTIN;
void commande(Xerbot& x, const XerbotCommande& c) {
if (strcmp(c.cmd, "led") == 0) { digitalWrite(LED, 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, OUTPUT); xb.begin(Serial); xb.onCommande(commande); }
void loop() {
xb.loop();
static unsigned long t = 0;
if (millis() - t > 2000) { t = millis(); xb.telemetrie().add("a0", (long)analogRead(A0)).add("uptime_s", (long)(millis() / 1000)).envoyer(); }
}

View File

@@ -0,0 +1,23 @@
// 02 · un nœud ESP-NOW (ESP32 / ESP8266) : sans Wi-Fi ni Internet, il parle à la passerelle (exemple 03) jusqu'à ~200 m.
// Il apparaît dans xerbot avec le badge ESPNOW ; « led » allume sa LED. Mets la MAC de ta passerelle pour ne pas diffuser.
#include <Xerbot.h>
#include <XerbotEspNow.h>
Xerbot xb("noeud-1", "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.onCommande(commande);
xerbotEspNowNoeud(xb /*, macPasserelle */);
}
void loop() {
xb.loop();
static unsigned long t = 0;
#if defined(ESP32)
if (millis() - t > 2000) { t = millis(); xb.telemetrie().add("t_puce", (double)temperatureRead(), 1).add("rssi", (long)WiFi.RSSI()).envoyer(); }
#else
if (millis() - t > 2000) { t = millis(); xb.telemetrie().add("a0", (long)analogRead(A0)).envoyer(); }
#endif
}

View File

@@ -0,0 +1,6 @@
// 03 · la passerelle ESP-NOW (ESP32 / ESP8266) : branchée en USB (au PC, ou à un Raspberry Pi Zero 2 W), elle relaie tous les nœuds.
// xerbot › ⌁ trouver › ⎍ USB : chaque nœud apparaît (badge ESPNOW) ; leurs commandes repartent par elle.
#include <Xerbot.h>
#include <XerbotEspNow.h>
void setup() { Serial.begin(115200); xerbotEspNowPasserelle(Serial); }
void loop() { xerbotEspNowLoop(); }

View File

@@ -0,0 +1,14 @@
// 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(); }
}

View File

@@ -0,0 +1,26 @@
// 05 · RuView : la présence par le Wi-Fi (ESP32, pas S2). Il écoute le canal (CSI) des paquets qu'envoie un AUTRE ESP32 (l'exemple 02, qui
// diffuse toutes les 2 s ; mets son intervalle à 50 ms pour une belle cascade) et envoie {"csi":[amplitudes],"rssi":…} en USB.
// Le ploxion ruview (bouton ⎍ brancher un ESP32) les dessine : calme / présence / mouvement. Deux ESP32 face à face, 2 à 5 m.
#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_now.h>
static volatile bool pret = false; static int8_t buf[384]; static int len = 0, rssi = 0;
static void csiCb(void*, wifi_csi_info_t* info) {
if (pret || !info || !info->buf) return;
len = info->len > 384 ? 384 : info->len; memcpy(buf, info->buf, len); rssi = info->rx_ctrl.rssi; pret = true;
}
void setup() {
Serial.begin(921600); // le CSI est bavard : 921600 bauds (règle-le aussi dans le ploxion si besoin)
WiFi.mode(WIFI_STA); esp_now_init(); // ESP-NOW ouvre la radio sur le canal 1, comme l'émetteur
wifi_csi_config_t cfg = {}; cfg.lltf_en = true; cfg.htltf_en = true; cfg.stbc_htltf2_en = true; cfg.ltf_merge_en = true; cfg.channel_filter_en = false; cfg.manu_scale = false;
esp_wifi_set_promiscuous(true); esp_wifi_set_csi_config(&cfg); esp_wifi_set_csi_rx_cb(csiCb, nullptr); esp_wifi_set_csi(true);
}
void loop() {
if (!pret) return;
// le tampon = des paires (imaginaire, réel) par sous-porteuse → l'amplitude
Serial.print("{\"csi\":[");
int n = len / 2; if (n > 64) n = 64;
for (int k = 0; k < n; k++) { float im = buf[2 * k], re = buf[2 * k + 1]; Serial.print(sqrtf(im * im + re * re), 1); if (k + 1 < n) Serial.print(','); }
Serial.print("],\"rssi\":"); Serial.print(rssi); Serial.print("}\n");
pret = false;
}

View File

@@ -0,0 +1,8 @@
// 06 · le plus petit : un Arduino Uno / Nano (AVR, 2 Ko de RAM). USB seulement ; une ligne de 128 caractères max.
#include <Xerbot.h>
Xerbot xb("uno", "capteur");
void commande(Xerbot& x, const XerbotCommande& c) {
if (strcmp(c.cmd, "led") == 0) { digitalWrite(13, c.booleen("on") ? HIGH : LOW); x.ack(c.id, true); } else x.ack(c.id, false);
}
void setup() { Serial.begin(115200); pinMode(13, OUTPUT); xb.battement(30000); xb.begin(Serial); xb.onCommande(commande); }
void loop() { xb.loop(); static unsigned long t = 0; if (millis() - t > 3000) { t = millis(); xb.telemetrie().add("a0", (long)analogRead(A0)).envoyer(); } }