|
|
@ -19,34 +19,40 @@ the same directory as this: /services/. |
|
|
|
device_check_token = "QWERTYuiopasdfghjklzxcvbnm_1234567890" |
|
|
|
device_check_token = "QWERTYuiopasdfghjklzxcvbnm_1234567890" |
|
|
|
|
|
|
|
|
|
|
|
def add_latest_reading(meter, info): |
|
|
|
def add_latest_reading(meter, info): |
|
|
|
if info["token"] == device_check_token: |
|
|
|
try: |
|
|
|
reading = {"reading":info["reading"], "time":info["time"]} |
|
|
|
if info["token"] == device_check_token: |
|
|
|
if meter == 1: |
|
|
|
reading = {"reading":info["reading"], "time":info["time"]} |
|
|
|
return add_reading_to_meter1(reading) |
|
|
|
if meter == 1: |
|
|
|
elif meter == 2: |
|
|
|
return add_reading_to_meter1(reading) |
|
|
|
return add_reading_to_meter2(reading) |
|
|
|
elif meter == 2: |
|
|
|
elif meter == 3: |
|
|
|
return add_reading_to_meter2(reading) |
|
|
|
return add_reading_to_meter3(reading) |
|
|
|
elif meter == 3: |
|
|
|
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400) |
|
|
|
return add_reading_to_meter3(reading) |
|
|
|
return make_response("Invalid token.", 400) |
|
|
|
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400) |
|
|
|
|
|
|
|
return make_response("Invalid token.", 400) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
return make_response("The data you sent was invalid or incorrectly formatted.", 400) |
|
|
|
|
|
|
|
|
|
|
|
def log_status_change(device, info): |
|
|
|
def log_status_change(device, info): |
|
|
|
if info["token"] == device_check_token: |
|
|
|
try: |
|
|
|
status = {"time":info["time"], "status":info["status"]} |
|
|
|
if info["token"] == device_check_token: |
|
|
|
if device == 1: |
|
|
|
status = {"time":info["time"], "status":info["status"]} |
|
|
|
return add_status_change_to_device1(status) |
|
|
|
if device == 1: |
|
|
|
elif device == 2: |
|
|
|
return add_status_change_to_device1(status) |
|
|
|
return add_status_change_to_device2(status) |
|
|
|
elif device == 2: |
|
|
|
elif device == 3: |
|
|
|
return add_status_change_to_device2(status) |
|
|
|
return add_status_change_to_device3(status) |
|
|
|
elif device == 3: |
|
|
|
elif device == 4: |
|
|
|
return add_status_change_to_device3(status) |
|
|
|
return add_status_change_to_device4(status) |
|
|
|
elif device == 4: |
|
|
|
elif device == 5: |
|
|
|
return add_status_change_to_device4(status) |
|
|
|
return add_status_change_to_device5(status) |
|
|
|
elif device == 5: |
|
|
|
elif device == 6: |
|
|
|
return add_status_change_to_device5(status) |
|
|
|
return add_status_change_to_device6(status) |
|
|
|
elif device == 6: |
|
|
|
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400) |
|
|
|
return add_status_change_to_device6(status) |
|
|
|
return make_response("Invalid token.", 400) |
|
|
|
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400) |
|
|
|
|
|
|
|
return make_response("Invalid token.", 400) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
return make_response("The data you sent was invalid or incorrectly formatted.", 400) |
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
|
''' |
|
|
|
Nitty-Gritty Functions |
|
|
|
Nitty-Gritty Functions |
|
|
|