2021-02-16 03:40:22 +00:00
|
|
|
#!/usr/bin/env python3
|
2021-07-07 12:18:06 +00:00
|
|
|
"""
|
2021-03-05 11:35:53 +00:00
|
|
|
script to post data to the ingest route with simulated data for testing
|
|
|
|
|
|
|
|
"""
|
2021-02-16 03:40:22 +00:00
|
|
|
import json
|
2021-07-07 12:18:06 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
def get_config():
|
|
|
|
""" read config file """
|
|
|
|
config_path = 'flask_aqi/config.json'
|
|
|
|
|
|
|
|
with open(config_path, 'r') as config_file:
|
|
|
|
data = config_file.read()
|
|
|
|
|
|
|
|
config = json.loads(data)
|
|
|
|
|
|
|
|
return config
|
2021-02-16 03:40:22 +00:00
|
|
|
|
|
|
|
# get auth
|
2021-07-07 12:18:06 +00:00
|
|
|
|
|
|
|
CONFIG = get_config()
|
|
|
|
user_name = CONFIG['aqi_monitor']['authUsername']
|
|
|
|
user_pass = CONFIG['aqi_monitor']['authPassword']
|
|
|
|
|
2021-02-16 03:40:22 +00:00
|
|
|
|
|
|
|
# example json data as from the esp8266
|
2021-07-07 12:18:06 +00:00
|
|
|
example_data = '{"uptime":33,"temperature":35.36,"pressure":970.9545,"humidity":41.44336,"pm25":4.5,"pm10":6.2,"sensor_id":1}'
|
|
|
|
|
2021-02-16 03:40:22 +00:00
|
|
|
|
|
|
|
# make the call
|
2021-07-07 12:18:06 +00:00
|
|
|
response = requests.post("http://localhost:5000/data/in", json=example_data, auth = (user_name, user_pass))
|
2021-02-16 03:40:22 +00:00
|
|
|
|
|
|
|
# print result
|
|
|
|
print(response)
|
|
|
|
print(response.text)
|