Using mqtt from ESP to Openhab2

This is great - thanks.
I have never seen anything like:

hence my pursuit of an answer.
The two terminals test works perfectly as do similar tests I have done previously.
I think I will try re-loading the ESP software and see if anything changes.

Ok. Solved. It was my ESP setup. I decided I had to publish something else from the ESP12E so used a system info parameter in a new task to prove I could send a message of some sort. Had some success there. Went back and adjusted a couple of things with my temperature device and am now sending data which can be seen at the cmdline.
Not yet getting data into OH2 but with a bit of trial and error with the items line should be good to go.
Thanks for the help and patience guys.

The winning line in the Items file is:
Number DS18B20ESP “Temperature ESP2 [%.2f °C]” (HouseTemps) {mqtt="<[localbrokerrb:/DeviceESP12E/Room1/Temperature:state:default]"}

Hope this thread helps some others with DS18B20 sensors using mqtt on ESP8266 to Openhab2.

Hi Rob,

this are good news that your MQTT is working now.
Because of you I gave ESPEasy a try on my project with ESP8266 and 11 DS18B20 and one DHT11.
The setup of the devices is easy going, but my ESP8266 won’t connect to my home wifi :wink:

So now I am on my way to get this (normally easy) part done…

Andreas

Hi Andreas
Can you ping your ESP device?

Slightly OT, but another (very good) ESP framework for MQTT IMO is Homie. YMMV and I am sure ESPEasy is great. Just thought I would add it here for those interested.

Myself and @jpmens wrote a python based OTA update server which allows you to monitor and update your Homie devices from the comfort of your armchair!

Hi Rob,

I have some ESP-12E modules soldered to one of these white breakout boards.
With one of these boards I tried to use ESPEasy:

  • all 11 DS18B20 are detected and the right temperature is displayed
  • the DHT11 is working as well, temperature and humidity are in the expected range
  • the AP-mode is working, I can connect to ESP_0 and get the config pages
  • giving the right credentials for WifiSSID and Wifikey, the ESP cannot connect to my home wlan

This weekend I tried with an NodeMCU v1.0 compatible board and had the same sketch compiled and loaded. And here I have no problem connecting to my home wlan!!!
The way was the same:

  • loading sketch to ESP
  • restart ESP with power cycle
  • use serial console
  • set WifiSSID, Wifikey and do “save” to EEPROM
  • reset device
  • first attempt to connect to WLAN was sucessful!!!

So I have to find the difference of both designs to check, if the problem is hardware related or if I bought scrap.

Andreas

PS: first I was looking for Homie. But for me it is not obvious at first sight how to configure my 12 sensors within Homie. Within ESPEasy you just go step by step through the webbased configuration pages…
Maybe someone can give me an easy example, how to configure Homie for my Project (please in a new thread, I don’t want to hi-jack this thread)

Thanks for the post on Homie. I have not checked it out but will do so. Maybe it is a good option but certainly EasyESP is well developed for a range of devices.
I notice reference to Wemos in your device table. Would that be a Wemos D1 by any chance? I think this is a pretty smart ESP8266 device for being pin compatible with arduino boards so the use of existing shields can be extended. makes the 3V3 and 5V issue resolve easily also.

Have you tried setting the device (Unit Nr.) to a non-zero value so you have e.g. ESP_2 ? I think you just need to then connect wirelessly once to that AP and confirm your local IP address and then you can connect with your browser.
Maybe your [quote=“imhofa, post:32, topic:11549”]
NodeMCU v1.0 compatible board
[/quote]
had a device Number 1 so it went thru smoothly?

Wemos D1 Mini. Great little device, very cheap, and there is a range of
shields from Wemos as well.

Yes mine is D1 (retired) now replaced by:
http://www.wemos.cc/Products/d1_r2.html
which is still pin compatible with arduino - this was my interest. I particularly wanted the Arduino FET shield for driving an LED strip (about 60W).
The D1 Mini is indeed a great little device with its range of shields and you can do so much in a compact package.

I set the unit nr to a different value than 0 (first ESP to 1 and NodeMCU compatible I set to 2) within the first configuration. After this setting and a reboot I was able to connect to ESP_1 or ESP_2 but the ESP8266 was not connecting to my home WLAN…

Because the NodeMCU was working like a charme without any poblems, I think the different PCBs will be the answer. At the moment I added a R-C-timedelay at RESET to get a defined reset at power-up (and also have a stable voltage at RESET through the pull-up) and put a 4u7 capacitor direct on the ESP8266-PCB between 3V3 and GND.

This evening I will try if this is the solution for the probelm… Otherwise I have to look for other differences within the schematics.

Andreas

So you could connect to the wireless AP ESP_1 and after confirming you could not see a wireless IP address at your router? And you could for the NodeMCU? If so did you select the correct board in the Arduino IDE for the ESP8266? What is your ESP8266 device?

Hello Rob,

last night I just plugged in my ESP-12E with the additional electronic parts (Reset with pull-up R=10k and capacitor 220nF to GND; capacitor 4u7 between VCC and GND) and it connected to my home WLAN without anny further Settings (I compiled the source code with the credentials of my WLAN as Default values…)

So everything works fine now and I can see may temperature and humidity values within my MQTT Broker.

Now I just have to install the DS18B20 eithin my heating system and everything will work like a charme…

Thank you for your help,
Andreas

Glad you got it working.
Do you think it was all to do with the resistors and caps?

I think the main issue was the reset pin. Maybe I will try it with an other ESP-12E to confirm the results…

Hi guys.

I am having same errors about bad socket on MQTT

I just have installed an Openhabian image with Mosquitto and openhabgenerator.

I am looking to connect a device ESP8266 node MCU using ESP Easy V2.0

below you can see my logs, and attached the ESP easy screens.


ESPEasy ControllerMosquitto Log

ESPEasy Log


ESPEasy Log
1419823 : WD : Uptime 24 ConnectFailures 94 FreeMem 22768
1419823 : MQTT : Connection lost
1420934 : MQTT : Failed to connected to broker
1421456 : MQTT : Failed to connected to broker

Mosquitto Log
1504567388: Socket error on client , disconnecting.
1504567418: New connection from 192.168.7.128 on port 1883.

Mosquitto Status
[20:27:13] openhabian@CriaLabPi:~$ sudo systemctl status mosquitto

  • mosquitto.service - Mosquitto MQTT Broker
    Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled)
    Active: active (running) since Sun 2017-09-03 21:54:50 -03; 22h ago
    Docs: man:mosquitto(8)
    https://mosquitto.org/
    Main PID: 453 (mosquitto)
    CGroup: /system.slice/mosquitto.service
    `-453 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

OpenHab2 items
GNU nano 2.2.6 File: /etc/openhab2/items/CriaLab.items

Group Home “CriaLab”
Group GF “GF” (Home)
Group FF “FF” (Home)
Group F2 “F2” (Home)

Group GF_Terrace “Terrace” (Home, GF)
Switch GF_Terrace_Light “Light” (GF_Terrace, Lights)

Have you fully tested your mqtt broker?
In one terminal window type
mosquitto_sub -d -t testTopic

and on another type
mosquitto_pub -d -t testTopic -m "Hello world!"
You should see “Hello world!” on the first terminal window.
This will tell you if the broker is working and connecting correctly.

good point.

the first keeps telling this:

Client mosqsub|29553-CriaLabPi sending CONNECT
Client mosqsub|29553-CriaLabPi received CONNACK
Connection Refused: not authorised.
Client mosqsub|29553-CriaLabPi sending CONNECT
Client mosqsub|29553-CriaLabPi received CONNACK
Connection Refused: not authorised.
Client mosqsub|29553-CriaLabPi sending CONNECT
Client mosqsub|29553-CriaLabPi received CONNACK
Connection Refused: not authorised.

the second terminal was this:

[20:36:05] openhabian@CriaLabPi:~$ mosquitto_pub -d -t testTopic -m "Hello world!"
Client mosqpub|29887-CriaLabPi sending CONNECT
Client mosqpub|29887-CriaLabPi received CONNACK
Connection Refused: not authorised.
Error: The connection was refused.
[20:36:13] openhabian@CriaLabPi:~$

Hi Rob, thank you for the useful information. Everything is working great with my mosquitto server, I can read all the messages from Mqtt.fx, my nodeMCU + DHT11 publishes everything to “sensor/temperature” and “sensor/humidity” but i cant see this on my openhub2 basic UI. I guess that the problem relays when i create the item. Right now i wrote this:

//1
Number Temperature “Temperature [%.1f]” {mqtt="<[broker:sensor/temperature:state:default]"}"

//2
Number Humidity “Humidity [%.1f%%] {mqtt=”<[broker:sensor/humidity:state:default]"}"

name of my broker: "broker"
ip address of the broker: "192.168.0.10"
port: 1883
clientid: "not set"
user: "not set"
pass: “not set”

Can you help me to write the right line in the Items file and the sitemap file? Thank you very much.