Getting MySensors MQTT Gateway working on OpenHAB 2.2 (Stable)



  • Here are step by step instructions for taking a vanilla OpenHabian 2.2 and adding MQTT Gateway and MySensors to it. This may change, but at the date of this post and with the versions / snapshots below, this currently works:

    Pre-requisites / configuation:

    GatewayW1500MQTTClient I have setup as follows:


    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_MIN // ONLY FOR nrf24L01+ Enhanced, it reduces the output of the nrf24L01 otherwise rfaxis power amp overloads and starts corrupting messages
    #define MY_RF24_CHANNEL (109) // 0-126: Note specifying a channel >= 108 clears most of the wifi interference.

    // Security (Signing)
    #define MY_SIGNING_SOFT
    //For the software backed signing backend, an unconnected analog pin is required on boards that does not provide a hardware based random generator unit to set a
    //random seed for the pseudo-random generator. It is important that the pin is floating, or the output of the pseudo-random generator will be predictable, and thus compromise the signatures.
    #define MY_SIGNING_SOFT_RANDOMSEED_PIN A12
    #define MY_SIGNING_REQUEST_SIGNATURES

    #define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
    #define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN 9 // the PCB, on board L

    #define MY_GATEWAY_MQTT_CLIENT

    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4

    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN A0
    #define MY_SOFT_SPI_MISO_PIN A2
    #define MY_SOFT_SPI_MOSI_PIN A1
    #endif

    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif

    #define MY_MAC_ADDRESS 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX <--- CHANGE TO YOUR MAC ADDRESS

    // Static ip setup, otherwise if not defined, dhcp is used
    //#define MY_IP_ADDRESS 192,168,178,87
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1

    // MQTT broker ip address or url. Define one or the other.
    //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, XXX, XXX <--- SET THIS TO THE ADDRESS OF YOUR RASPBERRY PI

    // The MQTT broker port to to open
    #define MY_PORT 1883

    // Enable these if your MQTT broker requires usenrame/password
    #define MY_MQTT_USER "openhabian" <--- MUST MATCH THE USERNAME FOR MOSQUITTO ON THE PI
    #define MY_MQTT_PASSWORD "XXXXX" <--- SET THIS TO YOUR A PASSWORD - MUST MATCH THE ONE FOR MOSQUITTO ON THE PI"

    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"

    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"


    Steps:

    1. Boot Raspberry pi from SD Card connected to ethernet (if you have any wifi connectivity problems, parts of the installation fail, and you get an incomplete install, that doesn't necessarily fail to complete, hence use ethernet till built)

    2. After about 2-3 mins, connect to the Pi with: ssh openhabian@IP_ADDRESS (password: openhabian) and you will see the install in progress

    3. Watch until installation has finished (approx 25mins depending on connection speed), the last entry will be "First time setup successfully finished". There should be no errors (except: sed: -e expression #1, char 5: unterminated address regex), if you're getting other errors, retry it (you need to make up the SD Card with the image again), if errors are randomly happening, suspect the SD Card.

    4. Ctrl-C and type sudo reboot

    5. Verify Installation: After about 5 mins you should be able to connect to: http://IP_ADDRESS:8080, select Standard Setup and wait until PaperUI and HABPanel have appeared
      Also: http://IP_ADDRESS:9001 should show no errors

    6. ssh openhabian@IP_ADDRESS
      sudo openhabian-config
      Change openhab-cli password:

      System Settings / Change Passwords / openHAB Console: and set to something, we'll need this when logging into openhab-cli, we'll call this password_openhab-cli

      Add Mosquitto:

      Optional Components / Mosquitto, set password to something (we'll call this password_mosquitto), needs to match the one in your MySensors gateway and the one in the next step.

      Exit

    7. Configuring MQTT:
      IMPORTANT: DO NOT INSTALL THE MQTT BINDING IN THE PAPER UI, IT CONFLICTS WITH MYSENSORS

    cd /srv/openhab2-conf/services
    nano org.eclipse.smarthome.mqtt.cfg   (or use your favorite editor)
    

    add:

    mosquitto.url=tcp://localhost:1883	
    mosquitto.user=openhabian
    mosquitto.pwd=YOUR_PASSWORD_GOES_HERE   (This is password_mosquitto referenced previously)
    mosquitto.qos=1
    mosquitto.retain=true
    mosquitto.async=false
    (NOTE: We don't add clientId here, it causes problems and prevents both OpenHab and MySensors connecting due to multiple id's (persistance in use errors).  Allowing the id's to be auto and uniquely assigned, will prevent this clash)
    

    save the file and exit

    nano mqtt-eventbus.cfg
    

    Add:

    broker=mosquitto
    

    save the file and exit

    sudo chown openhab:openhabian org.eclipse.smarthome.mqtt.cfg mqtt-eventbus.cfg

    Remove the backup files:

    cd /var/lib/openhab2/config/org/openhab
    rm mqtt-eventbus.config
    cd ../eclipse/smarthome
    rm mqtt.config
    
    sudo reboot
    

    Power cycle or switch on your already configured MySensors MQTT Gateway

    1. ssh openhabian@IP_ADDRESS
      After a few minutes, visit: http://IP_ADDRESS:9001
      You should have no errors.

    2. Installing MySensors:
      openhab-cli console
      (if password prompt doesn’t appear after a while, ctrl-c and try again, it can take a while or timeout the first few times after installation, this is password_openhab-cli)

    feature:install openhab-transport-serial
    feature:install esh-io-transport-mqtt
    CTRL-D
    cd /srv/openhab2-addons
    wget http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.3.0-SNAPSHOT.jar
    sudo chown openhab:openhabian org.openhab.binding.mysensors-2.3.0-SNAPSHOT.jar
    openhab-cli console
    
    Check the features and services we need are active:
    
    feature:list | grep openhab-transport-serial	(Should say Started)
    feature:list | grep esh-io-transport-mqtt	(Should say Started)
    bundle:list | grep MySensors			(Should say Active)
    bundle:list | grep nrjavaserial			(Should say Active)
    
    CTRL-D
    sudo reboot
    
    1. ssh openhabian@IP_ADDRESS
      After a few minutes, visit: http://IP_ADDRESS:9001
      You should have no errors.

    Check mosquitto is running and gateway is connected:

    cd /var/log/mosquitto
    tail -f mosquitto.log
       526088756: mosquitto version 1.4.10 (build date Fri, 22 Dec 2017 08:19:25 +0000) starting
       1526088756: Config loaded from /etc/mosquitto/mosquitto.conf.
       1526088756: Opening ipv4 listen socket on port 1883.
       1526088756: Opening ipv6 listen socket on port 1883.
       1526088764: New connection from 192.168.20.143 on port 1883.
       1526088764: New client connected from 192.168.20.143 as mysensors-1 (c1, k15, u'openhabian'). <-- This is the MySensors MQTT Gateway connecting)
       1526088783: New connection from 127.0.0.1 on port 1883.						<-- This is the MQTT Service on the Raspberry Pi Connecting
       (If you're not seeing the above, power cycle the MySensors MQTT Gateway)
    CTRL-C
    
    1. Adding MySensors Binding in PaperUI:
      Visit: http://IP_ADDRESS:8080 and click on PaperUI
    Choose Inbox / + / MySensors Binding / MySensors MQTT Gateway
       Enable: "Enabled the startup check"
       Enable: "Enabled network sanity check"
       (all other settings remain at the default, but you might want to change Imperial/Metric for your preference)
       Click the "Blue" Checkmark at the top to save.
    
    Choose Configuration / Things (you may have to reload the page)
       MySensors MQTT Gateway should be ONLINE, if not, check your Gateway is configured correctly.
    
    sudo reboot
    
    1. After a few minutes, visit: http://IP_ADDRESS:9001
      You should have no errors.
      Visit: http://IP_ADDRESS:8080 and click on PaperUI
      Visit Configuration / Things, MySensors MQTT Gateway should still be ONLINE

      ssh openhabian@IP_ADDRESS

      Check mosquitto is running and gateway is connected:
      cd /var/log/mosquitto
      tail mosquitto.log

      It should look like this:

    1526089285: mosquitto version 1.4.10 (build date Fri, 22 Dec 2017 08:19:25 +0000) starting
    1526089285: Config loaded from /etc/mosquitto/mosquitto.conf.
    1526089285: Opening ipv4 listen socket on port 1883.
    1526089285: Opening ipv6 listen socket on port 1883.
    1526089294: New connection from 192.168.20.143 on port 1883.
    1526089294: New client connected from 192.168.20.143 as mysensors-1 (c1, k15, u'openhabian').
    1526089312: New connection from 127.0.0.1 on port 1883.
    

    CONGRATULATIONS, gateway and mysensors are now setup

    1. Now you want to add some mysensors things into PaperUI. Easiest way is to power cycle the sensor, this should result in the sensor appear in the Inbox in PaperUI. For example, I built an RGB Light, when I power cycle it, I see in the Inbox:
      MySensors Device (1;1) RGB Light Sensor: mysensors:rgbLight:a6e1bcda:rgblight_1_1

      Click on the Blue checkmark, and click "Add As Thing"
      Go to Configuration / Things, and you should see the MySensors Device(1;1) show up
      Click the bolded title of the sensor (MySensors Device (1;1) and check the blue circles you want to see the data for one by one. Each one pops up a "Link Channel" message, change item to "Create new item" and select "Link"

      That newly added item will now show up in Configuration / Items and also in "Control" so you can change it's status

    2. If you're new to this, checkout HABPanel, use PaperUI to setup items, but HABPanel to present a UI for use.


Log in to reply
 

357
Online

7.4k
Users

8.2k
Topics

88.9k
Posts

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.