add radar support

This commit is contained in:
Wolfgang Hottgenroth 2023-02-23 21:53:04 +01:00
parent 5c361ba524
commit 3b9d517ad5
Signed by: wn
GPG Key ID: 836E9E1192A6B132
2 changed files with 58 additions and 0 deletions

View File

@ -1,3 +1,5 @@
Ultraschall - LDDS75
http://wiki.dragino.com/xwiki/bin/view/Main/User%20Manual%20for%20LoRaWAN%20End%20Nodes/LDDS75%20-%20LoRaWAN%20Distance%20Detection%20Sensor%20User%20Manual/
@ -22,3 +24,32 @@ status = struct.unpack('?', frame[7:8])[0]
print(f"{battery=}, {distance=}, {status=}")
payload = 'DRgAAAAAAAE='
Radar - LMDS200
http://wiki.dragino.com/xwiki/bin/view/Main/User%20Manual%20for%20LoRaWAN%20End%20Nodes/LMDS200%20-%20LoRaWAN%20Microwave%20Radar%20Distance%20%20Sensor%20User%20Manual/
Value, Size (bytes), FPORT = 2
Battery (mV), 2
Distance 1 (cm), 2
Distance 2 (cm), 2
Status, 1
import base64
import struct
payload = 'DN4AqQD8AA=='
frame = base64.b64decode(payload)
battery = struct.unpack('>H', frame[0:2])[0]
distance1 = struct.unpack('>H', frame[2:4])[0]
distance2 = struct.unpack('>H', frame[4:6])[0]
print(f"{battery=}, {distance1=}, {distance2=}")

View File

@ -19,6 +19,8 @@ class SensorTypeNotFoundException (Exception):
def __init__(self, sensorType):
self.sensorType = sensorType
class JustIgnoreMessage (Exception): pass
class DbOp(object):
def __init__(self, config):
self.conn = None
@ -95,6 +97,7 @@ def mqttOnMessageCallback(client, userdata, message):
application = dbh.getApplication(device_id)
frame = base64.b64decode(parse_payload['uplink_message']['frm_payload'])
f_port = parse_payload['uplink_message']['f_port']
measurement = {}
match application['sensor_type']:
@ -117,11 +120,35 @@ def mqttOnMessageCallback(client, userdata, message):
'status': statusText,
'battery': battery / 1000
}
case 'LMDS200':
if f_port != 2:
raise JustIgnore()
battery = struct.unpack('>H', frame[0:2])[0]
distance1 = struct.unpack('>H', frame[2:4])[0]
distance2 = struct.unpack('>H', frame[4:6])[0]
status = struct.unpack('?', frame[7:8])[0]
logger.debug(f"{frame=}, {battery=}, {distance1=}, {distance2=}")
statusText = 'Ok'
if distance1 == 1:
statusText = 'No sensor'
elif distance1 == 2:
statusText = 'Out of range'
measurement = {
'application_name': application['label'],
'raw_level': distance1,
'level': application['ground_level'] - distance1,
'status': statusText,
'battery': battery / 1000
}
case _:
raise SensorTypeNotFoundException(application['sensor_type'])
logger.debug(f"{measurement=}")
dbh.storeMeasurement(measurement)
except JustIgnore:
pass
except SensorTypeNotFoundException as e:
logger.error(f"application has unknown sensor type {e.sensorType}")
except ApplicationNotFoundException as e: