Browse Source

update to firmware 1.6

master
Tobias Brunner 1 year ago
parent
commit
4b0fa0487a
  1. 34
      lgt92.py
  2. 88
      ttnscripts/lgt92.js

34
lgt92.py

@ -20,7 +20,7 @@ DST_INFLUX_USER = os.getenv("DST_INFLUX_USER")
DST_INFLUX_PASS = os.getenv("DST_INFLUX_PASS")
DST_INFLUX_DB = os.getenv("DST_INFLUX_DB")
HC_PING_URL = os.getenv("HC_PING_URL")
VERSION = "V1.1"
VERSION = "v2.0"
OT_TOPIC="owntracks/tobru/dragino"
OT_TID="dragino"
@ -61,19 +61,19 @@ def on_message_ttn(client, userdata, msg):
logging.info("received via gw %s", gtw_id)
# max is 4 volts, 3 volts is considered empty
batpercent = round((data["payload_fields"]["batV"] - 3) * 100)
batpercent = round((data["payload_fields"]["BatV"] - 3) * 100)
if data["payload_fields"]["alarm"]:
if data["payload_fields"]["ALARM_status"]:
print("ALARM button pressed")
got_fix = False
if "latitude" in data["payload_fields"]:
if "Latitude" in data["payload_fields"]:
got_fix = True
# transform received data into OwnTracks format
ot_data = json.dumps({
"_type": "location",
"lat": data["payload_fields"]["latitude"],
"lon": data["payload_fields"]["longitude"],
"lat": data["payload_fields"]["Latitude"],
"lon": data["payload_fields"]["Longitude"],
"batt": batpercent,
"t": "p",
"tid": OT_TID,
@ -85,11 +85,15 @@ def on_message_ttn(client, userdata, msg):
logging.info("publishing data to owntracks via mqtt %s", OT_TOPIC)
client_ot.publish(OT_TOPIC, payload=ot_data, retain=True, qos=1)
else:
logging.info("no GPS data / latitude present")
logging.info("no GPS data (latitude) present")
# set GPS data to 0 for InfluxDB
data["payload_fields"]["latitude"] = 0.0
data["payload_fields"]["longitude"] = 0.0
data["payload_fields"]["Latitude"] = 0.0
data["payload_fields"]["Longitude"] = 0.0
logging.info("Motion detection: %s", data["payload_fields"]["MD"])
logging.info("LED status for position: %s", data["payload_fields"]["LON"])
logging.info("Firmware version: %s", data["payload_fields"]["FW"])
# write to influxdb
logging.info("writing data to influxdb")
influxdb.write_points(
@ -99,12 +103,12 @@ def on_message_ttn(client, userdata, msg):
"device": "lgt92",
},
"fields": {
"bat": float(data["payload_fields"]["batV"]),
"pitch": float(data["payload_fields"]["pitch"]),
"roll": float(data["payload_fields"]["roll"]),
"lat": data["payload_fields"]["latitude"],
"lon": data["payload_fields"]["longitude"],
"alarm": int(data["payload_fields"]["alarm"]),
"bat": float(data["payload_fields"]["BatV"]),
"pitch": float(data["payload_fields"]["Pitch"]),
"roll": float(data["payload_fields"]["Roll"]),
"lat": data["payload_fields"]["Latitude"],
"lon": data["payload_fields"]["Longitude"],
"alarm": int(data["payload_fields"]["ALARM_status"]),
"counter": data["counter"],
"airtime": data["metadata"]["airtime"],
"rssi": data["metadata"]["gateways"][0]["rssi"],

88
ttnscripts/lgt92.js

@ -1,45 +1,47 @@
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var alarm=(bytes[6] & 0x40)?true:false; //Alarm status
value=((bytes[6] & 0x3f) <<8) | bytes[7];
var batV=value/1000; //Battery,units:Volts
value=bytes[8]<<8 | bytes[9];
if(bytes[8] & 0x80)
{
value |=0xFFFF0000;
}
var roll=value/100; //roll,units: °
value=bytes[10]<<8 | bytes[11];
if(bytes[10] & 0x80)
{
value |=0xFFFF0000;
}
var pitch=value/100; //pitch,units: °
var json={
roll:roll,
pitch:pitch,
batV:batV,
alarm:alarm
return {
// GPS coordinates; signed 32 bits integer, MSB; unit: °
// When power is low (<2.84v), GPS won’t be able to get location
// info and GPS feature will be disabled and the location field
// will be filled with 0x0FFFFFFF, 0x0FFFFFFF.
Latitude:
(bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]) / 1000000,
Longitude:
(bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]) / 1000000,
// Alarm status: boolean
ALARM_status: (bytes[8] & 0x40) > 0,
// Battery; 14 bits; unit: V
BatV: ((bytes[8] & 0x3f)<<8 | bytes[9]) / 1000,
// Motion detection mode; 2 bits
MD: {
"0": "Disable",
"1": "Move",
"2": "Collide",
"3": "Custom"
}[bytes[10]>>6],
// LED status for position, uplink and downlink; 1 bit
LON: (bytes[10] & 0x20) ? "ON" : "OFF",
// Firmware version; 5 bits
FW:150+(bytes[10] & 0x1f),
// Roll; signed 16 bits integer, MSB; unit: °
// Sign-extend to 32 bits to support negative values: shift 16 bytes
// too far to the left, followed by sign-propagating right shift
Roll: (bytes[11]<<24>>16 | bytes[12]) / 100,
// Pitch: signed 16 bits integer, MSB, unit: °
Pitch: (bytes[13]<<24>>16 | bytes[14]) / 100,
};
var value=bytes[0]<<16 | bytes[1]<<8 | bytes[2];
if(bytes[0] & 0x80)
{
value |=0xFFFFFF000000;
}
var value2=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
if(bytes[3] & 0x80)
{
value2 |=0xFFFFFF000000;
}
if (value == 0x0FFFFF && value2 == 0x0FFFFF)
{
//gps disabled (low battery)
} else if (value === 0 && value2 === 0) {
//gps no position yet
} else {
json.latitude=value/10000; //gps latitude,units: °
json.longitude=value2/10000; //gps longitude,units: °
}
return json;
}
}
Loading…
Cancel
Save