User Tools

Site Tools


hydrus-flowmeter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
hydrus-flowmeter [2023/08/17 10:35] – created emozolyakhydrus-flowmeter [2023/08/17 11:42] emozolyak
Line 1: Line 1:
-====== Connecting to HYDRUS by DIEHL flowmeter  ======+{{ :custom_protocols:mbus:hydrus-meter-for-mbus.jpg?direct&150|}} 
 +====== Connecting to DIEHL HYDRUS flowmeter ====== 
 + 
 +<WRAP center round info 80%> 
 +Highly accurate, lead-free brass ultrasonic smart water meter for residential, commercial and industrial installations. It has Mbus onboard. 
 +</WRAP> 
 + 
 + 
 +---- 
  
 <code lua> <code lua>
Line 121: Line 130:
     flow   = {pattern = {0xB, 0x3C}, length = 3, func = table.bcd},     flow   = {pattern = {0xB, 0x3C}, length = 3, func = table.bcd},
     tint   = {pattern = {0xA, 0x5A}, length = 2, func = table.bcd},     tint   = {pattern = {0xA, 0x5A}, length = 2, func = table.bcd},
-    text   = {pattern = {0xA, 0x66}, length = 2, func = table.bcd}+    text   = {pattern = {0xA, 0x66}, length = 2, func = table.bcd}
 +    err    {pattern = {0x4, 0xFD, 0x17} 
 +              , length = 4 
 +              , func = function(d) 
 +                          return tonumber(table.hexView(d), HEX_NUMBERING)  
 +                        end},  -- int32 convertion
 } }
  
Line 129: Line 143:
    addDevice{name = "TI",     shift = 0, base = 10, xtraFields = {'temp. internal' }       addDevice{name = "TI",     shift = 0, base = 10, xtraFields = {'temp. internal' }   
    addDevice{name = "TE",     shift = 0, base = 10, xtraFields = {'temp. external' }       addDevice{name = "TE",     shift = 0, base = 10, xtraFields = {'temp. external' }   
 +   addDevice{name = "ERR",     shift = 0, base = 10, xtraFields = {'error flags' }   
 end  end 
  
Line 135: Line 150:
     if (not lastReadTimeStamp or (now - lastReadTimeStamp) >= POLL_DELAY ) then      if (not lastReadTimeStamp or (now - lastReadTimeStamp) >= POLL_DELAY ) then 
    
-        PROBE_PACKET[PROBE_PACKET_CRC_POS] = getCRC(PROBE_PACKET, REQ_UD2_POS, PROBE_PACKET_PAYLOAD_LEN)+        PROBE_PACKET[PROBE_PACKET_CRC_POS] = getCRC(PROBE_PACKET 
 +                                                    , REQ_UD2_POS 
 +                                                    , PROBE_PACKET_PAYLOAD_LEN)
    
         if (not sendBytes(PROBE_PACKET) ) then         if (not sendBytes(PROBE_PACKET) ) then
Line 143: Line 160:
    
         local meterDataFrame = readUntil(ETX)          local meterDataFrame = readUntil(ETX) 
-  
         if (#meterDataFrame > 10) then         if (#meterDataFrame > 10) then
             -- parsing              -- parsing 
             for param, struc in pairs(dataHandlers) do              for param, struc in pairs(dataHandlers) do 
-                 
                 local foundPos = table.findPattern(meterDataFrame, struc.pattern)                 local foundPos = table.findPattern(meterDataFrame, struc.pattern)
                 if foundPos then                 if foundPos then
-                                                                                    DBG('found data at: ', foundPos) +                    DBG('found data for ' .. param ..' at: ', foundPos)
-                    lastReadTimeStamp = now +
                     local foundBytes = table.sub(meterDataFrame, foundPos                     local foundBytes = table.sub(meterDataFrame, foundPos
-                                                               , foundPos + struc.length - 1) DBG('found bytes: ', foundBytes) +                                                               , foundPos + struc.length - 1)  
-                    foundBytes = table.reverse(foundBytes)   DBG("After reverse: ", foundBytes) +                    DBG('found bytes: ', foundBytes) 
-                    data[param] = struc.func(foundBytes)     DBG("Data - param: ", data[param])+                    foundBytes = table.reverse(foundBytes)    
 +                    DBG("After reverse: ", foundBytes) 
 +                    local actualData = struc.func(foundBytes)      
 +                    DBG("actualData: ", actualData) 
 +                    data[param] = actualData 
 +                     
 +                    lastReadTimeStamp = now 
                 else                  else 
                     ERROR("failed to find data !")                     ERROR("failed to find data !")
Line 167: Line 187:
     end      end 
          
-    if (device.name == 'V') then return data["volume"end  +    if (device.name == 'V'  then return data.volume end  
-    if (device.name == 'Q') then return data["flow"end  +    if (device.name == 'Q'  then return data.flow   end  
-    if (device.name == 'TI') then return data.tint end  +    if (device.name == 'TI' then return data.tint   end  
-    if (device.name == 'TE') then return data.text end +    if (device.name == 'TE' then return data.text   end  
 +    if (device.name == 'ERR') then return data.err    end 
    
 end  end 
Line 202: Line 223:
     return sum     return sum
 end  end 
- 
  
  
 </code> </code>
  
hydrus-flowmeter.txt · Last modified: 2024/02/20 14:42 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki