From 612e3b1b93ca19b5812d418f77df1b4a20e093fe Mon Sep 17 00:00:00 2001 From: caliskanbi Date: Thu, 25 May 2023 12:15:05 +0200 Subject: [PATCH] date time fixed --- .idea/deployment.xml | 5 +++-- software/backend/backend_database.db | Bin 16384 -> 16384 bytes software/backend/data_functions.py | 8 ++++++- software/{ => backend}/defines.py | 0 .../dev_test_examples/mqtt_publisher.py | 20 ++++++++++++------ .../dev_test_examples/mqtt_subscriber.py | 9 ++++---- software/backend/main.py | 2 +- software/backend/plantdatabase.py | 2 +- software/backend/tests/test_database.db | Bin 16384 -> 16384 bytes usefull-stuff.md | 2 +- 10 files changed, 32 insertions(+), 16 deletions(-) rename software/{ => backend}/defines.py (100%) 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 8880ff8ce6ebdd80bcf2cb5b149469261afe0ca6..3cbd3b58c08278a0465571250a766ee16ef79fb8 100644 GIT binary patch delta 111 zcmZo@U~Fh$oFL6;I#I@%(R5?N5`G>g{DsPHl{FsN|eo6K(D&cu0dV`CquoQw(wgE1o~5EvO48S5ID>Kd9W7@Aud Pm|7VdF>U^1$-)Kz<0%}a delta 77 zcmZo@U~Fh$oFL6;JW={%;KY-}vA0zu~{JSy12<|KwZp!W;}hz#&{% gzWJ*>mjH({FOaLu`DZe_f&0eBb)1|3ShBDI0F|Q`L;wH) 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 40c152cedcfd84bf2cf3ce43559ad745d1e0b35c..6e05cfb266e54245aded98584e88ca51a02d373b 100644 GIT binary patch delta 160 zcmZo@U~Fh$oFL8UH&Mo!(QjkIWPK4qE=Fca#)6#0ypm!zUIqpRL7vFT>;|%IJjZz^ z@I-EG)aQ{k735$rW@Kk)XEZV}GS)RP)ip9yFtoHXv9vO_oa|^XEhB(kfuXULsTo)S ZKe_@#a|J^KD-#PVL$C>(|JyJ!0|0)uAOHXW delta 53 zcmZo@U~Fh$oFL6;Gf~Ew(Pm@9WPK4nE=Fca#)6#0ypm!zUIqpRKAwM**$rejHs0dd J{LhAo832J!4&wj- 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