Revolution
Commodore
- Registriert
- März 2008
- Beiträge
- 4.965
Hallo zusammen,
Ich hab ein Problem ich bekomme die Variable nicht in die andere Funktion und ich verstehe nicht was ich falsch mach ...
TypeError: mqtt() missing 1 required positional argument: 'mqttsend'
Ich hab ein Problem ich bekomme die Variable nicht in die andere Funktion und ich verstehe nicht was ich falsch mach ...
TypeError: mqtt() missing 1 required positional argument: 'mqttsend'
Python:
def readsensors():
# read slave list from master 1
file = open('/sys/devices/w1_bus_master1/w1_master_slaves')
w1_slaves = file.readlines()
file.close()
temperaturliste = []
# for each slave
for line in w1_slaves:
# get slave id
w1_slave = line.split("\n")[0]
# read temp from slave id
file = open('/sys/bus/w1/devices/' + str(w1_slave) + '/w1_slave')
filecontent = file.read()
file.close()
# calc and show temp
stringvalue = filecontent.split("\n")[1].split(" ")[9]
temperature = float(stringvalue[2:]) / 1000
temperaturliste.append(temperature)
temp0 = str(temperaturliste[0])
temp1 = str(temperaturliste[1])
temp2 = str(temperaturliste[2])
temp3 = str(temperaturliste[3])
sep = str(",")
mqttsend = "".join((temp0,sep,temp1,sep,temp2,sep,temp3))
print(mqttsend)
return mqttsend
def mqtt(mqttsend):
mqttsend = readsensors()
client = mqttClient.Client("Python")
client.username_pw_set(user, password=password)
client.on_connect= on_connect
client.connect(broker_address, port=port)
client.loop_start()
while Connected != True: #Wait for connection
time.sleep(0.1)
try:
while True:
print(mqttsend)
value = (mqttsend)
client.publish("test",value)
except KeyboardInterrupt:
client.disconnect()
client.loop_stop()
mqtt()