forked from uva-hydroinformatics/FloodWarningSystems_20-21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_post.py
50 lines (37 loc) · 1.34 KB
/
http_post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
from http_config import *
device_ids = {
'pressure': 'dl-pr-26_5100',
'weather': 'dl-atm41_5245'
}
# URLs stored in config.py
downlink_urls = {
'pressure': pressure_downlink_url,
'weather': weather_downlink_url
}
# Command set period + save
sampling_rate = {
# Sampling rate in seconds, encoded in hex
# Command generated from https://htmlpreview.github.io/?https://github.com/decentlab/decentlab-decoders/blob/master/downlink-command-encoder.html
# 60: '0002003CF5A1',
# 300: '0002012CA9A1',
# 900: '0002038477A1'
# Sampling rate in seconds, encoded in base64 from hex
60: 'AAIAPPWh',
300: 'AAIBLKmh',
600: 'AAICWH6h',
900: 'AAIDhHeh'
}
# TODO: Change function definition to take in device IDs instead?
def update_sampling_period(downlink_url, seconds):
message = '{{"dev_id":"{}","payload_raw":"{}"}}'.format(device_ids['pressure'], sampling_rate[seconds])
downlink_command = requests.post(downlink_url, data=message)
print(downlink_command.text)
# 1 minute sampling period
# update_sampling_period(device_urls['pressure'], 60)
# 5 minute sampling period
# update_sampling_period(device_urls['pressure'], 300)
# 10 minute sampling period
update_sampling_period(downlink_urls['pressure'], 600)
# 15 minute sampling period
# update_sampling_period(device_urls['pressure'], 900)