added lacrosse
This commit is contained in:
parent
2716555b81
commit
29779fbc71
3 changed files with 112 additions and 0 deletions
|
@ -5,3 +5,5 @@ interfacing the RFM69
|
|||
controlling remote control sockets
|
||||
usage example:
|
||||
sudo intertechno.py 0000F0000FFF
|
||||
##lacrosse.py
|
||||
receiving temperature sensors
|
||||
|
|
32
lacrosse.py
Normal file
32
lacrosse.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python2.7
|
||||
|
||||
from rfm69 import Rfm69
|
||||
import rfm69
|
||||
import sensors
|
||||
from sensors import rawsensor
|
||||
import sys
|
||||
import time
|
||||
|
||||
rfm = Rfm69()
|
||||
|
||||
rfm.SetParams(
|
||||
Freq = 868.300, #MHz center frequency
|
||||
Datarate = 9.579, #17.241, #kbit/s baudrate
|
||||
ModulationType = rfm69.FSK, #modulation
|
||||
SyncPattern = [0x2d, 0xd4], #syncword
|
||||
Bandwidth = 200, #kHz bandwidth
|
||||
LnaGain = 0x88
|
||||
)
|
||||
|
||||
print hex(rfm.ReadReg(0x07))
|
||||
print hex(rfm.ReadReg(0x08))
|
||||
print hex(rfm.ReadReg(0x09))
|
||||
|
||||
|
||||
data = []
|
||||
|
||||
while 1:
|
||||
data = rfm.ReceivePacket(7)
|
||||
obj = rawsensor.CreateSensor(data)
|
||||
print(str(obj))
|
||||
|
78
sensors.py
Normal file
78
sensors.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
def crc8(buf):
|
||||
crc = 0
|
||||
for j in range(5):
|
||||
crc = crc ^ buf[j]
|
||||
for i in range(8):
|
||||
if (crc & 0x80 == 0x80):
|
||||
crc = (crc << 1) ^ 0x31
|
||||
else:
|
||||
crc <<= 1
|
||||
return crc & 0xFF
|
||||
|
||||
def csum(data):
|
||||
s = 0
|
||||
for i in range(12):
|
||||
s += data[i]
|
||||
return s & 0xFF
|
||||
|
||||
class rawsensor(object):
|
||||
def __init__(self, data):
|
||||
self._data = {}
|
||||
self.__raw = data
|
||||
|
||||
def __str__(self):
|
||||
res = 'raw';
|
||||
for data in self.__raw:
|
||||
res = res + ' ' + hex(data)[2:];
|
||||
return res;
|
||||
|
||||
def GetData(self):
|
||||
return self._data
|
||||
|
||||
@staticmethod
|
||||
def CreateSensor(data):
|
||||
obj = lacross.Create(data)
|
||||
if (obj):
|
||||
return obj
|
||||
|
||||
obj = emt7110.Create(data)
|
||||
if (obj):
|
||||
return obj
|
||||
|
||||
return rawsensor(data)
|
||||
|
||||
class lacross(rawsensor):
|
||||
def __init__(self, data):
|
||||
rawsensor.__init__(self, data)
|
||||
self._data['ID'] = hex((data[0] << 4 | data[1] >> 4) & 0xFC)[2:]
|
||||
self._data['T'] = (10 * ((data[1] & 0xF) - 4) + (data[2] >> 4) + (data[2] & 0xF) / 10.0, 'C')
|
||||
rh = data[3] & 0x7F
|
||||
if rh <= 100:
|
||||
self._data['RH'] = (rh, '%')
|
||||
|
||||
def __str__(self):
|
||||
res = 'La crosse ' + str(self._data) # + ' ' + rawsensor.__str__(self);
|
||||
return res;
|
||||
|
||||
@staticmethod
|
||||
def Create(data):
|
||||
if len(data) >= 5 and len(data) <= 8 and crc8(data) == 0:
|
||||
return lacross(data)
|
||||
|
||||
class emt7110(rawsensor):
|
||||
def __init__(self, data):
|
||||
rawsensor.__init__(self, data)
|
||||
id = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]
|
||||
self._data['ID'] = hex(id)[2:]
|
||||
self._data['P'] = (((data[4] << 8 | data[5]) & 0x3FFF) / 2.0, 'W')
|
||||
self._data['U'] = (data[8] / 2.0 + 128, 'V')
|
||||
self._data['I'] = (data[6] << 8 | data[7], 'mA')
|
||||
self._data['W'] = (((data[9] << 8 | data[10]) & 0x3FFF) / 100, 'kWh')
|
||||
|
||||
def __str__(self):
|
||||
return 'emt7110 ' + str(self._data)
|
||||
|
||||
@staticmethod
|
||||
def Create(data):
|
||||
if len(data) >= 12 and len(data) <= 20 and csum(data) == 0:
|
||||
return emt7110(data)
|
Loading…
Reference in a new issue