Skip to content
Snippets Groups Projects
Commit 265617e8 authored by Callum Inglis's avatar Callum Inglis
Browse files

Get sensor config from API and push to lora sensors

parent c6452b79
No related branches found
No related tags found
3 merge requests!12CO2 Sensor, Refactoring, CAD Files, Update Config from API,!7Update sensor config from api; CO2 Sensor; Refactor & Tidy-Up,!6Update sensor config from api; CO2 Sensor; Refactor & Tidy-Up
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
...@@ -93,7 +93,7 @@ class SensorResponse(object): ...@@ -93,7 +93,7 @@ class SensorResponse(object):
class GatewayMetadata(object): class GatewayMetadata(object):
def __init__(self): def __init__(self):
self.gatewayUID = getserial() self.gatewayUID = getserial()
self.apiKey = secrets.API_KEY self.apiKey = secrets.GATEWAY_API_KEY
class SensorMetadata(object): class SensorMetadata(object):
def __init__(self, uid, messageID, samplePeriod): def __init__(self, uid, messageID, samplePeriod):
...@@ -123,6 +123,16 @@ class Co2(object): ...@@ -123,6 +123,16 @@ class Co2(object):
def __init__(self, tmp): def __init__(self, tmp):
self.tmp = "Coming Soon!" self.tmp = "Coming Soon!"
class API():
def getSensorConfig(self, sensorUID):
headers = {'Content-Type': 'Application/json'}
response = requests.post(API_URL + '/api/' + secrets.API_KEY + '/sensor/getConfig/' + sensorUID, headers=headers)
if (response.status_code != 200):
return None
return json.loads(response.content)
class Reply(): class Reply():
ackStatus = False ackStatus = False
...@@ -130,8 +140,8 @@ class Reply(): ...@@ -130,8 +140,8 @@ class Reply():
self.gatewayUid = getserial() self.gatewayUid = getserial()
self.uid = remoteSensorID self.uid = remoteSensorID
self.replyMsgID = replyMsgID self.replyMsgID = replyMsgID
self.txAfterNReadings = None # We may update config of the sensor self.txAfterNReadings = None
self.pollingFrequency = None # We may update config of the sensor self.pollingFrequency = None
def setAckStatus(self, ackStatus): def setAckStatus(self, ackStatus):
self.ackStatus = ackStatus self.ackStatus = ackStatus
...@@ -270,10 +280,10 @@ def ackMsg(sensorResponse): ...@@ -270,10 +280,10 @@ def ackMsg(sensorResponse):
data = Reply(sensorResponse.sensorMetadata.uid, sensorResponse.sensorMetadata.messageID) data = Reply(sensorResponse.sensorMetadata.uid, sensorResponse.sensorMetadata.messageID)
data.setAckStatus(True) data.setAckStatus(True)
# TODO Fetch config for this sensor from the API here # Retrieve up-to-date sensor config from API & Transmit back to sensor
# TODO Include Reply config updates here updated_sensor_config = API().getSensorConfig(sensorResponse.sensorMetadata.uid)
data.updateConfigPollingFrequency(10000) data.updateConfigPollingFrequency(updated_sensor_config['txAfterNReadings'])
data.updateConfigTxAfterNReadings(6) data.updateConfigTxAfterNReadings(updated_sensor_config['pollingFrequency'])
if DEBUG > 1: if DEBUG > 1:
print(data.ToJson()) print(data.ToJson())
......
API_KEY = "<API KEY HERE>" GATEWAY_API_KEY = "<GATEWAY API KEY HERE>"
API_KEY = "<GENERIC API KEY HERE>"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment