MQTT Binding Fails for Non-Localhost

Hi! I’ve just started using OpenHAB with MQTT bindings.
Setup

  • Debian linux with mosquitto broker and openhab. apt-get installed recently (Sept 2016).
  • MQTT publishing from arduino boards on the local network
    Error
  • MQTT binding don’t read MQTT results from Arduino boards
    Debugging
    On localhost or another local box, I can publish and see OpenHab update. The following works fine (ie. OpenHAB reads and display it):

localhost>mosquitto_pub -t “emon/emontx/temp1” -m 25
localhost>tail /var/log/mosquitto.conf (I’ve turned on log_all):

1474197944: New client connected from ::1 as mosqpub/23840-blacklap2 (c1, k60).
1474197944: Sending CONNACK to mosqpub/23840-blacklap2 (0)
1474197944: Received PUBLISH from mosqpub/23840-blacklap2 (d0, q0, r0, m0, ‘emon/emontx/temp0’, … (2 bytes))
1474197944: Sending PUBLISH to mosq/I0kZJ9M9cVq:sxNY35 (d0, q0, r0, m0, ‘emon/emontx/temp0’, … (2 bytes))
1474197944: Sending PUBLISH to openhab.1474197199202 (d0, q0, r0, m0, ‘emon/emontx/temp0’, … (2 bytes))
1474197944: Received DISCONNECT from mosqpub/23840-blacklap2

But although the arduinos publish (and mosquitto re-publishes to openhab) I don’t see it appear in OpenHab.
localhost>tail /var/log/mosquitto.conf (after arduino publish):

1474198626: Received PUBLISH from bbtemps1 (d0, q0, r0, m0, 'emon/emontx/temp0', ... (9 bytes))
1474198626: Sending PUBLISH to mosq/I0kZJ9M9cVq:sxNY35 (d0, q0, r0, m0, 'emon/emontx/temp0', ... (9 bytes))
1474198626: Sending PUBLISH to openhab.1474197199202 (d0, q0, r0, m0, 'emon/emontx/temp0', ... (9 bytes))

I can subscribe to the topics fine. I’ve turned off all authentication.
Config
# openhab.cfg: mqtt only relevant line: mqtt:mosquitto.url=tcp://localhost:1883
# default.items: also tried a plain string here, to no avail Number emonth_t0 "Friends Room [%.1f°C]" { mqtt="<[mosquitto:emon/emontx/temp0:state:default]" }

It seems OpenHAB sees the MQTT values from the arduinos, but does not understand them?

You have provide a lot of good information except what we really need.

What are your Item configs?

What appears in openhab.log? In particular are there errors or at least an indication that OH is seeing the messages?

Hi Rich, thanks for your reply.

“What are your Item configs?”

I think you’re referring to the items listed in “default.items” . I listed that under “config” heading (3,4 line) in the question. If that’s not it, where are “item configs”? Apologies for my newbieness…

What appears in openhab.log?

Yes, there are errors when arduino publishs data:

localhost>tail -F /var/log/openhab.log
2016-09-19 17:53:02.703 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for ‘emonth_t4’
2016-09-19 17:53:02.988 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for ‘emonth_t8’
2016-09-19 17:53:06.231 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for ‘emonth_t2’

Is there any chance at all that the Arduino code that is publishing these numbers is formatting them in such a way that there are non-numeric characters in the message, such as padding with spaces before or after the digits, or using thousands separator characters, or using a comma instead of a period as a decimal separator? The openHAB log messages are consistent with trying to parse numbers but the MQTT message contained unacceptable characters.

Exactly! Indeed there is a whitespace issue (hint: “9 bytes” in the log). Yes, I found that whitespace fails in OpenHAB parsing. For others’ sakes, I’ll tell you that I changed Arduino sketch from:

dtostrf(tempC,-(PRINT_BUFFER_LEN-2),2,valCharStar); // oh no! now valCharStar is whitespace buffered - poison to OpenHAB
to
String valString = dtostrf(tempC,-(PRINT_BUFFER_LEN-2),2,valCharStar); valString.trim(); // remove poison whitespace

This is a difficult error to debug (as whitespace is invisible using mosquitto_pub / _sub).
Thanks again for your help. It’s working nicely now.