1
0
mirror of https://github.com/daniviga/bite.git synced 2024-12-23 08:41:24 +01:00

Send reasonable data with simulators

This commit is contained in:
Daniele Viganò 2020-06-04 18:06:37 +02:00
parent bb0e043bf9
commit b5e716ae5a
Signed by: dani
GPG Key ID: DB49AFC03C40EE02
2 changed files with 13 additions and 3 deletions

View File

@ -15,5 +15,6 @@ services:
IOT_HOST: "http://192.168.10.123:8000"
# IOT_SERIAL: "abcd1234"
# IOT_DELAY: 10
IOT_DEBUG: 1
networks:
- localnet

View File

@ -8,15 +8,20 @@ import datetime
import urllib3
from time import sleep
DEBUG = bool(os.environ.get('IOT_DEBUG', False))
http = urllib3.PoolManager()
def post_json(host, url, data):
encoded_data = json.dumps(data).encode('utf8')
json_data = json.dumps(data)
if DEBUG:
print(json_data)
encoded_data = json_data.encode('utf8')
while True:
try:
retry = False
r = http.request(
'POST',
host + url,
@ -45,7 +50,11 @@ def main():
'device': serial,
'clock': int(datetime.datetime.now().timestamp()),
'payload': {
'data': 'sample_data'
'id': 'device_http_simulator',
'light': random.randint(300, 500),
"temperature": {
"celsius": random.uniform(20, 28)
}
}
}