Browse Source

Changes after Test added

master
caliskan 1 year ago
parent
commit
052ace21bf

+ 1
- 1
.idea/webServers.xml View File

@@ -3,7 +3,7 @@
<component name="WebServers">
<option name="servers">
<webServer id="1b3e9e3f-7394-4cbc-a32d-b95ef2abda52" name="backend">
<fileTransfer accessType="SFTP" host="lego-K53SV" port="22" sshConfigId="40359a92-2c87-41df-943b-cfac73c7ea3d" sshConfig="lego@lego-K53SV:22 password">
<fileTransfer accessType="SFTP" host="192.168.137.197" port="22" sshConfigId="8ca8aafc-5b14-4074-b370-599a5b56368a" sshConfig="lego@192.168.137.197:22 password">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions>

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

@@ -51,7 +51,7 @@ def data_position(client: mqtt.Client, userdata, message: mqtt.MQTTMessage, robo


def data_battery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage, robot: Robot):
logging.info("ROBOT_DATA_BATTERY Received data: " + json.dumps(message.payload.decode("UTF-8")))
logging.info("ROBOT_DATA_BATTERY Received data: " + str(json.dumps(message.payload.decode("UTF-8"))))
robot.store_battery(json.loads(message.payload.decode("UTF-8"))["Battery"])
battery_data = {
"Battery": robot.get_battery(),
@@ -98,12 +98,6 @@ 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):

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

@@ -4,7 +4,7 @@ created by caliskan at 19.04.2023
contains all constants for the backend architecture of the smart garden project
"""

MQTT_BROKER_LOCAL = "192.168.0.199"
MQTT_BROKER_LOCAL = "192.168.137.197"
MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io"
RASPI_CLIENT_ID = "smart_farming_raspi"
BACKEND_CLIENT_ID = "smart_farming_server"

+ 3
- 10
software/backend/dev_test_examples/mqtt_publisher.py View File

@@ -19,21 +19,14 @@ def on_connect(client, userdata, flags, rc):
client = mqtt.Client()
client.on_connect = on_connect

client.connect(mqttBroker)
client.connect("mqtt://192.168.137.197", 1883)

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


print(type(PLANTDATA))
client.publish(Topics['BACKEND_ACTION_NEWPLANT'], json.dumps(plantdata))
client.publish(Topics['ROBOT_DATA_BATTERY'], json.dumps(plantdata))
print(json.dumps(plantdata))
time.sleep(2)

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

@@ -44,7 +44,7 @@ def on_connect(_client: mqtt.Client, _userdata, _flags, _rc, _mydatabase, _robot

_client.subscribe(Topics['ROBOT_DATA_BATTERY'])
_client.message_callback_add(Topics['ROBOT_DATA_BATTERY'], lambda client, userdata, message: data_functions.
data_battery(client, userdata, message))
data_battery(client, userdata, message, _robot))

# client.subscribe('Robot/Data/Picture')

@@ -101,7 +101,7 @@ def main():
robot = Robot()
my_database = PlantDataBase(database_name=DATABASE_NAME)
my_database.create_tables()
mqttclient = mqtt.Client(BACKEND_CLIENT_ID)
mqttclient = mqtt.Client(BACKEND_CLIENT_ID, transport="websockets")
mqttclient.on_connect = lambda client, userdata, flags, rc: on_connect(_client=client,
_userdata=userdata,
_flags=flags,

Loading…
Cancel
Save