Commit c47c3f7c authored by Federico Sismondi's avatar Federico Sismondi
Browse files

Update() push DCA moisture data using the correct range in cb (~KPa)

parent 29fdc01d
......@@ -36,6 +36,54 @@ def healthcheck():
return 'This service is up and running!'
def _log_level_of_moisture(cb, sensor):
"""
0-10 Centibars = Saturated soil
10-30 Centibars = Soil is adequately wet (except coarse sands, which are drying)
30-60 Centibars = Usual range for irrigation (most soils)
60-100 Centibars = Usual range for irrigation in heavy clay
100-200 Centibars = Soil is becoming dangerously dry- proceed with caution!
:param cb:
:param sensor:
:return:
"""
if cb < 10:
app.logger.warning("{} indicates soil is saturated wet ({} cb)!".format(sensor,cb))
elif cb < 30:
app.logger.info("{} indicates soil is adequately wet :] ({} cb)".format(sensor,cb))
elif cb < 60:
app.logger.info("{} indicates soil in usual range of irrigation for moist soils :) ({} cb)".format(sensor,cb))
elif cb < 100:
app.logger.warning("{} indicates soil needs irrigation ({} cb)!".format(sensor,cb))
elif cb < 200:
app.logger.warning("{} indicates soil is dangerously dry !!! ({} cb)!".format(sensor,cb))
else:
app.logger.error("Measurement not it expected range {}".format(cb))
def _conv_micro_volts_to_moiture_cb(micro_volts):
"""
Lora Bridge device has to channels (A and B). Only the channel A is connected. To read correctly the value from the channel A, you should take the byte 3 to 5.
Then, you should decoded from Hex to Decimal. IMPORTANT: The value is expressed in µV. (1V = 1.000.000µV)
Sensor Voltage range is from 0V to 3V. This voltage range is linearly dependent to the real value of the sensor, which is expressed in cb (kPa):
- 0V = Plants are wet - do not need watering (0cb)
- 3V = Plant are dry - need watering (239cb)
:param micro_volts:
:return: pressure (in cb ~ KPa)
"""
assert type(micro_volts) is int
if micro_volts == 0:
return 0
return (micro_volts * 239) / 3000000
def _get_reading(message_data):
"""
>>> base64.standard_b64decode("QmABACcnAQAAAA==").hex()
......@@ -48,7 +96,7 @@ def _get_reading(message_data):
reading_hex = base64.standard_b64decode(message_data).hex()
if reading_hex[0:2] == '42': # it's a dataFrame
return int(reading_hex[6:12], 16) # ToDo may need some calculations here
return _conv_micro_volts_to_moiture_cb(int(reading_hex[6:12], 16)) # ToDo may need some calculations here
else:
app.logger.warning("Not a sensor reading (expected 0x42) {}".format(reading_hex))
......@@ -63,8 +111,9 @@ def _forward_to_message_broker():
timestamp = request.json['timestamp']
dev_eui = request.json['deveui']
entity_id, street_address = mapping_deveui_to_fiware_instance_meta[dev_eui]
app.logger.info("Pushing IoT reading ({}) to {}".format(sensor_reading, entity_id))
_log_level_of_moisture(sensor_reading,entity_id)
app.logger.info("Pushing IoT reading ({}) to {}".format(sensor_reading, entity_id))
url = "{}/v2/entities/{}/attrs?options=keyValues".format(URL_BASE, entity_id)
payload = {
'boxId': entity_id.split('-')[-1],
......
......@@ -49,3 +49,4 @@ for pilot in entities_map.keys():
entities_map[pilot].append(entity['id'])
pprint(entities_map)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment