[SOLVED] Send multiple data with ESP8266 to openhab server

  • Platform information:
    • Hardware: Raspberry pi 3 b+
    • OS: Linux 4.14.34-v7+
    • Java Runtime Environment: i don’t know
    • openHAB version: openHABian 2.3.0-1
  • Issue of the topic: Send and receive multiple data between ESP8266 and MQTT

I’m currently following “mksmarthouse” guides about openhab and I’m trying to send two variables from ESP8266 to openhab server but I don’t know how to do it.

ESP8266 Firmware contain this line for sending data to openhab server:

" client.publish(outTopic, "CLOSED"); "

And in openHABian this is the line for receiving data:

" { mqtt="<[broker:MK-SmartHouse/security/MK-DoorSensor1:state:default] } "

Now I want to know how can I send & receive two or more data, for example if I want to send temperature and humidity data what should I do?

client.publish(humidityTopic, humidity);
client.publish(temperatureTopic, temperature);

The humidity and temperature have char* types, so you will need to convert the value from your senosrs to char*

There are hundreds on examples on the net… Just google esp8266 temperature mqtt

1 Like

@MWB if your new to mqtt I would suggest starting with a known firmware like Esp Easy or Tasmota. Looking at the example items above your using mqtt 1.x binding so I will post an example of one Esp8266 with Esp Easy firmware and BPM-280 sensor as an example.

Number Esp2_BMP_Temp "Esp8266 Temp [%.1f °F]" <temperature> 
	{ mqtt="<[pibroker:/Esp2/BMP/Temp:state:default]" }

Number Esp2_BMP_Humid "Esp8266 Humid [%.1f %%]" <humidity> 
	{ mqtt="<[pibroker:/Esp2/BMP/Humid:state:default]" }	

Number Esp2_BMP_Pressure "Esp8266 Pressure [%.1f mbar]" <pressure> 
    {mqtt="<[pibroker:/Esp2/BMP/Pressure:state:default"}

Hope this helps.

2 Likes

Thank you

Glad to help.:grinning:

If the topic is solved please click the solution.

Thanks

1 Like