HowTo onewire
Hardware: -cp210x
Connect GND and 5V to DS18B20.
connect RX and TX together and to the data line of 1-wire.
Connect pull-up 4.7 k from 5 V to data line.
Actually I did not need pull-up resistor.
digitemp-doku: http://www.digitemp.com/documentation.shtml
Lösung "owfs mit owshell"
Auf der Konfigurationsstufe von OpenWrt sind folgende Module auszuwählen:
Kernel modules:
USB Support:
<M> kmod-usb-serial
<M> kmod-usb-serial-cp210x
Utilities:
Filesystem:
<M> owfs
<M> owshell
<M> digitemp
Alle Aktivitäten mit einem Ein-Draht-Sensor in OpenWrt sind mit Hilfe von 2 Programmen möglich. Treten wir zuerst dem Programm digitemp näher.
Installieren wir die Pakete:
[email protected]:/# opkg install kmod-usb-serial-cp210x Installing kmod-usb-serial-cp210x (2.6.36.2-1) to root... Downloading ftp://ftp:[email protected]/kmod-usb-serial-cp210x_2.6.36.2-1_brcm47xx.ipk. Installing kmod-usb-serial (2.6.36.2-1) to root... Downloading ftp://ftp:[email protected]/kmod-usb-serial_2.6.36.2-1_brcm47xx.ipk. Configuring kmod-usb-serial. Configuring kmod-usb-serial-cp210x. [email protected]:/# opkg install digitemp Installing digitemp (3.6.0-3) to root... Downloading ftp://ftp:[email protected]/digitemp_3.6.0-3_brcm47xx.ipk. Configuring digitemp. |
Die Netzstruktur eines one-wire Sensors besteht aus einem Adapter und den Sensoren selbst. Der Adapter konvertiert das USB Protokoll zu einem 1-wire Sensor. Und die Sensoren können der Reihe nach angeschlossen werden. Das
Schließen wir den Adapter an den USB-Port des Routers an und prüfen wir die Ausgabe dmesg:
[email protected]:/# dmesg usb 1-1.4: new full speed USB device using ohci_hcd and address 4 cp210x 1-1.4:1.0: cp210x converter detected usb 1-1.4: reset full speed USB device using ohci_hcd and address 4 usb 1-1.4: cp210x converter now attached to ttyUSB0 |
Der Adapter wird vom System als ttyUSB0 definiert. Jetzt schließen wir einen Sensor an den Adapter an. Es ist ziemlich leicht das Programm digitemp zu verwenden. Zuerst initialisieren wir wie folgt:
[email protected]:/# digitemp_DS9097 -i -s /dev/ttyUSB0 DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane GNU Public License v2.0 - http://www.digitemp.com Turning off all DS2409 Couplers . Searching the 1-Wire LAN 265576BA000000DF : DS2438 Temperature, A/D Battery Monitor ROM #0 : 265576BA000000DF Wrote .digitemprc |
Wie wir sehen können hat das digitemp bei dieser Operation mit der Suche nach einem Busgerät von 1-wire begonnen, in deren Ergebnis unser Sensor — 265576BA000000DF : DS2438 Temperature, A/D Battery Monitor gefunden wurde.
Weiter, um die Temperatur- und Spannungswerte von unserem Sensor ablesen zu können, ist Folgendes zu tätigen:
[email protected]:/# digitemp_DS9097 -a -A -l /home/1wire_log DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane GNU Public License v2.0 - http://www.digitemp.com |
Machen wir die Datei mit dem Log auf und prüfen wir die Temperatur- und Spannungswerte am ADC-Eingang.
[email protected]:/# cat /home/1wire_log Jan 01 00:01:44 Sensor 0 VDD: 5.06 AD: 4.98 CAD: -1018 C: 24.59 |
Wie wir sehen können, ist der Temperaturwert 24.59C, und die Spannungswert 4.98V. Die Messgenauigkeit ist ziemlich hoch. Hier kann man die Beschreibung der Aktivitäten mit dem digitemp beenden, wobei darauf noch hinzuweisen ist, dass man die Liste der verfügbaren Optionen sehen kann, wenn man digitemp_DS9097 -h schreibt.
Installieren wir die Pakete für das Programm owfs:
[email protected]:/# opkg install owshell owfs Installing owshell (2.8p4-1) to root... Downloading ftp://ftp:[email protected]/owshell_2.8p4-1_brcm47xx.ipk. Installing libow (2.8p4-1) to root... Downloading ftp://ftp:[email protected]/libow_2.8p4-1_brcm47xx.ipk. Installing libusb (0.1.12-2) to root... Downloading ftp://ftp:[email protected]/libusb_0.1.12-2_brcm47xx.ipk. Installing libpthread (0.9.31-64) to root... Downloading ftp://ftp:[email protected]/libpthread_0.9.31-64_brcm47xx.ipk. Installing librt (0.9.31-64) to root... Downloading ftp://ftp:[email protected]/librt_0.9.31-64_brcm47xx.ipk. Installing owfs (2.8p4-1) to root... Downloading ftp://ftp:[email protected]/owfs_2.8p4-1_brcm47xx.ipk. Installing libfuse (2.8.5-1) to root... Downloading ftp://ftp:[email protected]/libfuse_2.8.5-1_brcm47xx.ipk. Installing kmod-fuse (2.6.36.2-1) to root... Downloading ftp://ftp:[email protected]/kmod-fuse_2.6.36.2-1_brcm47xx.ipk. Installing fuse-utils (2.8.5-1) to root... Downloading ftp://ftp:[email protected]/fuse-utils_2.8.5-1_brcm47xx.ipk. Configuring librt. Configuring libpthread. Configuring libusb. Configuring libow. Configuring owshell. Configuring kmod-fuse. Configuring libfuse. Configuring fuse-utils. Configuring owfs. |
Owfs ist ein Ein-Draht-Dateisystem. Es erstellt diverse Loge und überwacht alles! Owhttpd ist dasselbe System, aber mit einem Web-Server. Owfs passt perfekt für den Bau der eindrähtigen Netzwerke. Alles ist bis ins Detail durchdacht und es gibt eine Menge der Möglichkeiten.
Die Anwendung Owhttpd kann auf das Dateisystem in der aktuellen
Version von OpenWrt bei der Paketeninstallation nicht kopiert werden.
Deshalb kann man dies selbst machen, wobei man die Datei owhttpd von
hier kopiert:
openwrt/build_dir/target-mipsel_uClibc-0.9.31/owfs-2.8p4/module/owhttpd/src/c/.libs
Beim Starten von owfs hat man den Montierungspunkt sowie auch den Adaptertyp anzugeben (ich habe ds9097).
[email protected]:/# owfs -d /dev/ttyUSB0 /home/1wire/ |
Beim Starten ist der Merker --debug anzugeben, damit der Testbetrieb gestartet werden kann. Nach dem Start von owfs wird ein Dateisystem in dem installierten Verzeichnis erstellt:
[email protected]:/# ls -l /home/1wire/ drwxr-xr-x 1 root root 8 Jan 1 00:02 drwxrwxrwx 1 root root 8 Jan 1 00:02 26.5576BA000000 drwxr-xr-x 1 root root 8 Jan 1 00:02 settings drwxrwxrwx 1 root root 8 Jan 1 00:02 simultaneous drwxr-xr-x 1 root root 8 Jan 1 00:02 statistics drwxr-xr-x 1 root root 30 Jan 1 00:02 structure drwxr-xr-x 1 root root 8 Jan 1 00:02 system drwxr-xr-x 1 root root 8 Jan 1 00:02 uncached |
Um den Temperaturwert zu erkennen, prüfen wir den Verzeichnisinhalt des Sensors:
[email protected]:/# ls -l /home/1wire/26.5576BA000000 -r--r--r-- 1 root root 16 2011-02-16 20:52 address -r--r--r-- 1 root root 256 2011-02-16 20:52 alias drwxrwxrwx 1 root root 8 2011-02-16 20:56 B1-R1-A -rw-rw-rw- 1 root root 1 2011-02-16 20:56 CA -r--r--r-- 1 root root 2 2011-02-16 20:52 crc8 -rw-rw-rw- 1 root root 24 2011-02-16 20:52 date drwxrwxrwx 1 root root 8 2011-02-16 20:56 disconnect -rw-rw-rw- 1 root root 1 2011-02-16 20:56 EE drwxrwxrwx 1 root root 8 2011-02-16 20:56 endcharge -r--r--r-- 1 root root 2 2011-02-16 20:52 family drwxrwxrwx 1 root root 8 2011-02-16 20:56 HIH3600 drwxrwxrwx 1 root root 8 2011-02-16 20:56 HIH4000 drwxrwxrwx 1 root root 8 2011-02-16 20:56 HTM1735 -r--r--r-- 1 root root 12 2011-02-16 20:52 humidity -rw-rw-rw- 1 root root 1 2011-02-16 20:56 IAD -r--r--r-- 1 root root 12 2011-02-16 20:52 id -r--r--r-- 1 root root 16 2011-02-16 20:52 locator drwxrwxrwx 1 root root 8 2011-02-16 20:56 MultiSensor -rw-rw-rw- 1 root root 12 2011-02-16 20:56 offset drwxrwxrwx 1 root root 8 2011-02-16 20:56 pages -r--r--r-- 1 root root 16 2011-02-16 20:52 r_address -r--r--r-- 1 root root 12 2011-02-16 20:52 r_id -r--r--r-- 1 root root 16 2011-02-16 20:52 r_locator drwxrwxrwx 1 root root 8 2011-02-16 20:56 S3-R1-A -r--r--r-- 1 root root 12 2011-02-16 20:52 temperature -r--r--r-- 1 root root 32 2011-02-16 20:52 type -rw-rw-rw- 1 root root 12 2011-02-16 20:56 udate -r--r--r-- 1 root root 12 2011-02-16 20:56 VAD -r--r--r-- 1 root root 12 2011-02-16 20:56 VDD -r--r--r-- 1 root root 12 2011-02-16 20:56 vis |
[email protected]:/# cat ./temperature 22.3125 |
Weiter starten wir den Web-Server und prüfen seine Optionen:
[email protected]:/# owhttpd -d /dev/ttyUSB0 -p 8080Lösung "digitemp"
opkg update
opkg install digitemp
# It is installed in this directory:
cd /usr/bin
/usr/bin/digitemp_DS9097 -i -s /dev/ttyUSB0
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
..
Searching the 1-Wire LAN
28CC5F0E0200005C : DS18B20 Temperature Sensor
26E27927010000E5 : DS2438 Temperature, A/D Battery Monitor
ROM #0 : 28CC5F0E0200005C
ROM #1 : 26E27927010000E5
Wrote .digitemprc
# read sensors and store in file
digitemp_DS9097 -a -A -l 1wire_log
# display file
cat 1wire_log
Jan 01 00:45:19 Sensor 1 VDD: 4.94 AD: 1.40 CAD: 3 C: 34.75
Jan 01 00:45:25 Sensor 0 C: 24.88 F: 76.78
Jan 01 00:45:26 Sensor 1 VDD: 4.93 AD: 1.38 CAD: 30 C: 34.25
Jan 01 00:45:47 Sensor 0 C: 24.75 F: 76.55
DS2438
AD is humidity sensor
CAD is photodiode
C is built in temperature sensor
VDD is battery monitor