Skip to content

Commit

Permalink
Added hap sensor readout
Browse files Browse the repository at this point in the history
  • Loading branch information
pvgennip committed May 11, 2017
1 parent 582b250 commit e0645a2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
25 changes: 21 additions & 4 deletions laradock/mqttwarn/services/influxdb_akvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,27 @@ def split_ssu_wap_for_influx(item):
# 0 1 2 3 4 5
# HAP formatting: Timestamp, CO, CO2, P1, P2, BatteryLevel
def split_hap_sum_for_influx(item, sensor_id):
out = item.payload.strip().split(",")
tpc = "topic=" + item.topic.replace('/'+sensor_id, '').replace('/', '_')
tst = int(out[0]) if int(out[0]) > 0 else int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum co=%s,co2=%s,p1=%s,p2=%s,bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), float(out[3]), float(out[4]), float(out[5]), tst)
pl = item.payload
tpc= "topic=" + item.topic.replace('/'+sensor_id, '').replace('/', '_')
if len(pl) == 26: # HAP payload
out = []
out.append(int(pl[0:8], 16)) #ts
out.append(int(pl[8:12], 16))
out.append(int(pl[12:16], 16))
out.append(int(pl[16:20], 16))
out.append(int(pl[20:24], 16))
out.append(int(pl[24:26], 16))
tst = int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum co=%s,co2=%s,p1=%s,p2=%s,hap_bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), float(out[3]), float(out[4]), (float(out[5])+200)/100, tst)
elif len(pl) == 16: # HAP payload
out = []
out.append(int(pl[0:8], 16)) # ts
out.append(int(pl[8:10], 16)) # Dur
out.append(int(pl[10:14], 16)) # T max
out.append(int(pl[14:16], 16)) # Bat Level
tst = int(out[0]) if int(out[0]) > 0 and int(out[0]) < int(time.time()) else int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum duration=%s,t_max=%s,sum_bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), (float(out[3])+200)/100, tst)

return pyl


Expand Down
51 changes: 36 additions & 15 deletions laradock/mqttwarn/services/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,50 @@ def split_ssu_wap_for_influx(tpc, pl):
return pyl


def split_hap_sum_for_influx(tpc, pl):
sensor_id = 1
out = pl.split(",")
tpc = "topic=" + tpc.replace('/', '_')
tst = int(out[0]) if int(out[0]) > 0 else int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum co=%s,co2=%s,p1=%s,p2=%s,bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), float(out[3]), float(out[4]), float(out[5]), tst)
return pyl
# HAP Message: 1494335973, 98, 0, 65140, 52924, 168
# 0 1 2 3 4 5
# HAP formatting: Timestamp, CO, CO2, P1, P2, BatteryLevel
def split_hap_sum_for_influx(pl, sensor_id, tp):


tp = "ssu_wap"
pl = "6d70a5d273205cae,203,1024,1017,199,3677"
tag = ""
tpc= "topic=" + tp.replace('/'+sensor_id, '').replace('/', '_')
print 'topic: ' + tpc
print 'payload length: ' + str(len(pl))
if len(pl) == 26: # HAP payload
out = []
out.append(int(pl[0:8], 16)) #ts
out.append(int(pl[8:12], 16))
out.append(int(pl[12:16], 16))
out.append(int(pl[16:20], 16))
out.append(int(pl[20:24], 16))
out.append(int(pl[24:26], 16))
tst = int(out[0]) if int(out[0]) > 0 else int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum co=%s,co2=%s,p1=%s,p2=%s,hap_bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), float(out[3]), float(out[4]), (float(out[5])+200)/100, tst)
elif len(pl) == 16: # HAP payload
out = []
out.append(int(pl[0:8], 16)) # ts
out.append(int(pl[8:10], 16)) # Dur
out.append(int(pl[10:14], 16)) # T max
out.append(int(pl[14:16], 16)) # Bat Level
tst = int(out[0]) if int(out[0]) > 0 else int(time.time())
pyl = "%s,sensor_id=%s,type=hap_sum duration=%s,t_max=%s,sum_bat_v=%s %s" % (tpc, sensor_id, float(out[1]), float(out[2]), (float(out[3])+200)/100, tst)

# tp = "hap_sum"
# pl = "1494335973, 98, 0, 65140, 52924, 168"
return pyl

# tp = "ssu_wap"
# pl = "6d70a5d273205cae,203,1024,1017,199,3677"
# tag = ""

tp = "ITAY/HAP/0000E0DB40604500"
pl = "81ff0b6e0000000000000000e2"
tag = ""
tpc = tp.split('/')

if tp == "ssu_wap":
tag = ""
payload = split_ssu_wap_for_influx(tp, pl)
elif tp == "hap_sum":
elif tpc[0] == "ITAY" and tpc[1] == "HAP":
tag = ""
payload = split_hap_sum_for_influx(tp, pl)
payload = split_hap_sum_for_influx(pl, tpc[2], tp)
else:
payload = " value="+item.payload

Expand Down
11 changes: 8 additions & 3 deletions portal/app/Http/Controllers/SensorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function allowedSensors($request, $id=null)

protected function convertSensorTypeToInfluxSeries($type)
{
return substr(strtolower($type), 0, 3);
return substr(strtolower($type), 0, 3); // convert hap_sum -> hap, ssu_wap -> ssu
}


Expand Down Expand Up @@ -63,12 +63,17 @@ protected function addLastSensorData($sensors)
{
//die(print_r($sensordata));
$sensors[$id]->date = $sensordata[0]['time'];
if ($sensor->type == "ssu_wap")
if ($sensor->type == "ssu_wap" && isset($sensordata[0]['pressure_wap']) && isset($sensordata[0]['pressure_ssu']))
{
// Depth = Depth(m)=(WAP pressure- BME280 pressure)/98.1
$sensors[$id]->value = round( (($sensordata[0]['pressure_wap'] - $sensordata[0]['pressure_ssu'])/98.1), 2)." m";
}
else
else if ($sensor->type == "hap_sum" && isset($sensordata[0]['p1']))
{
// Depth = Depth(m)=(WAP pressure- BME280 pressure)/98.1
$sensors[$id]->value = $sensordata[0]['p1']." pcs/ft³";
}
else if (isset($sensordata[0]['value']))
{
$sensors[$id]->value = $sensordata[0]['value'];
}
Expand Down

0 comments on commit e0645a2

Please sign in to comment.