mirror of
https://github.com/daniviga/bite.git
synced 2025-02-17 05:59:14 +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_HOST: "http://192.168.10.123:8000"
|
||||||
# IOT_SERIAL: "abcd1234"
|
# IOT_SERIAL: "abcd1234"
|
||||||
# IOT_DELAY: 10
|
# IOT_DELAY: 10
|
||||||
|
IOT_DEBUG: 1
|
||||||
networks:
|
networks:
|
||||||
- localnet
|
- localnet
|
||||||
|
@ -8,15 +8,20 @@ import datetime
|
|||||||
import urllib3
|
import urllib3
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
DEBUG = bool(os.environ.get('IOT_DEBUG', False))
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
|
|
||||||
|
|
||||||
def post_json(host, url, data):
|
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:
|
while True:
|
||||||
try:
|
try:
|
||||||
retry = False
|
|
||||||
r = http.request(
|
r = http.request(
|
||||||
'POST',
|
'POST',
|
||||||
host + url,
|
host + url,
|
||||||
@ -45,7 +50,11 @@ def main():
|
|||||||
'device': serial,
|
'device': serial,
|
||||||
'clock': int(datetime.datetime.now().timestamp()),
|
'clock': int(datetime.datetime.now().timestamp()),
|
||||||
'payload': {
|
'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