mirror of
https://github.com/daniviga/bite.git
synced 2024-11-22 21:16:12 +01:00
Send reasonable data with simulators
This commit is contained in:
parent
bb0e043bf9
commit
b5e716ae5a
|
@ -15,5 +15,6 @@ services:
|
|||
IOT_HOST: "http://192.168.10.123:8000"
|
||||
# IOT_SERIAL: "abcd1234"
|
||||
# IOT_DELAY: 10
|
||||
IOT_DEBUG: 1
|
||||
networks:
|
||||
- localnet
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user