Browse Source

date time fixed

master
caliskanbi 1 year ago
parent
commit
612e3b1b93

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

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

BIN
software/backend/backend_database.db View File


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

""" """
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from plantdatabase import PlantDataBase from plantdatabase import PlantDataBase
from software.defines import Topics, MAX_PLANT_COUNT
from defines import Topics, MAX_PLANT_COUNT
import json import json
import uuid import uuid
from typing import Union from typing import Union
def action_getbattery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): def action_getbattery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage):
client.publish(Topics['ROBOT_ACTION_GETBATTERY']) client.publish(Topics['ROBOT_ACTION_GETBATTERY'])
logging.info("BACKEND_ACTION_GETBATTERY message forwarded to Robot") 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): 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

import paho.mqtt.client as mqtt 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 from random import randrange, uniform
import time import time
import json 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): def on_connect(client, userdata, flags, rc):
client.connect(mqttBroker) client.connect(mqttBroker)


plantdata = { plantdata = {
"PlantName": "Kemal"
"AirTemperature": 1.0,
"AirHumidity": 1.0,
"SoilMoisture": 1.0,
"Brightness": 1,
"PlantID": 2,
"Timestamp": "",
"MeasurementID": 0,
"PlantName": "test"
} }



print(type(PLANTDATA)) print(type(PLANTDATA))
client.publish("BACKEND/ACTION/GETBATTERY", json.dumps(plantdata))
client.publish(Topics['BACKEND_ACTION_NEWPLANT'], json.dumps(plantdata))
print(json.dumps(plantdata)) print(json.dumps(plantdata))
time.sleep(2) time.sleep(2)

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

import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import time 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): def on_message(client, userdata, message):
print("Connection failed") print("Connection failed")




mqttBroker = "192.168.178.182"
mqttBroker = ""


client = mqtt.Client() client = mqtt.Client()
client.connect(mqttBroker, 1883)
client.connect(MQTT_BROKER_GLOBAL, 1883)


client.on_message = on_message client.on_message = on_message


client.subscribe("TEST")
client.subscribe(Topics['BACKEND_ACTION_GETALLDATA'])
client.loop_forever() client.loop_forever()

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



# imports # imports
import paho.mqtt.client as mqtt 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 from plantdatabase import PlantDataBase
import data_functions import data_functions
import logging import logging

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



table_config = "CREATE TABLE IF NOT EXISTS measurement_values " \ table_config = "CREATE TABLE IF NOT EXISTS measurement_values " \
"(measurementID INTEGER PRIMARY KEY," \ "(measurementID INTEGER PRIMARY KEY," \
"Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP," \
"Timestamp DATETIME DEFAULT (datetime('now', 'localtime'))," \
"PlantID INTEGER, " \ "PlantID INTEGER, " \
"AirTemperature REAL," \ "AirTemperature REAL," \
"AirHumidity REAL," \ "AirHumidity REAL," \

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


+ 1
- 1
usefull-stuff.md View File





## Passwords: ## Passwords:
- Backend PC: Lego_Ohm1
- Backend PC: Lego?Ohm1
- Raspy: OHM_123.! - Raspy: OHM_123.!

Loading…
Cancel
Save