PROBLEM with Mosquito MQTT with ESP8266

Hi everyone, I’m asking for help with the above mentioned issues.
I try to summarize as much as possible.
My configuration involves an ESP8266 which publishes the values of 4 sensors, via wifi, and it works because with the app on the phone I see the published messages…
On the Raspeberry where OH4 is installed, Mosquito is also active.
The configuration of everything is done with files and is as follows:

ESP8266 CONFIGURATION

‘’’
randomSeed(analogRead(A0));
pompa_temperatura = int(random(0, 100));
Serial.print("Temperatura Pompa : ");
Serial.println(pompa_temperatura);
itoa(pompa_temperatura, mqtt_pompa_temperatura, 10);
client.publish(“mqttChannelPompaTemperatura”, mqtt_pompa_temperatura);
‘’’

BRIDGE AND THING CONFIGURATION
‘’’
Bridge mqtt:broker:mqttBridgeBrokerMosquito “Mosquito OH4”[ host=“localhost”, port=1883, username=“xxxx”, password=“yyyy” ]

Thing mqtt:topic:mqttThingPompaIrrigazione “Pompa Irrigazione” (mqtt:broker:mqttBridgeBrokerMosquito) {
Channels:
Type contact : mqttChannelPompaStato “Pompa - Topic Stato” // [min=0, max=1, step=1]
Type number : mqttChannelPompaPortata “Pompa - Topic Portata” [min=0, max=100, step=1, “l/min”]
Type number : mqttChannelPompaPressione “Pompa - Topic Pressione” [min=0, max=10, step=1, “bar”]
Type number : mqttChannelPompaTemperatura “Pompa - Topic Temperatura” [min=0, max=100, step=1, “°C”]
}
‘’’

ITEMS CONFIGURATION
‘’’
String mqttItemPompaStato “Pompa topic stato” (GR_Info_Pompa) {autoupdate=“true”, channel=“mqtt:topic:mqttThingPompaIrrigazione:mqttChannelPompaStato”}
String mqttItemPompaPortata “Pompa topic portata” (GR_Info_Pompa) {autoupdate=“true”, channel=“mqtt:topic:mqttThingPompaIrrigazione:mqttChannelPompaPortata”}
String mqttItemPompaPressione “Pompa topic pressione” (GR_Info_Pompa) {autoupdate=“true”, channel=“mqtt:topic:mqttThingPompaIrrigazione:mqttChannelPompaPressione”}
String mqttItemPompaTemperatura “Pompa topic temperatura” (GR_Info_Pompa) {autoupdate=“true”, channel=“mqtt:topic:mqttThingPompaIrrigazione:mqttChannelPompaTemperatura”}
,

The Bridge and the Thing are ONLINE and therefore configured correctly,
I see the channel values pass through, but the problem is that the ITEM values are always NULL.
I have done various tests by changing the data TYPES both on the Channels and on the Items but to no avail…
I’m not a programmer, I can get by with some of these things, but in this case I can’t continue…
Maybe it’s just a syntax error…
THANK YOU ALL FOR THE HELP

No :slight_smile:

But first: Please mark code with code fences:
``` ← three backticks (there are several buttons for this in the textbox to write a posting)

code goes here

```

You will have to set the stateTopic to get data from the broker. Please take care of names and UIDs, as they are not correct in your example.

Bridge mqtt:broker:mosquitto "Mosquito OH4 Bridge" [ host="localhost", port=1883, username="xxxx", password="yyyy" ]

Thing mqtt:topic:mosquitto:irrigazione "Pompa Irrigazione" (mqtt:broker:mosquitto) {
    Channels:
    Type  number : temperatura "Pompa - Temperatura" [ stateTopic="mqttChannelPompaTemperatura", unit="°C" ]
}

I skipped the other channels. Please do not set min, max and step for pure receive channels.

Number:Temperature PompaTemperatura "Pompa temperatura" (GR_Info_Pompa) {channel="mqtt:topic:mosquitto:irrigazione:temperatura", unit="°C", stateDescription=""[pattern="%.1f °C"]}

There is no need to set autoupdate="true" as this is default behavior. Furthermore autoupdate is only relevant if an Item is used to send commands (you would need a commandTopic for those channels)

EDIT: fixed Typo in broker UID

1 Like

Hi, many thanks for your replay. :pray:
Sorry for the incorrect layout, I edited the post, it should be clearer now.

while ? on OH4 item list i see the grenn icon ONLINE :

I modified the code last night, which is perhaps more correct, now it is like this:

**ESP8266 CONFIGURATION (ONLY ONE FOR EXAMPLE) **
‘’’
int pompa_stato = 0;
char *mqtt_pompa_stato = “0”;
#define mqttChannelPompaStato “Pompa/Stato”

itoa(pompa_stato, mqtt_pompa_stato, 10);
client.publish(mqttChannelPompaStato, mqtt_pompa_stato, true);
‘’’

BRIDGE AND THING CONFIGURATION
‘’’
Bridge mqtt:broker:mqttBridgeBrokerMosquito “Mosquito OH4”[ host=“localhost”, port=1883, username=“xxx”, password=“yyy” ]

Thing mqtt:topic:mqttThingPompaIrrigazione “Pompa Irrigazione” (mqtt:broker:mqttBridgeBrokerMosquito) {
Channels:
Type string : mqttChannelPompaStato “Pompa - Topic Stato”
}
‘’’

ITEMS CONFIGURATION
‘’’
String mqttItemPompaStato “Pompa Item Stato” (GR_Info_Pompa) {channel=“mqtt:topic:mqttThingPompaIrrigazione:mqttChannelPompaStato”}
‘’’

Perhaps now the configuration is more correct, in fact using MQTT Explorer the result is this:

image

Where am I doing the syntax wrong?
thank you so much for the support!!

But ONLINE is not necessarily “all correct” :slight_smile:
A Thing may be online, when it’s dedicated to a bridge, which is online. It may or may not have Channels, the Channels may or may not be functional.

Given the screenshot of MQTT Explorer the stateTopics are

Pompa/Stato
Pompa/Portata
Pompa/Pressione
Pompa/Temperature

setting these topics as stateTopic parameter is mandatory for a functional channel.
You must set the channels correctly.

There is no point in using wording like mqtt in UIDs (the UID already contains mqtt as the first part), Bridge or Broker (already contained…), Thing (why?) or Channel, as well as mqtt or Item in an Item name (ALL Items are Items, and there is absolutely no need to make an Item name depending on the used binding, as Items are independent of the binding by definition.

An even more common way to define Bridge/Things/Channels is to do it hierarchic - you won’t need to add the bridge information over and over again, as it’s set automatically via the hierarchy:

Bridge mqtt:broker:mosquitto "Mosquito OH4 Bridge" [
    host="localhost",
    port=1883,
    username="xxxx",
    password="yyyy" ]
   {
    Thing topic irrigazione "Pompa Irrigazione" {
        Channels:
        Type number : stato       "Pompa - Stato"       [ stateTopic="Pompa/Stato" ]
        Type number : portata     "Pompa - Portata"     [ stateTopic="Pompa/Portata" ]
        Type number : pressione   "Pompa - Pressione"   [ stateTopic="Pompa/Pressione" ]
        Type number : temperatura "Pompa - Temperatura" [ stateTopic="Pompa/Temperatura", unit="°C" ]
    }
}

Items for the channels:

Number             PompaStato       "Pompa Stato"       (GR_Info_Pompa) {channel="mqtt:topic:mosquitto:irrigazione:stato" }
Number             PompaPortata     "Pompa Portata"     (GR_Info_Pompa) {channel="mqtt:topic:mosquitto:irrigazione:portata"}
Number             PompaPressione   "Pompa Pressione"   (GR_Info_Pompa) {channel="mqtt:topic:mosquitto:irrigazione:pressione"}
Number:Temperature PompaTemperatura "Pompa temperatura" (GR_Info_Pompa) {channel="mqtt:topic:mosquitto:irrigazione:temperatura", unit="°C", stateDescription=""[pattern="%.1f °C"]}

EDIT: fixed Typo in broker UID

Not quite. You need to use the backquote ``` not forward quote ‘’'.

Or you can use the icons between the calendar looking icon and the cog looking icon in the post edit menu.

Good morning, thank you for your availability and support. :star_struck:
I’m not a programmer and I’m trying, I just need to read these 4 values, but it’s difficult! :cold_sweat:

I used the correct code you indicated, The result is now this:

image

What could be the problem now?
thanks so much again!

I found the error…it was just an extra “t” in the broker name…NOW IT WORKS!!!
Thanks thanks thanks !!! :star_struck: :smiling_face_with_three_hearts: :heart_eyes: :star_struck:

1 Like

I’m not sure which post is the solution but I’m pretty certain it isn’t mine. It will help future users of the forum if you mark the post with what ever gave you the clue you needed to fix the problem.

Sorry… almost always there is a small typo… :slight_smile: fixed them above.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.