si_tyler
@twilson · Mitglied seit März 2026
System integrator · energy · 15 years in the field
- Themen
- 3
- Antworten
- 21
- Punkte
- 0
Erstellte Forenantworten
Von English mit KI übersetzt ·
Habe vor ein paar Jahren eines davon mit meinem Kind gebaut und beide Fehler gemacht.Winkel: Kombiniere die beiden Sensoren mit einem komplementären Filter. Das Gyroskop ist kurzfristig gut, der Beschleunigungssensor langfristig:
// fixed 200 Hz loop from a hardware timer, dt = 0.005
float accAngle = atan2f(ax, az) * RAD_TO_DEG;
angle = 0.98f * (angle + gy * dt) + 0.02f * accAngle;
Verwende eine feste Schleifenrate von einem Timer statt millis()-Differenzen in einer ausgelasteten Schleife, und halte MQTT vollständig aus dieser Schleife heraus. Wilsons DMP-Ansatz funktioniert auch, bindet dich aber an die Bibliothek dieses Chips.PID: Beginne nur mit P und erhöhe es, bis der Roboter um die aufrechte Position schwingt, dann füge D hinzu, bis die Schwingung abklingt, danach ein kleines I gegen Drift. Und addiere das Totband der Motoren zum Ausgang, Getriebemotoren drehen sich unterhalb weniger Prozent Tastverhältnis nicht.Daten: Sammle Samples in der schnellen Schleife, dezimiere auf 20 Hz und sende eine Nachricht pro Sekunde als Array von Datensätzen mit eigenen Zeitstempeln:
[
{"ts": 1767600000000, "values": {"bal.angle": 0.42, "bal.out": 12.5, "bal.speed": 3.1}},
{"ts": 1767600000050, "values": {"bal.angle": 0.38, "bal.out": 11.9, "bal.speed": 3.0}},
...
]
Das ergibt 1 Nachricht pro Sekunde mit 20 x 3 = 60 Datenpunkten, innerhalb der Standardwerte pro Gerät (10 Nachrichten pro Sekunde, 200 Punkte pro Sekunde und 6.000 pro Minute). Dein Tarif hat außerdem ein organisationsweites Limit für Datenpunkte pro Minute, also prüfe unter Nutzung, falls andere Geräte stark ausgelastet sind. Der ESP32 benötigt NTP-Zeit für ts, andernfalls lasse ts weg. Ein Diagramm über die letzten 24 Stunden zeigt jeden Rohpunkt, sodass die Tuning-Kurven scharf bleiben. Payload-Formate: MQTT-Themen und Payload-Referenz.
Built one of these with my kid a couple of years ago and made both mistakes.
Angle: combine the two sensors with a complementary filter. The gyro is good short-term, the accelerometer long-term:
// fixed 200 Hz loop from a hardware timer, dt = 0.005
float accAngle = atan2f(ax, az) * RAD_TO_DEG;
angle = 0.98f * (angle + gy * dt) + 0.02f * accAngle;
Use a fixed loop rate from a timer, not millis() differences in a busy loop, and keep MQTT out of that loop entirely. Wilson’s DMP route works too, it just ties you to that chip’s library.
PID: start with P only and raise it until the robot oscillates around upright, then add D until the oscillation dies down, then a small I for drift. And add the motors‘ deadband to the output, gear motors don’t move below a few percent duty.
Data: collect samples in the fast loop, decimate to 20 Hz, and send one message per second as an array of records with their own timestamps:
[
{"ts": 1767600000000, "values": {"bal.angle": 0.42, "bal.out": 12.5, "bal.speed": 3.1}},
{"ts": 1767600000050, "values": {"bal.angle": 0.38, "bal.out": 11.9, "bal.speed": 3.0}},
...
]
That is 1 message a second with 20 x 3 = 60 data points, inside the per-device defaults (10 messages a second, 200 points a second and 6,000 a minute). Your plan has an organisation-wide data points per minute limit too, so check Usage if other devices are busy. The ESP32 needs NTP time for ts, otherwise leave ts out. A chart over the last 24 hours shows every raw point, so the tuning curves stay sharp. Payload forms: MQTT topics and payload reference.
Von English mit KI übersetzt ·
Eine Erfahrung aus dem Feld: Gestalten Sie den Befehlssatz als Zustand, niemals als Umschalten. Ein Befehl, bei dem ein Timeout auftritt, bedeutet nur, dass keine Antwort zurückkam; er könnte trotzdem ausgeführt worden sein. Drückt der Supervisor erneut, ist fan.set on zweimal unschädlich, fan.toggle zweimal schaltet den Lüfter wieder aus.
One thing from the field: make the command set a state, never toggle. A command that times out only means no answer came back, it may have run anyway. If the supervisor presses again, fan.set on twice is harmless, fan.toggle twice turns it off.
Von English mit KI übersetzt ·
Ich dachte, es gibt in den Dashboards eine Option „Bericht senden“?
I thought there was a „send report“ option on dashboards?
Von English mit KI übersetzt ·
Ich betreibe etwa dreißig dieser kleinen Gateways in Umspannwerken, nach demselben Muster.Overlay für das Root-Dateisystem ist aktiv, ja. Nimm deine RaspAP-Änderungen mit ausgeschaltetem Overlay vor, starte neu und schalte es danach wieder ein. Lästig, aber selten.Der Puffer braucht einen Ort, der Neustarts und Stromausfälle übersteht: eine zweite Partition auf der Karte (oder ein USB-Stick), mit ext4 und Journal schreibend eingebunden, außerhalb des Overlays. Richte SQLite dorthin, mit PRAGMA journal_mode=WAL und synchronous=NORMAL. Ein Abbruch kostet dann höchstens die letzten Schreibvorgänge, nicht die Datenbank. Verschiebe auch die Persistenz von mosquitto dorthin oder schalte sie ab, da dein Forwarder ohnehin puffert.Zu Rachels Frage: Ja, wenn du jeden Messwert beim Senden durch den ESP mit ts in UTC-Millisekunden versiehst (nur wenn die Uhr des Pi synchronisiert ist, was sie nach dem Start von 4G ist, und behalte eine fake-hwclock bei, damit es nach einem Stromausfall nicht 1970 ist). Sende den Rückstau gebündelt pro Child:
{"esp-bed3": [{"ts": 1767254400000, "values": {"soil_pct": 41}},
{"ts": 1767254460000, "values": {"soil_pct": 41}}]}
Die Datensätze landen zu ihrer eigenen Zeit in der Historie. Eine Nachricht, deren Datensätze alle älter als eine Minute sind, gilt als Replay und muss zur Replay-Rate des Profils passen, daher wird ein langer Rückstau über einige Zeit abgebaut. Keine Panik, wenn nicht alles in einer Sekunde erscheint. Und warte auf das PUBACK, bevor du Zeilen löschst. Siehe Devices behind a gateway.
I run about thirty of these little gateways on substations, same pattern.
Overlay on for the root filesystem, yes. Do your RaspAP changes with the overlay switched off, reboot, switch it back on. Annoying but rare.
The buffer needs a place that survives reboots and power loss: a second partition on the card (or a USB stick) mounted read-write with ext4 and its journal, outside the overlay. Point SQLite there, with PRAGMA journal_mode=WAL and synchronous=NORMAL. A cut then costs you at most the last few writes, not the database. Move mosquitto’s persistence there too, or turn persistence off since your forwarder already buffers.
On Rachel’s question: yes, if you stamp each reading with ts in UTC milliseconds when the ESP sends it (only if the Pi’s clock is synced, which it is once 4G is up, and keep a fake-hwclock so it isn’t 1970 after a power cut). Send the backlog in batches per child:
{"esp-bed3": [{"ts": 1767254400000, "values": {"soil_pct": 41}},
{"ts": 1767254460000, "values": {"soil_pct": 41}}]}
Records land at their own time in history. A message whose every record is older than a minute counts as a replay and has to fit the profile’s replay rate, so a long backlog drains over a while. Don’t panic when it doesn’t all appear in one second. And wait for the PUBACK before deleting rows. See Devices behind a gateway.
Von English mit KI übersetzt ·
Dann ist es das. Ein Pi 3 hat keine echte Echtzeituhr. Beim Booten stellt er die Zeit wieder her, die er beim letzten sauberen Herunterfahren gespeichert hat (fake-hwclock), und wartet dann auf NTP. Dein Lab-Netzwerk blockiert NTP (UDP 123), also bleibt die Uhr in der Vergangenheit, und für die TLS-Bibliothek ist das Serverzertifikat noch nicht gültig. Das habe ich bei der Inbetriebnahme schon auf der Hälfte der Feld-Pis hinter abgeschotteten Firewalls gesehen.Lösungen, wähle eine:
# 1. die interne NTP-Adresse bei der IT erfragen und verwenden
sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.your-lab.example
sudo systemctl restart systemd-timesyncd
timedatectl # "System clock synchronized: yes"
# 2. falls nur 443 offen ist: Synchronisation über HTTPS-Header
sudo apt install htpdate
sudo htpdate -s https://www.example.org
Die fest eingetragene IP entfernen. Der Broker benötigt SNI, also über den Hostnamen verbinden; das Zertifikat wird ohnehin gegen diesen Namen geprüft, deshalb kam die Abweichung zustande. Einfaches client.tls_set() mit dem System-CA-Bundle reicht aus; Tyler, für Token-Logins wird kein Client-Zertifikat benötigt, der Server fordert eines an, verlangt es aber nicht.Außerdem sollte das Skript vor dem Verbinden auf eine synchronisierte Uhr warten, sonst bricht ein Neustart im Lab die Verbindung erneut ab. Eine kurze Schleife über timedatectl show -p NTPSynchronized funktioniert. Siehe den TLS-Abschnitt von MQTT.
That’s it then. A Pi 3 has no real time clock. At boot it restores the time it saved at the last clean shutdown (fake-hwclock) and then waits for NTP. Your lab network blocks NTP (UDP 123), so the clock stays in the past, and to the TLS library the server certificate isn’t valid yet. Seen this on half the field Pis I’ve commissioned behind locked-down firewalls.
Fixes, pick one:
# 1. ask IT for the internal NTP server and use it
sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.your-lab.example
sudo systemctl restart systemd-timesyncd
timedatectl # "System clock synchronized: yes"
# 2. if only 443 is open: sync from HTTPS headers
sudo apt install htpdate
sudo htpdate -s https://www.example.org
Undo the hardcoded IP. The broker needs SNI, so connect by host name, and the certificate is checked against that name anyway, which is why you got the mismatch. Plain client.tls_set() with the system CA bundle is fine; Tyler, no client certificate is needed for token logins, the server asks for one but doesn’t require it.
Also make the script wait for a synced clock before connecting, otherwise a reboot in the lab breaks it again. A quick loop on timedatectl show -p NTPSynchronized works. See the TLS section of MQTT.
Von English mit KI übersetzt ·
Auf dem Prüfstand teilen sich beide Netzteile den Schutzleiter des Stromnetzes, daher liegen die „isolierten“ Seiten über die Versorgungskapazität wahrscheinlich näher beieinander, als Sie denken.
On the bench both power supplies share mains earth, so the „isolated“ sides are probably closer to each other than you think through supply capacitance.

