Zwanzig DS18B20-Sensoren an einem Pi: Ausfälle ab acht Sensoren und wie man die Schlüssel benennt
Von English mit KI übersetzt ·
ok, das sind wohl eigentlich zwei Fragen in einer, sorry.Ich überwache einen kleinen Keller, in dem ich Käse und etwas Hausbrauerei lagere. Raspberry Pi 4, Raspberry Pi OS Bookworm, 1-Wire an GPIO4 mit dtoverlay=w1-gpio. Ich möchte 20 DS18B20-Sensoren (Regal oben/Mitte/unten usw.). Bis zu 8 funktioniert es problemlos. Darüber verschwinden einige Sensoren aus /sys/bus/w1/devices und tauchen wieder auf, und ab und zu liefern ein paar genau 85.0.Zweite Frage: Ich sende sie mit paho-mqtt an Hermetry, eine Veröffentlichung pro Sensor, Schlüssel = die ROM-ID wie 28-0316a2794bff. Ist das eine schlechte Idee? Mein Dashboard sieht aus wie ein Telefonbuch.Verkabelung: 4,7k Pull-up am Pi, Cat5-Leitung zu den Regalen, dann kurze Stichleitungen zu jedem Sensor, insgesamt etwa 15 m.
ok so this is probably two questions in one, sorry.
I’m monitoring a small cellar where I keep cheese and some homebrew. Raspberry Pi 4, Raspberry Pi OS Bookworm, 1-wire on GPIO4 with dtoverlay=w1-gpio. I want 20 DS18B20 probes (rack top/middle/bottom etc). With up to 8 it is fine. Past that some sensors vanish from /sys/bus/w1/devices and come back, and a few read exactly 85.0 now and then.
Second thing: I send them to Hermetry with paho-mqtt, one publish per sensor, key = the ROM id like 28-0316a2794bff. Is that a bad idea? My dashboard looks like a phone book.
Wiring: 4.7k pull-up at the Pi, cat5 run out to the racks, then short legs to each probe, about 15 m total.
Von English mit KI übersetzt ·
Sind die Fühler mit 3 Adern oder im Parasitärbetrieb angeschlossen? Und wie kurz meinen Sie mit kurzen Beinchen?
Are the probes on 3 wires or parasite power? And when you say short legs, how short?
Von English mit KI übersetzt ·
3 Leitungen, 3.3V vom Pi. Die Stichleitungen sind 30 cm bis 1 m lang, es ist eher ein Stern als eine Linie, glaube ich.
3 wires, 3.3V from the Pi. Legs are 30 cm to 1 m, it’s more of a star than a line I guess.
Von English mit KI übersetzt ·
Die Sternverkabelung ist dein Dropout-Problem. 1-Wire mag keine Stichleitungen, jede Abzweigung reflektiert. Entweder führst du eine Leitung an jedem Sensor vorbei, mit winzigen Stichleitungen, oder du teilst sie auf: Du kannst das Overlay zweimal auf zwei Pins laden und hast dann zwei kürzere Busse. Bei so viel Kabel würde ich außerdem 2.2k statt 4.7k probieren.
The star is your dropout problem. 1-wire hates stubs, every leg reflects. Either run one line past every probe with tiny stubs, or split it: you can load the overlay twice on two pins and have two shorter buses. I’d also try 2.2k instead of 4.7k with that much cable.
Von English mit KI übersetzt ·
Wäre es nicht einfacher, einfach auf jedem Rack einen günstigen ESP32 anzubringen? Das würde ich machen, aber ich bin kein Hardware-Experte.
Would it be easier to just put a cheap ESP32 on each rack? That’s what I’d do but I’m not a hardware guy.
Von English mit KI übersetzt ·
James hat die Verkabelung richtig gemacht. Zwei Busse, jeweils 2.2k, dann passt das. Wir betreiben so in einem Pumpenhaus 14 Sonden pro Bus.85.0 ist der Einschaltwert des DS18B20, das bedeutet, dass die Messung vor Abschluss einer Wandlung erfolgte, meist ein Brown-out am Bus. Im Code verwerfen, niemals senden.Bei den Keys jetzt ändern, bevor Historie entsteht. Keys zählen als eindeutige Namen über die gesamte Organisation (Starter begrenzt auf 250), daher verbrauchen ROM-IDs pro Sensor dieses Kontingent schnell, sobald Sie einen zweiten Keller aufbauen. Benennen Sie sie nach Position, führen Sie eine Zuordnung von ROM-ID zu Position in einer Datei auf dem Pi und senden Sie alle 20 in einer Nachricht. Eine Nachricht mit 20 Datenpunkten kostet dasselbe Kontingent wie eine mit einem.
import glob, json, paho.mqtt.client as mqtt
MAP = {"28-0316a2794bff": "rack1.top", "28-0316a27a11ff": "rack1.mid"} # etc
vals = {}
for p in glob.glob("/sys/bus/w1/devices/28-*/temperature"):
rom = p.split("/")[-2]
t = int(open(p).read()) / 1000
if rom in MAP and t != 85.0:
vals["cellar." + MAP[rom]] = round(t, 2)
c.publish("v1/telemetry", json.dumps(vals), qos=1)
Die Regeln für Keys stehen unter Telemetry keys.
James has the wiring right. Two buses, 2.2k each, and you’ll be fine. We run 14 probes per bus in a pump house that way.
85.0 is the power-on value of the DS18B20, it means the read happened before a conversion finished, usually a brown-out on the bus. Drop it in code, never send it.
On the keys, change it now before you have history. Keys count as distinct names across the whole organisation (Starter caps you at 250), so ROM ids per sensor will eat that fast once you build a second cellar. Name them by position, keep a map from ROM id to position in a file on the Pi, and send all 20 in one message. One message with 20 points costs the same quota as one with one.
import glob, json, paho.mqtt.client as mqtt
MAP = {"28-0316a2794bff": "rack1.top", "28-0316a27a11ff": "rack1.mid"} # etc
vals = {}
for p in glob.glob("/sys/bus/w1/devices/28-*/temperature"):
rom = p.split("/")[-2]
t = int(open(p).read()) / 1000
if rom in MAP and t != 85.0:
vals["cellar." + MAP[rom]] = round(t, 2)
c.publish("v1/telemetry", json.dumps(vals), qos=1)
Key rules are on Telemetry keys.
Von English mit KI übersetzt ·
Zwei Busse an GPIO4 und GPIO17, je 2.2k, und ich habe die Leitung entlang der Racks als eine Linie neu verlegt. Seit zwei Tagen 20 von 20, nicht ein einziges 85. Die Schlüssel habe ich ebenfalls umbenannt, das Gerät gelöscht und neu angefangen, da nur eine Woche Daten vorlag. Das Dashboard liest sich jetzt wie ein Weinkeller statt wie eine Liste von Seriennummern. Danke an alle, Kevin vielleicht beim nächsten Build 😉
Two buses on GPIO4 and GPIO17, 2.2k each, and I re-did the run as a line along the racks. 20 of 20 for two days now, not a single 85. Renamed the keys too, deleted the device and started fresh since there was only a week of data. Dashboard reads like a cellar now instead of a serial number list. Thanks all, Kevin maybe next build 😉
Von English mit KI übersetzt ·
Eine kleine Sache, wenn Sie schon dabei sind: Legen Sie das Geräte-Token in eine Datei, die nur Ihr Dienstbenutzer lesen kann, und nicht in das Skript. Ich habe zu viele davon in Git-Repositories gesehen.
One small thing while you’re in there: put the device token in a file only your service user can read, not in the script. Saw too many of those in git repos.
- 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.

