Skip to content
Snippets Groups Projects

Update sensor config from api; CO2 Sensor; Refactor & Tidy-Up

Merged Callum Inglis requested to merge update-sensor-config-from-api into DEV
1 file
+ 26
5
Compare changes
  • Side-by-side
  • Inline
@@ -93,7 +93,7 @@ class SensorResponse(object):
class GatewayMetadata(object):
def __init__(self):
self.gatewayUID = getserial()
self.apiKey = secrets.API_KEY
self.apiKey = secrets.GATEWAY_API_KEY
class SensorMetadata(object):
def __init__(self, uid, messageID, samplePeriod):
@@ -123,6 +123,16 @@ class Co2(object):
def __init__(self, tmp):
self.tmp = "Coming Soon!"
class API():
def getSensorConfig(self, sensorUID):
headers = {'Content-Type': 'Application/json'}
response = requests.post(API_URL + '/' + secrets.API_KEY + '/sensor/getConfig/' + sensorUID, headers=headers)
if (response.status_code != 200):
return None
return json.loads(response.content)
class Reply():
ackStatus = False
@@ -130,8 +140,8 @@ class Reply():
self.gatewayUid = getserial()
self.uid = remoteSensorID
self.replyMsgID = replyMsgID
self.txAfterNReadings = None # We may update config of the sensor
self.pollingFrequency = None # We may update config of the sensor
self.txAfterNReadings = None
self.pollingFrequency = None
def setAckStatus(self, ackStatus):
self.ackStatus = ackStatus
@@ -270,10 +280,11 @@ def ackMsg(sensorResponse):
data = Reply(sensorResponse.sensorMetadata.uid, sensorResponse.sensorMetadata.messageID)
data.setAckStatus(True)
# TODO Fetch config for this sensor from the API here
# TODO Include Reply config updates here
data.updateConfigPollingFrequency(10000)
data.updateConfigTxAfterNReadings(6)
# Retrieve up-to-date sensor config from API & Transmit back to sensor
updated_sensor_config = API().getSensorConfig(sensorResponse.sensorMetadata.uid)
if updated_sensor_config is not None:
data.updateConfigPollingFrequency(updated_sensor_config['txAfterNReadings'])
data.updateConfigTxAfterNReadings(updated_sensor_config['pollingFrequency'])
if DEBUG > 1:
print(data.ToJson())
Loading