database fixed and added
This commit is contained in:
@@ -1,15 +1,36 @@
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
from software.defines import MQTT_BROKER_LOCAL
|
||||
from random import randrange, uniform
|
||||
import time
|
||||
import json
|
||||
from software.defines import Topics, PLANTDATA
|
||||
mqttBroker = "mqtt.eclipseprojects.io"
|
||||
|
||||
mqttBroker ="mqtt.eclipseprojects.io"
|
||||
|
||||
client = mqtt.Client("Temperature_Inside")
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
print("Connected")
|
||||
else:
|
||||
print("Connection failed")
|
||||
|
||||
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
|
||||
client.connect(mqttBroker)
|
||||
|
||||
while True:
|
||||
client.publish("ROBOT/ACTION/DRIVE")
|
||||
print("Just published to topic TEMPERATURE")
|
||||
time.sleep(0.5)
|
||||
plantdata = {
|
||||
"AirTemperature": 20.4,
|
||||
"AirHumidity": 7.0,
|
||||
"SoilMoisture": 5.0,
|
||||
"Brightness": 39,
|
||||
"PlantID": 2,
|
||||
"Timestamp": "hallo",
|
||||
"MeasurementID": 187
|
||||
}
|
||||
|
||||
print(type(PLANTDATA))
|
||||
while True:
|
||||
client.publish(Topics["BACKEND_DATA_SENSORDATA"], json.dumps(plantdata))
|
||||
print(json.dumps(plantdata))
|
||||
time.sleep(2)
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
import paho.mqtt.client as mqtt
|
||||
import time
|
||||
from software.defines import Topics
|
||||
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
print("received message: " ,str(message.payload.decode("utf-8")))
|
||||
print("received message: ", str(message.payload.decode("utf-8")))
|
||||
|
||||
mqttBroker ="mqtt.eclipseprojects.io"
|
||||
|
||||
client = mqtt.Client("Smartphone")
|
||||
client.connect(mqttBroker)
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
print("Connected")
|
||||
else:
|
||||
print("Connection failed")
|
||||
|
||||
|
||||
mqttBroker = "192.168.0.199"
|
||||
|
||||
client = mqtt.Client()
|
||||
client.connect(mqttBroker, 1883)
|
||||
|
||||
client.loop_start()
|
||||
client.on_message = on_message
|
||||
|
||||
client.subscribe("TEMPERATURE")
|
||||
client.on_message=on_message
|
||||
|
||||
client.subscribe(Topics["BACKEND_DATA_SENSORDATA"])
|
||||
client.subscribe("Bilal")
|
||||
time.sleep(30)
|
||||
client.loop_stop()
|
||||
client.loop_stop()
|
||||
|
||||
Reference in New Issue
Block a user