Kein Display, kein Tastenfeld: WLAN und Token auf 12 ESP32-C3-Laborknoten bringen
Von English mit KI übersetzt ·
ok, das ist für ein Uni-Projekt, sorry falls das das falsche Unterforum ist. Wir bauen 12 kleine Luftqualitätsknoten (ESP32-C3 SuperMini + SCD41 + ein PMS5003), die in verschiedene Labore auf dem Campus kommen und über MQTT an unsere Hermetry-Organisation berichten. Sie haben kein Display, und der einzige Knopf ist BOOT.Im Moment sind SSID, Passwort und das Geräte-Zugangstoken alles #defines im Sketch, also bekommt jeder Knoten seinen eigenen Build. Für 2 Prototypen war das in Ordnung, für 12 ist es das nicht, und die Labortechniker, die die Geräte umstellen, können die IDE nicht bedienen.Was ich möchte: auf alle dieselbe Firmware flashen, dann vor Ort mit dem Handy mit dem Knoten verbinden, das Labor-WLAN eingeben, und der Knoten bekommt irgendwie seine eigene Hermetry-Zugangsdaten. Ich habe WiFiManager gefunden, und der Captive-Portal-Teil funktioniert auf dem Labortisch. Beim Token habe ich keine Ahnung. Gibt es eine übliche Methode dafür, oder fest codieren alle einfach?
ok so this is for a uni project, sorry if it’s the wrong sub-forum. We’re building 12 little air quality nodes (ESP32-C3 SuperMini + SCD41 + a PMS5003) that go into different labs across campus and report to our Hermetry org over MQTT. They have no display and the only button is BOOT.
Right now the SSID, password and the device access token are all #defines in the sketch, so every node gets its own build. That was fine for 2 prototypes, it’s not fine for 12, and the lab techs who’ll move them around can’t run the IDE.
What I want: flash one identical firmware on all of them, then on site someone joins a phone to the node, types the lab Wi-Fi, and the node gets its own Hermetry credential somehow. I found WiFiManager and the captive portal part works on the bench. The token part I have no idea. Is there a normal way people do this, or does everyone just hardcode?
Von English mit KI übersetzt ·
Vielleicht eine dumme Frage, aber warum schreibt man das WLAN nicht einfach einmal in den Code, wenn es doch alles im selben Campus ist?
Possibly a dumb question but why not just put the Wi-Fi in the code once, if it’s all the same campus?
Von English mit KI übersetzt ·
Leider nicht überall dasselbe Netzwerk. Zwei Gebäude hängen an einer separaten IoT-SSID, ein Labor hat einen eigenen Router, und die Passwörter werden jedes Semester gewechselt. Außerdem müssen die Tokens ohnehin für jeden Knoten unterschiedlich sein.
Not the same network everywhere sadly. Two buildings are on a separate IoT SSID, one lab has its own router, and the passwords get rotated each term. Plus the tokens have to be different per node anyway.
Von English mit KI übersetzt ·
WPS? BOOT 3 s gedrückt halten, Taste am Router drücken, fertig. Habe ich vor Jahren bei ein paar Lagerscannern gemacht.
WPS? Hold BOOT for 3 s, press the button on the router, done. Did that on some warehouse scanners years ago.
Von English mit KI übersetzt ·
WPS ist auf praktisch jedem verwalteten Netzwerk, das ich gesehen habe, deaktiviert. An einer Uni würde ich nicht darauf setzen. Verwendet ihr den Arduino-Core oder ESP-IDF? IDF bringt eine Provisioning-Komponente über SoftAP oder BLE mit, die angenehmer ist als ein Captive Portal.
WPS is switched off on pretty much every managed network I’ve seen, I wouldn’t count on it at a uni. Are you on the Arduino core or ESP-IDF? IDF has a provisioning component over SoftAP or BLE that’s nicer than a captive portal.
Von English mit KI übersetzt ·
Arduino-Core 2.0.14 in PlatformIO. Ich bleibe gern bei WiFiManager für den Wi-Fi-Teil, hänge aber am Hermetry-Token. Ich möchte auch nicht die Konsole öffnen, 12 Geräte anlegen und 12 Token in 12 Portale kopieren, wenn ich das vermeiden kann.
Arduino core 2.0.14 in PlatformIO. Happy to stay with WiFiManager for the Wi-Fi bit, it’s the Hermetry token I’m stuck on. I don’t want to open the console and create 12 devices and copy 12 tokens into 12 portals either if I can avoid it.
Von English mit KI übersetzt ·
Du brauchst im Firmware-Code überhaupt keine Tokens pro Gerät. Teile das Problem in zwei Teile.WLAN: Behalte WiFiManager bei. Wenn du einen gut lesbaren Gerätenamen möchtest, füge im Portal ein benutzerdefiniertes Feld hinzu, andernfalls verwende die MAC.Token: Lass den Knoten sein eigenes anfordern. Öffne im Geräteprofil den Reiter Provisioning, setze die Strategie auf Allow creating new devices, speichere, klicke dann auf Create key und kopiere das Secret (es wird nur einmal angezeigt). Dieser Schlüssel mit Secret ist für alle 12 Builds gleich. Beim ersten Start verbindet sich der Knoten mit dem Benutzernamen provision und einem leeren Passwort, abonniert v1/provision/res und veröffentlicht seine Anfrage. Die Antwort enthält sein Zugriffstoken; du speicherst es im NVS, und ab dann meldet sich der Knoten normal an.
// first boot only, after Wi-Fi is up
mqtt.setServer(host, 8883); // WiFiClientSecure, TLS
mqtt.connect(clientId, "provision", "");
mqtt.subscribe("v1/provision/res", 1);
String req = String("{"deviceName":"aq-") + mac6 +
"","provisionDeviceKey":"pk_xxx","provisionDeviceSecret":"ps_xxx"}";
mqtt.publish("v1/provision/req", req.c_str());
// in the callback: parse credentialsValue when status == "SUCCESS",
// prefs.putString("tok", value); then reconnect with the token as username
Zwei Dinge haben uns auf einer Pharma-Anlage erwischt. Neue Geräte, die so angelegt werden, landen in Quarantäne: Sie verbinden sich, aber ihre Daten werden verworfen, bis ein Administrator sie aktiviert. Sag deshalb dem Verantwortlichen der Organisation, dass er nach ihnen suchen soll. Außerdem muss der Name eindeutig sein; eine zweite Anfrage mit demselben Namen erhält device_exists, weil nie zweimal eine Zugangsdaten ausgegeben wird. Lösche den NVS deshalb nicht leichtfertig. Details stehen unter Adding and claiming devices.
You don’t need per-device tokens in the firmware at all. Split it in two problems.
Wi-Fi: keep WiFiManager. Add one custom field in the portal if you want a friendly device name, otherwise use the MAC.
Token: let the node ask for its own. On the device profile open the Provisioning tab, set the strategy to Allow creating new devices, save, then Create key and copy the secret (it’s shown once). That key + secret is the same for all 12 builds. On first boot the node connects with username provision and an empty password, subscribes to v1/provision/res and publishes its request. The answer carries its access token, you store that in NVS and from then on it logs in normally.
// first boot only, after Wi-Fi is up
mqtt.setServer(host, 8883); // WiFiClientSecure, TLS
mqtt.connect(clientId, "provision", "");
mqtt.subscribe("v1/provision/res", 1);
String req = String("{"deviceName":"aq-") + mac6 +
"","provisionDeviceKey":"pk_xxx","provisionDeviceSecret":"ps_xxx"}";
mqtt.publish("v1/provision/req", req.c_str());
// in the callback: parse credentialsValue when status == "SUCCESS",
// prefs.putString("tok", value); then reconnect with the token as username
Two things bit us on a pharma site. New devices created this way land in quarantine, they connect but their data is dropped until an admin activates them, so tell whoever owns the org to look for them. And the name must be unique, a second request with the same name gets device_exists because it never hands out a credential twice. So never wipe NVS casually. Details are on Adding and claiming devices.
Von English mit KI übersetzt ·
Das hat funktioniert, alle 12 sind online. Ich bin sofort auf das device_exists-Problem gestoßen, weil ich beim Debuggen den Flash von Knoten 3 gelöscht hatte; er war bereits als aq-3c84a1 registriert. Ich habe das Gerät in der Konsole gelöscht, danach wurde es problemlos neu provisioniert. Heute Morgen habe ich alle aus der Quarantäne aktiviert. Außerdem musste ich die Anführungszeichen richtig escapen, meine erste Version hat fehlerhaftes JSON gesendet und ich habe einfach keine Antwort bekommen.
That worked, all 12 are up. I did hit the device_exists thing straight away because I’d erased flash on node 3 while debugging, it had already registered as aq-3c84a1. Deleted that device in the console and it provisioned again fine. Activated them all from quarantine this morning. Also had to escape the quotes properly, my first version sent broken JSON and just got nothing back.
Von English mit KI übersetzt ·
Wir machen dasselbe bei unseren Liniensensoren. Ein Tipp aus der Halle: Den Namen des Setup-APs auf einen Aufkleber am Gehäuse drucken. Sechs Monate später erinnert sich niemand mehr, welcher Knoten „ESP-3C84A1“ ist.
We do the same on our line sensors. One tip from the floor: print the setup AP name on a sticker on the case. Nobody remembers which node is „ESP-3C84A1“ six months later.
Von English mit KI übersetzt ·
+1 zum Aufkleber. Falls in einigen dieser Labore nur ein Enterprise-WLAN mit benutzerspezifischer Anmeldung verfügbar ist, reicht ein einfaches Captive Portal nicht aus; dann bräuchte man Felder für Identität/Benutzername und WPA2-Enterprise in der Firmware. Bitten Sie die IT stattdessen um ein PSK-IoT-Netz, das ist deutlich weniger Aufwand.
+1 to the sticker. Also if any of those labs only has enterprise Wi-Fi with a per-user login, a plain captive portal can’t do it, you’d need identity/username fields and WPA2-Enterprise in the firmware. Ask IT for a PSK IoT network instead, much less pain.
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.
Mitdiskutieren
Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

