MQTT Binding Problem

I can’t get openhab to work with my mqtt broker. The broker is a Rpi with installed mqtt:
pip install paho-mqtt

The client is also a Rpi, with openhab installed and configured with item:

Switch node2_sw1 “sw2” (node2,all) {mqtt=">[mysensor:devices/admin/get:command:ON:1],>[mysensor:devices/admin/get:command:OFF:0]"}

Openhab runtime knows the switch is being toggled.

The Openhab MQTT binding was put in the addon folder.

Figure I might as well list the python code, which seems to be working


import paho.mqtt.client as paho
import RPi.GPIO as GPIO
import json, time

device credentials

device_id = ‘admin’ # * set your device id (will be the MQTT client username)
device_secret = ‘313131’ # * set your device secret (will be the MQTT client password)
random_client_id = ‘MQTT’ # * set a random client_id (max 23 char)

--------------

Board settings

--------------

buttonPin = 7
ledPin = 12

GPIO.setmode(GPIO.BOARD) # use P1 header pin numbering convention
GPIO.cleanup() # clean up resources
GPIO.setup(ledPin, GPIO.OUT) # led pin setup
GPIO.setup(buttonPin, GPIO.IN) # button pin setup

#GPIO.output(ledPin, GPIO.HIGH)

---------------

Callback events

---------------

connection event

def on_connect(client, data, flags, rc):
print('Connected, rc: ’ + str(rc))

subscription event

def on_subscribe(client, userdata, mid, gqos):
print('Subscribed: ’ + str(mid))

received message event

def on_message(client, obj, msg):
# get the JSON message
json_data = msg.payload
# check the status property value
print(json_data)
value = json.loads(json_data)[‘properties’][0][‘value’]

if value == ‘on’:

led_status = GPIO.HIGH
GPIO.output(ledPin, GPIO.HIGH)

else:

led_status = GPIO.LOW

GPIO.output(ledPin, GPIO.LOW)

# confirm changes to Leylan

client.publish(out_topic, json_data)

-------------

MQTT settings

-------------

create the MQTT client

client = paho.Client(client_id=random_client_id, protocol=paho.MQTTv31)

* set a random string (max 23 chars)

assign event callbacks

client.on_message = on_message
client.on_connect = on_connect
client.on_subscribe = on_subscribe

device topics

in_topic = ‘devices/’ + device_id + ‘/get’ # receiving messages
out_topic = ‘devices/’ + device_id + ‘/set’ # publishing messages

client connection

client.username_pw_set(device_id, device_secret) # MQTT server credentials
client.connect(“10.10.10.105”) # MQTT server address
client.subscribe(in_topic, 0) # MQTT subscribtion (with QoS level 0)

------------

Button logic

------------

prev_status = GPIO.LOW
led_status = GPIO.LOW
updated_at = 0 # the last time the output pin was toggled
debounce = 0.2 # the debounce time, increase if the output flickers

Continue the network loop, exit when an error occurs

rc = 0
while rc == 0:
rc = client.loop()
button = GPIO.input(buttonPin)

if button != prev_status and time.time() - updated_at > debounce:
    prev_status = button
    updated_at  = time.time()

    if button:
        led_status = not led_status
        button_payload = 'off'
        if led_status == GPIO.HIGH:
            button_payload = 'on'
        # effectively update the light status
        GPIO.output(ledPin, led_status)
        payload = { 'properties': [{ 'id': '518be5a700045e1521000001', 'value': button_payload }] }
        client.publish(out_topic, json.dumps(payload))

print('rc: ’ + str(rc))

That will install the Python client library but not the broker. The broker is a separate server that acts as the go between. Clients only talk to the broker, never directly to each other. Most people I’ve seen here tend to use mosquitto.

sudo apt-get install mosquitto

Basically you install mosquitto and configure which is the broker and point both your python code and openHAB at that to exchange messages.

If you have already done this could you edit your posting and highlight your Python code and press <ctrl>-k to eliminate the weird formatting. The problem is the # symbol is interpreted as a heading by the forum software. It is really hard to read the code as it is. The same trick also helps with the “Switch” line and any other configuration stuff you copy and paste into this forum.

Also post your MQTT binding config from openhab.cfg (don’t forget to obfuscate your password).

Hey Rich thanks for the help to start off with.

I installed mosquitto at the same time I installed the mqtt client, but I’m not sure exactly what you mean by “configure which is the broker” and how to point my python code and openhab towards it.

I was pointing openhab config towards the python program that was running on my Rpi.

The code and all the steps I took from this guide:
http://lelylan.github.io/lab-projects/raspberry-pi-light/

Only I am using openhab not their virtual “lelylan” client.

Here is the python code.


import paho.mqtt.client as paho
import RPi.GPIO as GPIO
import json, time

– device credentials
device_id = ‘<DEVICE_ID>’ – * set your device id (will be the MQTT client username)
device_secret = ‘<DEVICE_SECRET>’ – * set your device secret (will be the MQTT client password)
random_client_id = ‘<CLIENT_ID>’ – * set a random client_id (max 23 char)


– Board settings –


buttonPin = 7
ledPin = 12

GPIO.setmode(GPIO.BOARD) – use P1 header pin numbering convention
GPIO.cleanup() – clean up resources
GPIO.setup(ledPin, GPIO.OUT) – led pin setup
GPIO.setup(buttonPin, GPIO.IN) – button pin setup


– Callback events –


– connection event
def on_connect(client, data, flags, rc):
print('Connected, rc: ’ + str(rc))

– subscription event
def on_subscribe(client, userdata, mid, gqos):
print('Subscribed: ’ + str(mid))

– received message event
def on_message(client, obj, msg):
– get the JSON message
json_data = msg.payload
– check the status property value
print(json_data)
value = json.loads(json_data)[‘properties’][0][‘value’]
if value == ‘on’:
led_status = GPIO.HIGH
GPIO.output(ledPin, GPIO.HIGH)
else:
led_status = GPIO.LOW
GPIO.output(ledPin, GPIO.LOW)

-- confirm changes to Leylan
client.publish(out_topic, json_data)

– MQTT settings –


– create the MQTT client
client = paho.Client(client_id=random_client_id, protocol=paho.MQTTv31) – * set a random string (max 23 chars)

– assign event callbacks
client.on_message = on_message
client.on_connect = on_connect
client.on_subscribe = on_subscribe

– device topics
in_topic = ‘devices/’ + device_id + ‘/get’ – receiving messages
out_topic = ‘devices/’ + device_id + ‘/set’ – publishing messages

– client connection
client.username_pw_set(device_id, device_secret) – MQTT server credentials
client.connect(“178.62.108.47”) – MQTT server address
client.subscribe(in_topic, 0) – MQTT subscribtion (with QoS level 0)


– Button logic –


prev_status = GPIO.LOW
led_status = GPIO.LOW
updated_at = 0 – the last time the output pin was toggled
debounce = 0.2 – the debounce time, increase if the output flickers

– Continue the network loop, exit when an error occurs
rc = 0
while rc == 0:
rc = client.loop()
button = GPIO.input(buttonPin)

if button != prev_status and time.time() - updated_at > debounce:
    prev_status = button
    updated_at  = time.time()

    if button:
        led_status = not led_status
        button_payload = 'off'
        if led_status == GPIO.HIGH:
            button_payload = 'on'
        -- effectively update the light status
        GPIO.output(ledPin, led_status)
        payload = { 'properties': [{ 'id': '518be5a700045e1521000001', 'value': button_payload }] }
        client.publish(out_topic, json.dumps(payload))

print('rc: ’ + str(rc))


From the 2 parts of my openhab.cfg file:

------------------------------------------------------------------ MQTT Persistence ----------------------------------------------------------------------------------

– Name of the broker as defined in the section MQTT Transport
– mqtt-persistence:broker=

– The MQTT topic to which the persistence messages should be sent.
– mqtt-persistence:topic=

– A string representing the persistence message content.
– mqtt-persistence:message=


– Define your MQTT broker connections here for use in the MQTT Binding or MQTT
– Persistence bundles. Replace with a id you choose.

– URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:mysensor.url=tcp://10.10.10.105:1883

– Optional. Client id (max 23 chars) to use when connecting to the broker.
– If not provided a default one is generated.
–mqtt:mysensor.clientId=MQTT

– Optional. User id to authenticate with the broker.
– mqtt:mysensor.user=admin

– Optional. Password to authenticate with the broker.
–mqtt:mysensor.pwd=******

– Optional. Set the quality of service level for sending messages to this broker.
– Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
– (Deliver exactly once). Defaults to 0.
–mqtt:.qos=

– Optional. True or false. Defines if the broker should retain the messages sent to
– it. Defaults to false.
–mqtt:.retain=

– Optional. True or false. Defines if messages are published asynchronously or
– synchronously. Defaults to true.
–mqtt:.async=

– Optional. Defines the last will and testament that is sent when this client goes offline
– Format: topic:message:qos:retained

–mqtt:.lwt=


my openhab test.items

Group all
Group node1 (all)
Group node2 (all)
Group sketch (all)

Switch node2_sw1 “sw2” (node2,all) {mqtt=">[mysensor:devices/admin/get:command:ON:1],>[mysensor:devices/admin/get:command:OFF:0]"}


My openhab runtime notices the switch being changed but nothing happens on the Rpi led breadboard.

Thanks so much for your help, can’t wait to figure out how this can work.

What I mean by pointing the device and openHAB to the broker is that the URL used by each needs to be the address and port of the Mosquitto server.

For example here is my configuration:

  • Mosquitto MQTT Broker installed on 192.168.1.200 at port 1883 and 8883
  • openHAB installed on 192.168.1.200 at port 8080 and 8443
  • Sensors wired to a Raspberry Pi at 192.168.1.201
  • Sensors wired to a Raspberry Pi at 192.168.1.202

#Mosquitto Config:
/etc/mosquitto/conf.d/mosquitto.conf
NOTE: These are just the fields I changed. It is not my complete conf file.

# Default Listener : used for internal traffic
port 1883

# External Listener, encrypted and exposed to Internet
listner 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/ca_certificates/server.crt
keyfile /etc/mosquitto/ca_certificates/server.key

# Security
allow_anonymous false
passwod_file /etc/mosquitto/passwords

This configuration has an unencrypted connection for client that access it via port 1883 and an encrypted connection for clients that access it via port 8883. My firewall will only forward requests from the Internet (e.g. my phone when I’m out and about) to the encrypted port. The username/passwords are created using the mosquitto_passwd command. You will have to create your own cert and key files if you want to go this route. There are lots of tutorials and I think it is documented in man mosquitto.conf.

#openHAB Config

Ignore the MQTT persistence

openhab.cfg

# MQTT Transport
# Address of the broker
mqtt:mosquitto.url=tcp://192.168.1.200:1883
mqtt:mosquitto.clientId=openhab
# previously configured on Mosquitto using mosquitto_passwd
mqtt:mosquitto.user=user
mqtt:mosquitto.pwd=password

Items

// remote sensors subscribe and publish their current state to their topics when openHAB publishes a message to this topic
String N_D_Update { mqtt=">[mosquitto:entry_sensors/getUpdate:state:*:default]" } 

// Sensors
// This sensor is hosted on 192.168.1.201
Contact N_D_Front "Front Door [MAP(en.map):%s]" <frontdoor> { mqtt="<[mosquitto:entry_sensors/main/front_door:state:default]" }

// This sensor is hosted on 192.168.1.202
Contact N_D_GarageDoor1 "Garage Door 1 [MAP(en.map):%s]"  <garagedoor> { mqtt="<[mosquitto:entry_sensors/main/garage/door1:state:default]" }

Notice that nowhere is openHAB told about where (IP addresses) the remote sensors are. It is only configured to connect to the broker.

#Python clients

I’ll not post my code as it is pretty much the same as yours so I’ll post my configs. My script basically polls Raspberry Pi GPIO pins or scans for nearby bluetooth devices and publishes changes in their state (OPEN, CLOSED) to an MQTT topic.

192.168.1.202’s configuration:

[Sensor1]
Type: GPIO
Pin: 4
Topic: entry_sensors/main/front_door
PUD: UP

[Sensor2]
Type: GPIO
Pin: 17
Topic: entry_sensors/main/back_door
PUD: UP

[Sensor3]
Type: GPIO
Pin: 21
Topic: entry_sensors/main/garage_door
PUD: UP

[Sensor4]
Type: Bluetooth
Address: F8:F1:B6:3C:4A:FA
Topic: presence_sensors/bluetooth/hydraRich

[Sensor5]
Type: Bluetooth
Address: 8C:29:37:0F:FC:85
Topic: presence_sensors/bluetooth/hydraJenn

[Logging]
File: /var/log/mqttReporter.log
MaxSize: 67108864
NumFiles: 10

[MQTT]
User = user
Password = password
Host = 192.168.1.200
Port = 1883
Keepalive = 60
Topic = entry_sensors/getUpdate
LWT-Topic = status/sensor-reporters
LWT-Msg = hydra mqttReporter is dead

Notice that the Host and Port are pointed to the Mosquitto broker, not openHAB. I also have openHAB configured to listen on the Last Will and Testament topic so I get an alert when these remote sensors go down.

192.168.1.201’s config

[Sensor1]
Type: GPIO
Pin: 7
Topic: entry_sensors/main/garage/door1
PUD: DOWN

[Sensor2]
Type: GPIO
Pin: 8
Topic: entry_sensors/main/garage/door2
PUD: DOWN

[Sensor3]
Type: Bluetooth
Address: F8:F1:B6:3C:4A:FA
Topic: presence_sensors/bluetooth/garageRich

[Sensor4]
Type: Bluetooth
Address: 8C:29:37:0F:FC:85
Topic: presence_sensors/bluetooth/garageJenn

[Logging]
File: /var/log/mqttReporter.log
MaxSize: 67108864
NumFiles: 10

[MQTT]
User = user
Password = password
Host = 192.168.1.200
Port = 1883
Keepalive = 60
Topic = entry_sensors/getUpdate
LWT-Topic = status/sensor-reporters
LWT-Msg = garage mqttReporter is dead

Same comment, the client is pointing at the Broker, not openHAB directly.

Rich thank you so much, first thing I noticed when I went to find mosquitto.conf, it was not there, the only file in that directory was README.

Edit: I found the mosquitto.conf file under the /etc/mosquitto directory, will proceed using that file now

Does this mean Mosquitto was not correctly installed?

What are your recommendations for how to uninstall how I installed it and reinstall it?

Ty so much for all your help.

Is there any specific way I should be launching, executing this mosquitto broker upon a fresh boot?

Travis

Edit: This is how I installed mosquitto initially about 2 weeks ago:
sudo apt-get install mosquitto mosquitto-clients python-mosquitto

from this page:

The sudo apt-get install mosquitto should have installed it and configured it to run as a service. You can check to see if it is running through the command service mosquitto status. It will print out a lot of info but one of the lines should read “Active: active (running) since …”.

What does the README say? Is there a mosquitto.conf in the main /etc/mosquitto folder. It has been so long I honestly don’t remember how I configured it the first time and it may have changed.

man mosquitto.conf provides a pretty good description of what all the fields are and what they mean, but I’m pretty sure I had a default config that I just edited. I’m on Ubuntu so perhaps the config process is different.

You can start and stop mosquitto using the following command:

sudo service mosquitto stop
sudo service mosquitto start
sudo service mosquitto restart

I think by default mosquitto either doesn’t generate logs or it puts its logs into the syslog. You can see these logs with the command

sudo grep /var/log/syslog mosquitto | less

If mosquitto is configured to log here you will see a new line every time a client connects. It is one way to debug the system and verify everything is talking.

Thank you so much Rich, I have installed mosquitto and set the username and password and generated the 3 key/ca files. That worked well and Mosquitto server starts up great.

I have my openhab item setup to match and that looks great too:

Switch node2_sw1 “sw2” (node2,all) {mqtt=">[mosquitto:devices/phaze3131/get:command:ON:1],>[mosquitto:devices/phaze3131/get:command:OFF:0]"}

I change my python code to match all the correct username/passwords/clientid.
Changed this:
client.connect(“10.10.10.103:1883”)

So that points to the Mosquitto server Rpi (which also has openhab running)

But when I run my code I am now getting these errors, I’m hoping you could maybe shed some light as to why they are coming up and if the python code is even being executed. I’m aware the gpio errors don’t mean much but it’s the errors at the end that concern me.

pi@raspberrypi ~ $ sudo python mqttlight.py
mqttlight.py:23: RuntimeWarning: No channels have been set up yet - nothing to clean up! Try cleaning up at the end of your program instead!
GPIO.cleanup() # clean up resources
mqttlight.py:24: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(ledPin, GPIO.OUT) # led pin setup
Traceback (most recent call last):
File “mqttlight.py”, line 78, in
client.connect(“10.10.10.103:1883”) # MQTT server address
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 612, in connect
return self.reconnect()
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 734, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File “/usr/lib/python2.7/socket.py”, line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known


I’m going to post my python code just in case:


import paho.mqtt.client as paho
import RPi.GPIO as GPIO
import json, time

& device credentials
device_id = ‘phaze3131>’ & * set your device id (will be the MQTT client username)
device_secret = ‘********’ & * set your device secret (will be the MQTT client password)
random_client_id = ‘openhab’ & * set a random client_id (max 23 char)

& -------------- &
& Board settings &
& -------------- &
buttonPin = 7
ledPin = 12

GPIO.setmode(GPIO.BOARD) & use P1 header pin numbering convention
GPIO.cleanup() & clean up resources
GPIO.setup(ledPin, GPIO.OUT) & led pin setup
GPIO.setup(buttonPin, GPIO.IN) & button pin setup

& --------------- &
& Callback events &
& --------------- &

& connection event
def on_connect(client, data, flags, rc):
print('Connected, rc: ’ + str(rc))

& subscription event
def on_subscribe(client, userdata, mid, gqos):
print('Subscribed: ’ + str(mid))

& received message event
def on_message(client, obj, msg):
& get the JSON message
json_data = msg.payload
& check the status property value
print(json_data)
value = json.loads(json_data)[‘properties’][0][‘value’]
if value == ‘on’:
led_status = GPIO.HIGH
GPIO.output(ledPin, GPIO.HIGH)
else:
led_status = GPIO.LOW
GPIO.output(ledPin, GPIO.LOW)

& confirm changes to Leylan
client.publish(out_topic, json_data)

& ------------- &
& MQTT settings &
& ------------- &

& create the MQTT client
client = paho.Client(client_id=random_client_id, protocol=paho.MQTTv31) & * set a random string (max 23 chars)

& assign event callbacks
client.on_message = on_message
client.on_connect = on_connect
client.on_subscribe = on_subscribe

& device topics
in_topic = ‘devices/’ + device_id + ‘/get’ & receiving messages
out_topic = ‘devices/’ + device_id + ‘/set’ & publishing messages

& client connection
client.username_pw_set(device_id, device_secret) & MQTT server credentials
client.connect(“10.10.10.103:1883”) & MQTT server address
client.subscribe(in_topic, 0) & MQTT subscribtion (with QoS level 0)

& ------------ &
& Button logic &
& ------------ &

prev_status = GPIO.LOW
led_status = GPIO.LOW
updated_at = 0 & the last time the output pin was toggled
debounce = 0.2 & the debounce time, increase if the output flickers

& Continue the network loop, exit when an error occurs
rc = 0
while rc == 0:
rc = client.loop()
button = GPIO.input(buttonPin)

if button != prev_status and time.time() - updated_at > debounce:
    prev_status = button
    updated_at  = time.time()

    if button:
        led_status = not led_status
        button_payload = 'off'
        if led_status == GPIO.HIGH:
            button_payload = 'on'
        & effectively update the light status
        GPIO.output(ledPin, led_status)
        payload = { 'properties': [{ 'id': '518be5a700045e1521000001', 'value': button_payload }] }
        client.publish(out_topic, json.dumps(payload))

print('rc: ’ + str(rc))


Thanks so much for all your help Rich, this is really starting to make sense to me.

Travis

Well the MQTT client code isn’t working for some reason.

Your thread prompted me to update my code to pull the various parts into separate files for easier maintenance.

I don’t have time to compare your code with mine right now to see what is different but I can post it here and you can maybe figure out what is wrong from a working example.

You can find all of this script here. Feel free to reuse this if it helps.

mqttConn.py

"""
 Script: mqttConn.py
 Author: Rich Koshak
 Date:   October 22, 2015
 Purpose: Provides and maintains a connection to the MQTT broker
"""

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import sys
import paho.mqtt.client as mqtt

class mqttConnection(object):
    """Centralizes the MQTT logic"""

    def config(self, logger, user, password, host, prt, ka, lwtTopic, lwtMsg, topic, msgProc):
        """Creates and connects the client"""

        self.logger = logger
        self.msgProc = msgProc # function that gets called when a message is received
        self.topic = topic

        self.client = mqtt.Client()
        self.client.on_connect = self.on_connect
        self.client.on_message = self.msgProc
        self.client.on_disconnect = self.on_disconnect
        self.client.username_pw_set(user, password)
        self.client.will_set(lwtTopic, lwtMsg, 0, False)
        self.client.connect(host, port=prt, keepalive=ka)
        self.client.loop_start()

    def publish(self, message, pubTopic):
        """Called by others to publish a message to the publish topic"""

        try:
            rval = self.client.publish(pubTopic, message)
            if rval[0] == mqtt.MQTT_ERR_NO_CONN:
                self.logger.error("Error publishing update: " + message +  " to " + pubTopic)
                self.comms.reconnect() # try to reconnect again
            else:
                self.logger.info("Published message " + message + " to " + pubTopic)
        except:
            print "Unexpected error publishing message:", sys.exc_info()[0]

    def on_connect(self, client, userdata, flags, rc):
        """Called when the MQQT client successfully connects to the broker"""

        self.logger.info("Connected with result code "+str(rc)+", subscribing to command topic " + self.topic)

        # Subscribing in on_connect() means that if we lose the connection and
        # reconnect then subscriptions will be renewed
        self.client.subscribe(self.topic)

        self.msgProc(None, None, None)

    def on_disconnect(self, client, userdata, rc):
        """Called when the MQTT client disconnects from the broker"""

        self.logger.info("Disconnected from the MQTT broker with code " + str(rc))

        if rc != 0:
            self.logger.info("Unexpected disconnect: code = " + str(rc) + " reconnecting")

Hey Rich,

About my mqtt client python code, I decided to abandon it and I googled around and found a much simpler one here that I will use once I fix my mosquitto broker problems.

The problem with mosquitto:

I realized that my mosquitto broker was having problems, I would run a stop command but get this error:
[…] Stopping network daemon:: mosquittostart-stop-daemon: warning: failed to kill 2824: No such process
. ok

I also had another problem with doing an update:
When I ran sudo apt-get update I was getting this error:
E: Type ‘<?xml’ is not known on line 1 in source list /etc/apt/sources.list.d/mosquitto-repo.list

I installed Mosqitto from these directions:

I decided I need to figure out what is wrong with my mosquitto server and find a new way to install it. I posted on the Rpi forums and Dougie said this:
If I were you I’d build Mosquitto 1.4.4 (MQTT v3.1.1 & websockets) from source code.


Here is the link to the thread if you are curious:
https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=124427&p=835155#p835155

I’m very unsure about what he means and I will ask him if there is a site that has instructions on how to build mosquitto 1.4.4 from source code.

But I’m wondering if you can maybe shed some light and tell me your thoughts, Thanks so much Rich!

Hmmmm.

Before I spent a lot of time compiling Mosquitto from source or doing a lot of other things I would look into that apt-get error. That could be indicative of something much worse than Mosquitto failing going on.

You shouldn’t have to build from source. Plenty of people are running Mosquitto on Raspberry Pis through the apt-get.

That being said, you can fix the apt-get update error pretty easily. Replace the contents of

/etc/apt/sources.list

with

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

There should be nothing else in it.

Then run apt-get update and upgrade again. It should work this time.

Then once everything is updated and running look in the syslog for mosquitto log statements that will hopefully show why it crashed, if it continues to crash.

I would build from source only as a last resort. It can be tricky and then you are cut off from the automatic updates for good.

I’m curious and a little worried about how that garbage ended up in your source.list

Hello everyone. I hope somebody here can help me, I can’t find the answer myself and seem to be out of options.

I have a arduino with DHT22 and a BMP085 barometer sensor, ethernetshield attached. My Raspberry is installed as openhab server (debian), Mosquitto etc. seem to work: MQTT.fx shows the data from my DTH22 sensor and the barometer. Very cool, my messages are coming in on the RasPi. Openhab runs fine; I can piss my sons of with switching off the LG tv etc. However: I am unable to display the arduino sensor data with Openhab.

Settings Openhab:

openhab.cfg:
mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openhab

Item created in default.items:
Number studeerkamer_Temp “Temperatuur [%.1f °C]” (GF_Living) { mqtt=”<[broker:openhab/studeerkamer/temperatuur:state:default]" }
Number studeerkamer_Vocht “Luchtvochtigheid [%.1f %%]” (GF_Living) { mqtt=”<[broker:openhab/studeerkamer/vochtigheid:state:default]" }
Number studeerkamer_Luchtdruk “Luchtdruk [%.1f HPa]” (GF_Living) { mqtt=”<[broker:openhab/studeerkamer/luchtdruk:state:default]" }

I create a frame label in the default sitemap:

Frame label=“arduino” {
text item=studeerkamer_Temp
text item=studeerkamer_Vocht
text item=studeerkamer_Luchtdruk
}

and thats where things go wrong: everything UNDER this label is not showing; I just see arduino" and nothing below. When I move the frame to the bottom everything shows, except my sensor data. So the “arduino” frame blocks everything underneath and the mqtt bindings dont work.

When I look in /var/log/openhab/events.log I can see the data coming in:

2015-11-20 18:00:30 - studeerkamer_Temp state updated to 18
2015-11-20 18:00:30 - studeerkamer_Vocht state updated to 53
2015-11-20 18:00:30 - studeerkamer_Luchtdruk state updated to 1000

Anyone? I have spend too many hours searching now…

As numbers are coming in I guess there is an error in your sitemap. As you have posted only a fragment it is not possible to say much more. When adding to a huge sitemap it is easy to make errors. So try a simple sitemap like this or similar, it might do the job (without any bells an whistles) and be a good starting point.

sitemap xxx label=“Labelxxx”
{
Frame label=“Arduino”
{
text item=studeerkamer_Temp
text item=studeerkamer_Vocht
text item=studeerkamer_Luchtdruk
}
}

Thank you @mebj !

I solved the problem. Openhab is appearently case sensitive; I had to change the lowercase “t” in text ti uppercase “T” and everything worked!

So my Text items look like this now:

sitemap xxx label=“Labelxxx”
{
Frame label=“Arduino”
{
Text item=studeerkamer_Temp
Text item=studeerkamer_Vocht
Text item=studeerkamer_Luchtdruk
}
}

Old thread, but just a helpful hint… I use notepad++ for usual editing but if I have an issue to troubleshoot I always open in openhab designer, tends to highlight config errors well - way better than my eye can pickup!

1 Like