Browse Source

Changes after Test added

master
caliskan 1 year ago
parent
commit
052ace21bf

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

<component name="WebServers"> <component name="WebServers">
<option name="servers"> <option name="servers">
<webServer id="1b3e9e3f-7394-4cbc-a32d-b95ef2abda52" name="backend"> <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>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" /> <advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions> </advancedOptions>

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





def data_battery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage, robot: Robot): 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"]) robot.store_battery(json.loads(message.payload.decode("UTF-8"))["Battery"])
battery_data = { battery_data = {
"Battery": robot.get_battery(), "Battery": robot.get_battery(),
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):

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

contains all constants for the backend architecture of the smart garden project 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" MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io"
RASPI_CLIENT_ID = "smart_farming_raspi" RASPI_CLIENT_ID = "smart_farming_raspi"
BACKEND_CLIENT_ID = "smart_farming_server" BACKEND_CLIENT_ID = "smart_farming_server"

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

client = mqtt.Client() client = mqtt.Client()
client.on_connect = on_connect client.on_connect = on_connect


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


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




print(type(PLANTDATA)) 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)) print(json.dumps(plantdata))
time.sleep(2) time.sleep(2)

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



_client.subscribe(Topics['ROBOT_DATA_BATTERY']) _client.subscribe(Topics['ROBOT_DATA_BATTERY'])
_client.message_callback_add(Topics['ROBOT_DATA_BATTERY'], lambda client, userdata, message: data_functions. _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') # client.subscribe('Robot/Data/Picture')


robot = Robot() robot = Robot()
my_database = PlantDataBase(database_name=DATABASE_NAME) my_database = PlantDataBase(database_name=DATABASE_NAME)
my_database.create_tables() 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, mqttclient.on_connect = lambda client, userdata, flags, rc: on_connect(_client=client,
_userdata=userdata, _userdata=userdata,
_flags=flags, _flags=flags,

Loading…
Cancel
Save