Fernando
(Fernando García)
February 22, 2017, 10:43pm
1
Hi,
I’m trying to send temperature for arduito to openhab2 with mqtt, but openHab2 doesn’t refresh item value.
Arduino works correctly (proved with MQTTfx). The Arduino code:
float temp;
char buffer[10];
temp = sensors.getTempC(insideThermometer);
dtostrf(temp,0, 2, buffer);
psClient.publish("casa/insideTemp", buffer);
temp = sensors.getTempC(outsideThermometer);
dtostrf(temp,0, 2, buffer);
psClient.publish("casa/outsideTemp", buffer);
in openHab2, demo.items:
Group gMqtt
Number inTemp "Inside Temp [%.1f °C]" <temperature> (gMqtt) {mqtt="<[broker:casa/insideTemp:state:default]"}
Number outTemp "Outside Temp" <temperature> (gMqtt) {mqtt="<[broker:casa/outsideTemp:state:default]"}
in openHab2, demo.sitemap
Frame label="Persistece Test temps" {
Text item=inTemp
Text item=outTemp
}
and rr4j.persist
Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
default = everyChange
}
Items {
// persist everything when the value is updated, just a default, and restore them from database on startup
* : strategy = everyChange, restoreOnStartup
inTemp : strategy = everyMinute
outTemp : strategy = everyMinute
}
In HABmin, sitemaps, Inside Temp is allways “NULL”. No change
Any Idea?
Thanks
Have you got MQTT binding installed? If yes, what does your MQTT.cfq file look like?
Fernando
(Fernando García)
February 23, 2017, 9:52pm
3
Yes, it’s installed.
The config file:
borker.url=tcp://localhost:1883
broker.clientId=openhab2
I thinkg openhab2 connect with mqtt, but it doesn’t suscribe the items. It’s possible to check that?
Thanks
So what software are you running as an MQTT broker? In your code the Arduino is publishing to a broker and Openhab2 should subscribe to get data. I use mosquitto running on my RPI as the broker and various Arduino’s publish to the mosquitto broker (and also subscribe for data openhab2 to Arduino) and Openhab2 subscribes to Arduino (and publishes data to send to Arduino).
See http://www.homeautomationforgeeks.com/mosquitto.shtml
mikyh
(Michael)
February 24, 2017, 9:12am
5
The use of the function ‘dtostrf’ has caused problems for another user. It sometimes formats the string in a way that Openhab ignores.
Try the following first:
psClient.publish("casa/outsideTemp", "23");
If that works then it is probably ‘dtostrf’. See here for the other thread and a solution.
Hi all,
I'm struggling with a problem which i can relate to OpenHAB, but i'm not able to solve it. I've been searching the internet for a solution, but unable to find one. I have a DHT22 temp sensor connected to a NodeMCU, which communicates via Raspberry Pi 3 running Mosquitto and OpenHAB. All is working well and temperature+humidity are displayed correctly in Mosquitto and OpenHAB at room temperatures.
Yesterday i moved one DHT22+NodeMCU outside for outdoor temps+humidity. Temperature drop…
For you it would be:
psClient.publish("casa/outsideTemp", String(temp).c_str());
Fernando
(Fernando García)
February 24, 2017, 3:49pm
6
Thanks.
Mosquitto seems to work ok. I’ve suscribed casa/insideTemp with MQTTfx and data is arriving correcty.
I think the problem that openHab2 doesn’t suscribe the items (I don’t see any suscription message in the log option the MQTTfx cliente sw).
Fernando
(Fernando García)
February 24, 2017, 4:00pm
7
Solved. I’ve installed mqtt persistence but not mqtt binding.
Basic error form a beginner. Sorry.
It works now.
Fernando