I have ventured into the realm of mqtt with a fair bit of reading up my sleeve. I wish to use mqtt to post DS18B20 temperatures from an ESP12E to OH2 on Raspberry Pi 2.
I loaded up ESPEasy on the ESP and used this to install mqtt on the Pi:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
to get the right version of mosquitto thanks to this post: http://www.esp8266.nu/forum/viewtopic.php?t=111
and as a result I see this on the ESP serial monitor:
DS : Temperature: 20.19 (28-6-a3-69-2-0-0-9d)
WD : Uptime 82 ConnectFailures 0 FreeMem 26584
WD : Uptime 82 ConnectFailures 0 FreeMem 26584
DS : Temperature: 20.12 (28-6-a3-69-2-0-0-9d)
WD : Uptime 83 ConnectFailures 0 FreeMem 26584
so looking nice so far.
In OH2 I have this in my Items file:
Number DS18B20ESP âTemperature ESP2 [%.2f °C]â (HouseTemps) {mqtt="<[localbrokerRB:openHAB2:state:default]"}
I have tried replacing default with + and also with *. But still no temperature data displayed.
In testing I have tried this from the command line
mosquitto_sub -h http://192.168.1.112 -t localbrokerRB:openHAB2/DeviceESP12E/Temperature:*
Unable to connect (Lookup error.).
So I obviously have something NQR. Anyone have any thoughts on this?
Thanks for yr reply Watou.
I realised I should have been addressing localhost not the IP of the ESP12E so the more appropriate command is :
mosquitto_sub -d -t localbrokerRB:openHAB2/temperature:state:default
but all i get is:
Client mosqsub/32564-robsberry sending CONNECT
Client mosqsub/32564-robsberry received CONNACK
Client mosqsub/32564-robsberry sending SUBSCRIBE (Mid: 1, Topic: localbrokerRB/openHAB2/temperature:state:default, QoS: 0)
Client mosqsub/32564-robsberry received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/32564-robsberry sending PINGREQ
Client mosqsub/32564-robsberry received PINGRESP
Client mosqsub/32564-robsberry sending PINGREQ
Client mosqsub/32564-robsberry received PINGRESP
I have tried with temperature:status and with temperature:value with similar results.
Thanks for the support.
Used all lowercase in Items line and also tried the same at the cmd line with the same result. Does Subscribed (mid: 1): 0 suggest that the topic is being returned as empty? I figure that I must have a basic config setting wrong but have not been able to trace it down.
I have almost the same setup, so letsâs compare our settings:
On the config page of the espeasy interface:
MAIN CONFIG:
Name: esp8266ledbutton
You MUST use a âunit noâ (it doesnât matter which one)
Locate controller: use ip adress
On the devices page of the espeasy interface:
Task settings:
Name: alarm
idx/var: you MUST use a number, doesnât matter which one
Optional settings: Value name 1: switch
Now it comes to the topic to subscribe: Switch Alarm_Switch_WLAN_IN {mqtt="<[mosquitto:/esp8266ledbutton/alarm/switch:command:ON:1.00],<[mosquitto:/esp8266ledbutton/alarm/switch:command:OFF:0.00]"}
So the topic is: Name: esp8266ledbutton + Name: alarm + Value name 1: switch
Now try to adapt that from my switch to your number item.
Thanks for coming in on this sihui. This is helpful.
My Main config name is DeviceESP12E
Unit number is 2
I have used : Locate controller: use ip adress and the IP address is that of the Pi which is running the mqtt broker.
On Task settings Name is Room1
and Value name is Temperature.
So I should therefore have â<[localbrokerRB:/DeviceESP12E/Room1/Temperature:default]â where localbrokerRB is the broker name in mqtt.cfg - rather different to what I had come up with.
See screenshot of Task summary also.
But I am getting âBinding configuration of type âmqttâ of item âDS18B20ESPâ could not be parsed correctly.â
using Item line : Number DS18B20ESP âTemperature ESP2 [%.2f °C]â (HouseTemps) {mqtt="<[localbrokerRB:/DeviceESP12E/Room1/Temperature/#]"}
I will play around with the last few chars after Temperature and see what I get.
Ok so using
Number DS18B20ESP âTemperature ESP2 [%.2f °C]â (HouseTemps) {mqtt="<[localbrokerRB:/DeviceESP12E/Room1/Temperature:state:default]"}
I get 20:52:07.000 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item âDS18B20ESPâ : 1 subscribers, 0 publishers
in the log.
Plugging this in at the cmdline:
mosquitto_sub -d -t localbrokerrb:DeviceESP12E/Room1/temperature:state:default
still gives just - sending PINGREQ and received PINGRESP
I see this in the mosquitto log after stopping and re-starting the service:
1465818800: New connection from 192.168.1.112 on port 1883.
1465818800: New client connected from 192.168.1.112 as ESPClient2 (c1, k15).
1465819567: New connection from 127.0.0.1 on port 1883.
1465819567: New client connected from 127.0.0.1 as mosqsub/7449-robsberryp (c1, k60).
1465819674: Socket error on client mosqsub/7449-robsberryp, disconnecting.
1465819779: Error in poll: Interrupted system call.
1465819779: mosquitto version 1.4.8 terminating
Then your initial setup of mosquitto seems to have a problem ⊠sorry, but I donât know the reason.
A while ago Iâve written a small tutorial to setup mosquitto and mqtt, maybe that is a little help in the right direction:
Thatâs not the correct syntax. The MQTT topic in the above is DeviceESP12E/Room1/temperature. The other colon-separated bits are openHAB MQTT item binding config strings, which mosquitto doesnât know a thing about.
I have fixed up the commandline syntax - Thanks @Watou.
So I think the mosquitto terminating may have been due to me playing with the log filename to try and get a fresh log. However it is definitley still disconnecting with a socket error after connecting:
465891360: mosquitto version 1.4.8 (build date Tue, 17 May 2016 11:26:59 +0100) starting
1465891360: Config loaded from /etc/mosquitto/mosquitto.conf.
1465891360: Opening ipv4 listen socket on port 1883.
1465891360: Opening ipv6 listen socket on port 1883.
1465891360: Warning: Address family not supported by protocol
1465891373: New connection from 192.168.1.112 on port 1883.
1465891373: New client connected from 192.168.1.112 as ESPClient2 (c1, k15).
1465891385: New connection from 127.0.0.1 on port 1883.
1465891385: New client connected from 127.0.0.1 as mosqsub/1926-robsberryp (c1, k60).
1465891414: New connection from 127.0.0.1 on port 1883.
1465891414: New client connected from 127.0.0.1 as openHAB2 (c1, k60).
1465891458: Socket error on client mosqsub/1926-robsberryp, disconnecting.
1465891464: New connection from 127.0.0.1 on port 1883.
1465891464: New client connected from 127.0.0.1 as mosqsub/2155-robsberryp (c1, k60).
1465891617: Socket error on client mosqsub/2155-robsberryp, disconnecting.
So I will do some searching on that and see what I can discover. I will check out your tutorial thanks @sihui.
Interesting how it disconnects after Openhab client connects and again when I start a commandline connection.
Also have made sure I donât have a leading slash.
and the only thing I see on the commandline is PINGREQ and PINGRESP.
On the serial monitor it shows this on a reboot:
WIFI : Connected!
INIT : I2C
MQTT : Connected to broker
Subscribed to: /DeviceESP12E/#
and then
DS : Temperature: 20.50 (28-6-a3-69-2-0-0-9d)
WD : Uptime 1 ConnectFailures 0 FreeMem 26888
WD : Uptime 2 ConnectFailures 0 FreeMem 26856
DS : Temperature: 20.50 (28-6-a3-69-2-0-0-9d)
no mqtt messages that mention sub or pub. can this be right?
So given the ESP log shows the sysname with a leading slash then I should be including a leading slash in my OH Item line?
I thought the ESPEasy is already doing the publishing. I have seen no instructions for its setup. I think the following in EasyESP sets it up. #define DEFAULT_PROTOCOL 5 // Protocol used for controller communications
// 5 = OpenHAB MQTT