Announcement

Collapse
No announcement yet.

DigiTemp with a USB 1-Wire 9097 on a remote RPi2

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    DigiTemp with a USB 1-Wire 9097 on a remote RPi2

    A rewrite of the original post.

    This post is only related to running a base RPi2 / Wheezy configuration with a 1-wire network using 9097 USB device.

    Originally this RPi2 was running Jessie Lite and would crash in less than 30 days.

    Note that this post is using Digitemp and Rob's Homeseer script.
    Thank you Rob for letting me use your script.
    Note too that you will have to adjust your script for multiple 1-wire devices.

    Please keep the same directory structure as described below for Rob's Homeseer script to work.

    Hardware:

    1 - RPi2 - with Wheezy
    2 - PiFace RTC shim
    3 - ZWave dot me GPIO card
    4 - USB - Serial 1-Wire sensor - USB9097
    5 - Temperature and Humidity sensors - here using 5 of them on the second floor.
    6 - Hobby Boards Lightning sensor

    [ATTACH]62042[/ATTACH]

    Software:

    1 - Digitemp
    2 - Samba
    3 - mono Mono JIT compiler version 5.0.1.1 * this RPi2 is a remote Z-Wave/GPIO device.

    1 - Make digitemp directory and install digitemp

    A - SSH to your RPi
    B - type mkdir /opt/digitemp
    C - type apt-get update
    D - type apt-get install digitemp *NOTE: I have compiled newest version of Digitemp (Digitemp 3.7.1), zipped two files and attached to this post.
    replace the files in /usr/bin with attached files.
    E - create symbolic link
    type n -s /usr/digitemp_DS9097 /usr/bin/digitemp
    F - Initialize Digitemp
    type digitemp -i -s /dev/ttyUSB0 -q -c /etc/digitemp.conf

    28CFD8F4020000F5 : DS18B20 Temperature Sensor
    268CC814000000DC : DS2438 Temperature, A/D Battery Monitor
    26993AF50000008F : DS2438 Temperature, A/D Battery Monitor
    26B3CA1400000096 : DS2438 Temperature, A/D Battery Monitor
    263B3AF5000000BD : DS2438 Temperature, A/D Battery Monitor
    1D37C907000000FC : DS2423 4Kbit RAM + Counter
    ROM #0 : 28CFD8F4020000F5
    ROM #1 : 268CC814000000DC
    ROM #2 : 26993AF50000008F
    ROM #3 : 26B3CA1400000096
    ROM #4 : 263B3AF5000000BD
    ROM #5 : 1D37C907000000FC

    This is what my digitemp.conf formatting looks like:

    cat /etc/digitemp.conf

    Code:
    TTY /dev/ttyUSB0
    READ_TIME 2000
    LOG_TYPE 1
    LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F"
    CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
    HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
    SENSORS 6
    ROM 0 0x28 0xCF 0xD8 0xF4 0x02 0x00 0x00 0xF5 
    ROM 1 0x26 0x8C 0xC8 0x14 0x00 0x00 0x00 0xDC 
    ROM 2 0x26 0x99 0x3A 0xF5 0x00 0x00 0x00 0x8F 
    ROM 3 0x26 0xB3 0xCA 0x14 0x00 0x00 0x00 0x96 
    ROM 4 0x26 0x3B 0x3A 0xF5 0x00 0x00 0x00 0xBD 
    ROM 5 0x1D 0x37 0xC9 0x07 0x00 0x00 0x00 0xFC
    J - test one liner.
    cd /opt/digitemp;/usr/bin/digitemp -a -q -c /etc/digitemp.conf > /opt/digitemp/temp.txt

    K - create cron job which write /opt/digitemp/temp.txt every 5 minutes
    cd /etc; nano crontab

    */5 * * * * root cd /opt/digitemp;/usr/bin/digitemp -a -q -c /etc/digitemp.conf > /opt/digitemp/temp.txt

    2 - Install Samba and share /opt/digitemp directory to guest user and no password

    A - apt-get update; apt-get install samba

    B - nano /etc/samba/samba.conf

    C - change your workgroup to any name you want or leave it at default

    D - add the following to the end of the samba.conf file.

    [ICS-Znet] ;the share name can be what ever you want
    browseable = yes
    path = /opt/digitemp
    guest ok = yes
    read only = no
    create mask = 777

    E - reboot

    E - SSH to your homeseer server and type:
    mkdir /HomeSeer/Bin/1-wire

    F - go to your Homeseer server and do a nano fstab
    add the following to fstab

    //192.168.244.169/ICS-Znet /HomeSeer/Data/1-wire cifs guest,uid=1000,iocharset=utf8 0 0

    G - go to your homeseer server and type:
    cat /HomeSeer/Bin/1-wire/temp.txt

    Your 1-wire directory is now the the directory where digitemp is writing the temp.txt file.

    Rob's script modded to work with combo temperature and humidity sensors.

    Code:
    Imports System.IO
    ''1WireTemp.vb - Rob Mason - 7/30/2015 - Free to use/modify. 
    ''reads in the content of a temp file created by the 1-wire.
    Sub Main(parm as object) 
        dim FTemp,CTemp,Humid as Short
       'dim FTemp,CTemp,Humid as Double
       dim lin,t,h,x,n,s() as String 
       dim sr as StreamReader 
       dim sensor0_Temp_Ref as Integer = 260       'use your own device references 
       '' New Bathroom combo sensor
       dim sensor1_Temp_Ref as Integer = 1529 
       dim sensor1_Humid_Ref as Integer = 1530
       '' Hallway combo sensor 
       dim sensor2_Temp_Ref as Integer = 261
       dim sensor2_Humid_Ref as Integer = 262
       '' Master Bedroom combo sensor
       dim sensor3_Temp_Ref as Integer = 1532
       dim sensor3_Humid_Ref as Integer = 1533
       '' Study combo sensor - end one
       dim sensor4_Temp_Ref as Integer = 1534
       dim sensor4_Humid_Ref as Integer = 1535
    
    
       Try 
          sr = new StreamReader("/HomeSeer/Data/1-wire/temp.txt")       ''point this to your temp file
            while(1) 
                    lin=sr.ReadLine() 
                    if(lin is nothing) then exit while
                    if(lin.length()<=0) then exit while
                    s = Split(lin,"Sensor ") 
                    t = s(1) 
                    n = left(t,t.indexOf(" ")).Trim ''contains sensor number
                    s = Split(t,"C: ") 
                    CTemp = CDBL(left(s(1),s(1).indexOf(" ")).Trim) 
                    FTemp = getFarenheit(CTemp) 
                    s = Split(t,"H: ") 
                    if(s.length>1) then 
                            Humid=CDBL(left(s(1),s(1).indexOf("%")).Trim) 
                    else 
                            Humid=0 
                    end if
                  ''hs.writeLog("debug","t=[" & t & "]  n=[" & n & "] CTemp=[" & CTemp & "] FTemp=[" & FTemp & "] Humid=[" & Humid & "]")
                    Select case n 
                            case 0 
                            ''update HomeSeer here with the device references above 
                            hs.setDeviceValueByRef(sensor0_Temp_Ref,FTemp,True)     ''change to CTemp if you want Celsius 
                            hs.setDeviceLastChange(sensor0_Temp_Ref,Now()) 
                            hs.setDeviceString(sensor0_Temp_Ref,FTemp & " °F",False) 
                            case 1 
                            hs.setDeviceValueByRef(sensor1_Temp_Ref,FTemp,True)     ''change to CTemp if you want Celsius 
                            hs.setDeviceLastChange(sensor1_Temp_Ref,Now()) 
                            hs.setDeviceString(sensor1_Temp_Ref,FTemp & " °F",False)
                            if(humid>0) then 
                                    hs.setDeviceValueByRef(sensor1_Humid_Ref,humid,True)    ''change to CTemp if you want Celsius
                                    hs.setDeviceLastChange(sensor1_Humid_Ref,Now()) 
                                    hs.setDeviceString(sensor1_Humid_Ref,humid & "% RH",False) 
                            end if
                            '' Bathroom combo add
                            case 2
                            hs.setDeviceValueByRef(sensor2_Temp_Ref,FTemp,True)     ''change to CTemp if you wa$
                            hs.setDeviceLastChange(sensor2_Temp_Ref,Now())
                            hs.setDeviceString(sensor2_Temp_Ref,FTemp & " °F",False)
                            if(humid>1) then
                                    hs.setDeviceValueByRef(sensor2_Humid_Ref,humid,True)    ''change to CTemp i$
                                    hs.setDeviceLastChange(sensor2_Humid_Ref,Now())
                                    hs.setDeviceString(sensor2_Humid_Ref,humid & "% RH",False)
                            end if
                            '' Master Bedroom combo add
                            case 3
                            hs.setDeviceValueByRef(sensor3_Temp_Ref,FTemp,True)     ''change to CTemp if you wa$
                            hs.setDeviceLastChange(sensor3_Temp_Ref,Now())
                            hs.setDeviceString(sensor3_Temp_Ref,FTemp & " °F",False)
                            if(humid>2) then
                                    hs.setDeviceValueByRef(sensor3_Humid_Ref,humid,True)    ''change to CTemp i$
                                    hs.setDeviceLastChange(sensor3_Humid_Ref,Now())
                                    hs.setDeviceString(sensor3_Humid_Ref,humid & "% RH",False)
    
                            end if
                            '' Study combo add
                            case 4
                            hs.setDeviceValueByRef(sensor4_Temp_Ref,FTemp,True)     ''change to CTemp if you wa$
                            hs.setDeviceLastChange(sensor4_Temp_Ref,Now())
                            hs.setDeviceString(sensor4_Temp_Ref,FTemp & " °F",False)
                            if(humid>3) then
                                    hs.setDeviceValueByRef(sensor4_Humid_Ref,humid,True)    ''change to CTemp i$
                                    hs.setDeviceLastChange(sensor4_Humid_Ref,Now())
                                    hs.setDeviceString(sensor4_Humid_Ref,humid & "% RH",False)
    
                            end if
    
    
                    End Select 
            End While
    
    
       Catch ex as Exception 
          hs.WriteLog("1WireTemp Error","lin=[" & lin & "]    " & ex.Message) 
       Finally 
          if(not sr is Nothing) then sr.close() 
       End Try 
    End Sub
    Public Function getFarenheit(ByVal c as Double) as Double 
       dim d as Double 
       d = c*9/5+32 
       return d 
    End Function
    H - Create your Homeseer Temperature / Humidity sensor variables. Write down the device reference numbers and insert these in the script above.
    Create an event which runs Rob script every XX minutes. I run it every 5 minutes here.

    [ATTACH]62045[/ATTACH]

    This is what the combo temperature / humidity sensors look like.

    [ATTACH]62046[/ATTACH]

    3 - OPTIONAL: add Hobby Boards lightning sensor - adding this lightning sensor to 1-wire network in the attic. Note that Hobby Boards no longer exists and this device is no longer sold. Will update pictures of Digitemp / OWFS to include Lightning sensor dual counters. Device is mounted inside PVC tubing with a 6" copper wire. This device will be mounted in the attic.

    [ATTACH]62051[/ATTACH]

    4 - OPTIONAL: add owfs

    This is a jpg of the web access owhttpd which is hxxp://ipofserver:2121
    Testing OWFS 1-wire with DomoTicz.

    [ATTACH]62081[/ATTACH]

    A - apt-get update; apt-get install owfs

    B - this installs:
    owfs (filesystem)
    owftpd (ftp file server)
    owhttpd (web server)
    owserver (network protocol server)

    C - Default configuration file (/etc/owfs.conf) * edited for use with the above mentioned 9097 USB 1-wire device
    nano owfs
    Change the following lines to:

    Code:
    # Serial port: DS9097
    server: device = /dev/ttyUSB0
    #
    ######################### OWFS ##########################
    #
    mountpoint = /mnt/1wire
    allow_other
    #
    ####################### OWHTTPD #########################
    http: port = 2121
    ####################### OWFTPD ##########################
    ftp: port = 2120
    ####################### OWSERVER ########################
    server: port = localhost:4304
    D - In the configuration file the ports used are:

    owserver 4304 (the IANA assigned default)
    owhttpd 2121
    owftpd 2120

    E - Startup files are:

    owserver
    network server
    init file: /etc/init.d/owserver
    Control
    Code:
    sudo service owserver start
    sudo service owserver stop
    sudo service owserver restart
    sudo service owserver status
    owhttpd
    Web server
    init file: /etc/init.d/owhttpd
    Control
    Code:
    sudo service owhttpd start
    sudo service owhttpd stop
    sudo service owhttpd restart
    sudo service owhttpd status
    owftpd
    FTP server
    init file: /etc/init.d/owftpd
    Control
    Code:
    sudo service owftpd start
    sudo service owftpd stop
    sudo service owftpd restart
    sudo service owftpd status
    F - OWFS - Homeseer scripting - WeeWx weather
    Note that there is no current Homeseer script to read the values from OWFS. That said these values and application are used with a WeeWx weather software plugin.

    Starting OWFS and mount on startup:

    sudo /opt/owfs/bin/owfs -u --allow_other /mnt/1wire/

    Autostarting owfs

    A -
    cd /etc/init.d
    sudo nano start1wire.sh
    B -
    Code:
    #!/bin/bash
    
    ### BEGIN INIT INFO
    # Provides:          start1wire
    # Required-Start:    $local_fs $syslog
    # Required-Stop:     $local_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start OWFS at boot time
    # Description:       Start OWFS at boot time
    ### END INIT INFO
    
    # Starts OWFS
    /usr/bin/owfs -u --allow_other /mnt/1wire
    sudo chmod +x start1wire.sh

    sudo update-rc.d start1wire.sh defaults

    Check to make sure it is running:

    cd /mnt/1wire
    ls
    root@ICS-ZNet:/mnt/1wire# ls
    1D.37C907000000 26.993AF5000000 alarm simultaneous system
    26.3B3AF5000000 26.B3CA14000000 bus.0 statistics uncached
    26.8CC814000000 28.CFD8F4020000 settings structure


    Comments relating to 1-wire sensors using Digitemp and OWFS.

    OWFS seems a bit faster than Digitemp.

    5 - Optional: WeeWx Weather station parts which will be another post.

    A - Meteostick with Davis weather station connectivity - plus other wireless instruments - outdoor wireless ISS
    B - 1-wire multiple networks using OWFS (Temperatures, humidity, barometer, rain tipping bucket (analog and digital), et al
    C - AS3935 Lightning sensor
    D - NOAA satellite radio weather map download
    Last edited by Pete; July 6, 2017, 07:54 AM.
    - Pete

    Auto mator
    Homeseer 3 Pro - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb
    Homeseer Zee2 (Lite) - 3.0.0.548 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro
    HS4 Lite - Ubuntu 22.04 / Lenovo Tiny M900 / 32Gb Ram

    HS4 Pro - V4.1.18.1 - Ubuntu 22.04 / Lenova Tiny M900 / 32Gb Ram
    HSTouch on Intel tabletop tablets (Jogglers) - Asus AIO - Windows 11

    X10, UPB, Zigbee, ZWave and Wifi MQTT automation-Tasmota-Espurna. OmniPro 2, Russound zoned audio, Alexa, Cheaper RFID, W800 and Home Assistant
Working...
X