diff --git a/README.md b/README.md index 6e996c5..a91d62a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # gin206-iot IOT Project for the GIN206 course of Télécom Paris + +# Description +The main.py file contains the code generating the graphs seen on the document submitted for the project. The implementation.py file contains the code that sends the data to the Thingsboard server. + +# How to setup the implementation +Install the requirements +``` +pip install -r requirements.txt +``` +Create a .env file in the root directory of the project with the following content: +``` +SENSOR_API_URL= # URL of the sensor API +THINGSBOARD_URL = # URL of the Thingsboard server +``` +Run the application +``` +python implementation.py +``` \ No newline at end of file diff --git a/implementation.py b/implementation.py new file mode 100644 index 0000000..9cc6608 --- /dev/null +++ b/implementation.py @@ -0,0 +1,63 @@ +import time +import requests +from dotenv import load_dotenv +import os + +dT = 0.5 + +RATE_OF_CHANGE = [ + 0.609164, + 0.533102, + 0.490007, + 0.441728, + 0.422819, + 0.397558, + 0.381043, + 0.459887, + 1.095440, + 2.825424, + 3.922974, + 3.454793, + 2.309282, + 1.671112, + 1.513777, + 1.621256, + 2.043299, + 2.568422, + 2.934706, + 2.461657, + 2.166300, + 1.601714, + 1.058227, + 0.778290, + ] + +load_dotenv() + +def poll_data(): + # make a api call to http://quentin.com/api/temperature + res = requests.get(os.getenv("SENSOR_API_URL")).json() + return res["temperature"] + +def push_data(temperature): + print(f"Pushed data: {temperature}") + requests.post(os.getenv("API_URL"), json={"temperature": temperature}) + +def main(): + temperature = poll_data() + push_data(temperature) + while True: + #get hour of the day + current_hour = time.localtime().tm_hour + #get the rate of change for the current hour + rate_of_change = RATE_OF_CHANGE[current_hour] + #calculate the wait before the next poll + wait_time = 3600 * dT / rate_of_change + #wait + time.sleep(wait_time) + #poll data + new_temperature = poll_data() + print(f"New temperature: {new_temperature}") + #push data + push_data(new_temperature) + diff --git a/main.py b/main.py index f452c78..bca2c42 100644 --- a/main.py +++ b/main.py @@ -192,8 +192,9 @@ def histogram_sample_every_kth_point(k=10): # comparaison_mean(df) # Temperature rate of change over the day -# df = generate_greenhouse_data("datasets/greenhouse.csv") -# hcor = hourly_rate_of_change(df) +df = generate_greenhouse_data("datasets/greenhouse.csv") +hcor = hourly_rate_of_change(df) +print(hcor) # hcor.plot() # plt.xlabel("Hour of the day") # plt.ylabel("Average absolute rate of change (°C/hour)") @@ -202,8 +203,8 @@ def histogram_sample_every_kth_point(k=10): # plt.xlabel("Hour of the day") # plt.show() -df = generate_greenhouse_data("datasets/greenhouse.csv") -comparaison_mean(df, 1000) +# df = generate_greenhouse_data("datasets/greenhouse.csv") +# comparaison_mean(df, 1000) # example_sample_every_kth_point(1) # example_sample_every_kth_point(10) diff --git a/requirements.txt b/requirements.txt index 3bd22ab..a75ea90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ pandas -noise \ No newline at end of file +noise +requests +python-dotenv \ No newline at end of file