Results 1 to 3 of 3

Thread: Script to add support for RFXCOM WIND and RAIN sensors

  1. #1
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Default Script to add support for RFXCOM WIND and RAIN sensors

    Here is the code to add support for Rain and Wind devices I receive with my RfXCom :

    in packet.lua:

    Line 58:
    Code:
    RAIN                              = 0x55
    WIND                            = 0x56
    line 346 :
    Code:
    parsers[ RAIN ] = function ( data )
        
        local packet = parseHeader(data)
        
        if packet.type ~= RAIN then
            return nil, "not a RAIN message"
        end
        
        packet.subtype  = string.byte( data, 2 )
        packet.id = string.byte(data, 4) * 256 + string.byte(data, 5)
        packet.rate = (string.byte(data, 6) * 256 + string.byte(data, 7)) / 100
        packet.total = (string.byte(data, 8) * 65536 + string.byte(data, 9) * 256 + string.byte(data, 10)) / 10
        local batrssi = string.byte(data, 11)
        packet.rssi = bit.rshift( batrssi, 4)
        packet.battery = bit.band( batrssi, 0xf)
        return packet
    end
    
    
    parsers[ WIND ] = function ( data )
        
        local packet = parseHeader(data)
        
        if packet.type ~= WIND then
            return nil, "not a WIND message"
        end
        
        packet.subtype  = string.byte( data, 2 )
        packet.id = string.byte(data, 4) * 256 + string.byte(data, 5)
        packet.direction = string.byte(data, 6) * 256 + string.byte(data, 7)
        local unitKmh = true
    
    
        if packet.subtype == 6 then  --La Crosse Technology WS2300
            packet.gust = (string.byte(data, 10) * 256 + string.byte(data, 11)) / 10
        else
            packet.avgSpeed = (string.byte(data, 8) * 256 + string.byte(data, 9)) / 10
            packet.gust = (string.byte(data, 10) * 256 + string.byte(data, 11)) / 10
            -- Convert m/s to km/h or mph and keep an integer  
            if (unitKmh == true) then
                packet.avgSpeed = packet.avgSpeed * 3.6
            else
                packet.avgSpeed = packet.avgSpeed * 3.6 * 0.62137
            end 
        end
        -- Convert m/s to km/h or mph and keep an integer
        if (unitKmh == true) then
            packet.gust = packet.gust * 3.6
        else
            packet.gust = packet.gust * 3.6 * 0.62137
        end
    
    
        local batrssi = string.byte(data, 16)
        packet.rssi = bit.rshift( batrssi, 4)
        packet.battery = bit.band( batrssi, 0xf)
        return packet
        
    end

    in backend.lua
    Line 124
    Code:
            elseif param1.type == packet.WIND then
            
                local plds = {}
                table.insert( plds, param1.direction)
                table.insert( plds, param1.gust)            
                table.insert( plds, json.encode(param1))            
                gir.triggerEvent("WIND", 87, 0, plds)        
            
            elseif param1.type == packet.RAIN then
                local plds = {}
                table.insert( plds, param1.rate)
                table.insert( plds, param1.total)
                table.insert( plds, json.encode(param1))            
                gir.triggerEvent("RAIN", 87, 0, plds)
    I add the both files as attachment
    packet.lua
    backend.lua

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    Thanks! I'll merge your code for the next release.
    Ron
    No support through PM

  3. #3
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Default

    And if you have time to add the needed script for device manager integration with rfxcom. ... Thanks. ;-)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •