Browse Source

date time fixed

master
caliskanbi 1 year ago
parent
commit
612e3b1b93

+ 3
- 2
.idea/deployment.xml View File

@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" serverName="backend" remoteFilesAllowedToDisappearOnAutoupload="false">
<component name="PublishConfigData" autoUpload="Always" serverName="backend" remoteFilesAllowedToDisappearOnAutoupload="false">
<serverData>
<paths name="backend">
<serverdata>
<mappings>
<mapping deploy="/home/lego/SMARTGARDENING" local="$PROJECT_DIR$/software" web="/" />
<mapping deploy="/home/lego/SMARTGARDENING" local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
</serverData>
<option name="myAutoUpload" value="ALWAYS" />
</component>
</project>

BIN
software/backend/backend_database.db View File


+ 7
- 1
software/backend/data_functions.py View File

@@ -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):

software/defines.py → software/backend/defines.py View File


+ 14
- 6
software/backend/dev_test_examples/mqtt_publisher.py View File

@@ -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)

+ 5
- 4
software/backend/dev_test_examples/mqtt_subscriber.py View File

@@ -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()

+ 1
- 1
software/backend/main.py View File

@@ -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

+ 1
- 1
software/backend/plantdatabase.py View File

@@ -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," \

BIN
software/backend/tests/test_database.db View File


+ 1
- 1
usefull-stuff.md View File

@@ -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.!

Loading…
Cancel
Save