diff --git a/.idea/deployment.xml b/.idea/deployment.xml index efacd62..8886a73 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,14 +1,15 @@ - + - + + \ No newline at end of file diff --git a/software/backend/backend_database.db b/software/backend/backend_database.db index 8880ff8..3cbd3b5 100644 Binary files a/software/backend/backend_database.db and b/software/backend/backend_database.db differ diff --git a/software/backend/data_functions.py b/software/backend/data_functions.py index f5ea2e6..7592098 100644 --- a/software/backend/data_functions.py +++ b/software/backend/data_functions.py @@ -6,7 +6,7 @@ Every function should return json format with the wanted data from the database """ import paho.mqtt.client as mqtt from plantdatabase import PlantDataBase -from software.defines import Topics, MAX_PLANT_COUNT +from defines import Topics, MAX_PLANT_COUNT import json import uuid from typing import Union @@ -98,6 +98,12 @@ def action_getposition(client: mqtt.Client, userdata, message: mqtt.MQTTMessage, def action_getbattery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): client.publish(Topics['ROBOT_ACTION_GETBATTERY']) logging.info("BACKEND_ACTION_GETBATTERY message forwarded to Robot") + battery_data = { + "Battery": 66, + "Timestamp": str(datetime.now()) + } + print(battery_data) + client.publish(Topics['BACKEND_DATA_BATTERY'], json.dumps(battery_data)) def action_getalldata(client: mqtt.Client, userdata, message: Union[mqtt.MQTTMessage, list], mydatabase: PlantDataBase): diff --git a/software/defines.py b/software/backend/defines.py similarity index 100% rename from software/defines.py rename to software/backend/defines.py diff --git a/software/backend/dev_test_examples/mqtt_publisher.py b/software/backend/dev_test_examples/mqtt_publisher.py index c2d1091..ae9b8bd 100644 --- a/software/backend/dev_test_examples/mqtt_publisher.py +++ b/software/backend/dev_test_examples/mqtt_publisher.py @@ -1,12 +1,12 @@ import paho.mqtt.client as mqtt -import software.defines -from software.defines import MQTT_BROKER_LOCAL +import software.backend.defines +from software.backend.defines import MQTT_BROKER_LOCAL from random import randrange, uniform import time import json -from software.defines import Topics, PLANTDATA -mqttBroker = software.defines.MQTT_BROKER_GLOBAL +from software.backend.defines import Topics, PLANTDATA +mqttBroker = software.backend.defines.MQTT_BROKER_GLOBAL def on_connect(client, userdata, flags, rc): @@ -22,10 +22,18 @@ client.on_connect = on_connect client.connect(mqttBroker) plantdata = { - "PlantName": "Kemal" + "AirTemperature": 1.0, + "AirHumidity": 1.0, + "SoilMoisture": 1.0, + "Brightness": 1, + "PlantID": 2, + "Timestamp": "", + "MeasurementID": 0, + "PlantName": "test" } + print(type(PLANTDATA)) -client.publish("BACKEND/ACTION/GETBATTERY", json.dumps(plantdata)) +client.publish(Topics['BACKEND_ACTION_NEWPLANT'], json.dumps(plantdata)) print(json.dumps(plantdata)) time.sleep(2) diff --git a/software/backend/dev_test_examples/mqtt_subscriber.py b/software/backend/dev_test_examples/mqtt_subscriber.py index dbbc46f..57938c1 100644 --- a/software/backend/dev_test_examples/mqtt_subscriber.py +++ b/software/backend/dev_test_examples/mqtt_subscriber.py @@ -1,6 +1,7 @@ import paho.mqtt.client as mqtt import time -from software.defines import Topics +from software.backend.defines import Topics +from software.backend.defines import MQTT_BROKER_GLOBAL def on_message(client, userdata, message): @@ -14,12 +15,12 @@ def on_connect(client, userdata, flags, rc): print("Connection failed") -mqttBroker = "192.168.178.182" +mqttBroker = "" client = mqtt.Client() -client.connect(mqttBroker, 1883) +client.connect(MQTT_BROKER_GLOBAL, 1883) client.on_message = on_message -client.subscribe("TEST") +client.subscribe(Topics['BACKEND_ACTION_GETALLDATA']) client.loop_forever() diff --git a/software/backend/main.py b/software/backend/main.py index 6a89c44..3d6c577 100644 --- a/software/backend/main.py +++ b/software/backend/main.py @@ -9,7 +9,7 @@ Used protocol for interaction: mqtt (paho-mqtt module) # imports import paho.mqtt.client as mqtt -from software.defines import MQTT_BROKER_LOCAL, MQTT_BROKER_GLOBAL, Topics, BACKEND_CLIENT_ID, DATABASE_NAME +from defines import MQTT_BROKER_LOCAL, MQTT_BROKER_GLOBAL, Topics, BACKEND_CLIENT_ID, DATABASE_NAME from plantdatabase import PlantDataBase import data_functions import logging diff --git a/software/backend/plantdatabase.py b/software/backend/plantdatabase.py index fb89f77..9229cbd 100644 --- a/software/backend/plantdatabase.py +++ b/software/backend/plantdatabase.py @@ -27,7 +27,7 @@ class PlantDataBase: table_config = "CREATE TABLE IF NOT EXISTS measurement_values " \ "(measurementID INTEGER PRIMARY KEY," \ - "Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP," \ + "Timestamp DATETIME DEFAULT (datetime('now', 'localtime'))," \ "PlantID INTEGER, " \ "AirTemperature REAL," \ "AirHumidity REAL," \ diff --git a/software/backend/tests/test_database.db b/software/backend/tests/test_database.db index 40c152c..6e05cfb 100644 Binary files a/software/backend/tests/test_database.db and b/software/backend/tests/test_database.db differ diff --git a/usefull-stuff.md b/usefull-stuff.md index 13ce350..8f7f640 100644 --- a/usefull-stuff.md +++ b/usefull-stuff.md @@ -56,5 +56,5 @@ To send requests to your service, https://www.postman.com/downloads/ is a good a ## Passwords: -- Backend PC: Lego_Ohm1 +- Backend PC: Lego?Ohm1 - Raspy: OHM_123.! \ No newline at end of file