I have a dsb18b20 working just fine, publishing OK to MQTT.
But, I don't need three decimal places when 1 would be just fine.
I've formatted the reading OK, but on publish it says
TypeError: 'str' object is not callable - what's the solution to this, please?
But, I don't need three decimal places when 1 would be just fine.
I've formatted the reading OK, but on publish it says
TypeError: 'str' object is not callable - what's the solution to this, please?
Code:
import timefrom w1thermsensor import W1ThermSensorfrom paho.mqtt import client as mqttrunning = Truesensor = W1ThermSensor()# Setup mqttclientId = "sensor1"port = 1883broker = "192.nnn.n.nn"client = mqtt.Client(clientId)client.connect(broker, port)while True: temperature = sensor.get_temperature() print("The temperature is %s celsius" % temperature) temperature_formatted = ( f"{temperature:.1f}" ) print (temperature_formatted) client.publish("sensor1",temperature_formatted()) print("publishing....") time.sleep(5)Statistics: Posted by richard238 — Sat Apr 19, 2025 4:04 pm — Replies 1 — Views 69