Pubsubclient doesn't react on rgb message

Hey,

I have openHab running on a RasPi and I have connected an arduino to it. On Arduino I use the pubsubclient to receive the MQQT messages from the RasPi.

There is an example of the callback function of the pubsubclient:

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

So, basically this function is called everytime a message is send to the Arduino. It should then just print the received message. So far, so good.

I have created some basic switches in OpenHab and everytime I press one I can see the corresponding message on Arduino side. So my setup basically works.

Now I have created a Color Item to control a LED stripe which is connected to the Arduino. The problem is that as soon as I change one of the color values in OpenHab I don’t see any message on the Arduino. The callback function just doesn’t pick anything up.
I then used wireshark to check if the actual message is send out or not. But in fact, the RasPi sends the message. But obviously the callback function just ignores it. Other messages are working fine (like the one for the switch)

Any idea what is going on here?

Maybe show your configuration? I’m using color channels with mqtt myself and it just works.

what exactly you want to see?

The thing? It’s all about the connection between openHAB and the broker.

I attached two screenshots:


Maybe you can see something misconfigured here but actually I don’t think the issue can be found here. I in fact can see the message on the network. That means that OpenHab and the broker seem to do everything right. But somehow the arduino doesn’t react to this message.

That’s not the configuration…

well… what is the configuration?!

Let’s try a different approach

So, the MQTT message (that we cannot see) is what you expect, as to content and topic? openHAB is doing everything it should, you have an Arduino coding problem?

@rossko57 I am not sure if it is just an Arduino coding problem. But at least I think the problem is more related to Arduino than to the RasPi or OpenHab.

For me it looks like the RasPi sends out the message correctly (I can see it on the network) but the Arduino just doesn’t recognize it. Although it does with other MQTT messages.

What exactly do you nee to “see the message”?

Configuration: Go to Thing->Code and copy the code. Paste it marked as Code.
Message: What’s a working message (paste the data)? What’s a non working message (paste the data)?
When pasting code, mqtt messages, logs and so on, please mark as code. That way there will be no changing in format or text.

I don’t need to see the message.
but
You obviously want the correct message to be sent.
You’re telling us it is correct, that’s fine.
But you have a problem somewhere.
Maybe there is a typo you don’t see, or a difference in LetterCase, who knows.
If you’d like another pair of eyes to check it over, you have to show it.
If you completely trust your own judgement, then you don’t have to show it, and there’s no point in any of us talking about it.

Hey, I have to apologize. The issue is completely selfmade. I am not yet that much familiar with this MQTT stuff so I missed one line of code: of course I have to subsrice to a topic before I can receive commands from it :man_facepalming:

But now I face another issue:

These are the values which I can set in the corrseponding item. And I do see a receiving message on my Arduino. But the numbers are not the same:

Item in OpenHab

Received message on Arduino:
Screenshot 2022-05-17 171015

Because I have talked so much about network messages I grabbed the one which transmits the acutal data:

Screenshot 2022-05-17 171201

You can see that the numbers send by OpenHab are not the same given by the sliders:

This is the configuration if the thing:

UID: mqtt:topic:MQTT_Broker:154655061b
label: Licht
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:MQTT_Broker
channels:
  - id: light_top_1
    channelTypeUID: mqtt:colorRGB
    label: Licht_Decke_1
    description: ""
    configuration:
      commandTopic: light/LEDStripe/top1/cmnd
      stateTopic: light/LEDStripe/state
      colorMode: HSB

I see that the colorMode is set to HSB but I believe the numbers which are send to the Arduino are the correpsonding RGB values. Why?

For testing I set the colorMode to RGB but doesn’t have any effect on the slider of the item. They stay in HSB mode forever.

How can I make sure the values which I visually see in OpenHab are the same send to my device?

Because that’s what you asked for

By using this deprecated channel type, values are sent as RGB.
This channel type has no colorMode parameter, it’s just ignored.

Use color type channel with color_mode parameter.

Maybe use MQTT Explorer or something similar to see the message at the broker.

aah ok… so you mean better taking this one?

  - id: colorHSB
    channelTypeUID: mqtt:colorHSB
    label: colorHSB
    description: ""
    configuration:
      commandTopic: light/LEDStripe/top2/cmnd

No

Check the link provided by @rossko57 - it points to this exact Channel type.

oh okay, then it must be this one :slight_smile: last one I can choose:

  - id: colorTest
    channelTypeUID: mqtt:color
    label: colorTest
    description: ""
    configuration:
      colorMode: HSB

let’s see what this thing can do.