Skip to content

Instantly share code, notes, and snippets.

@mirhec
Created October 2, 2017 14:40
Show Gist options
  • Select an option

  • Save mirhec/27e8df1b2ff52196fabb0f9ea5f4313f to your computer and use it in GitHub Desktop.

Select an option

Save mirhec/27e8df1b2ff52196fabb0f9ea5f4313f to your computer and use it in GitHub Desktop.

Revisions

  1. mirhec created this gist Oct 2, 2017.
    37 changes: 37 additions & 0 deletions setup-mosquitto-raspi.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # Install Mosquitto on Raspberry Pi with OpenHAB

    Install a raspberry pi with the latest OpenHABian version.

    ## Install Mosquitto

    wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
    sudo apt-key add mosquitto-repo.gpg.key
    rm mosquitto-repo.gpg.key
    cd /etc/apt/sources.list.d/
    sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
    sudo apt-get update
    sudo apt-get install mosquitto mosquitto-clients

    Edit the mosquitto config file at `/etc/mosquitto/mosquitto.conf` and add the following line:

    listener 1883

    Now restart the service with `sudo /etc/init.d/mosquitto restart`.

    ## Test Mosquitto
    mosquitto_sub -d -t hello/world

    Connect to another ssh session and run

    mosquitto_pub -d -t hello/world -m "Hello from terminal window 2!"

    ## Configure OpenHAB
    Now install Mosquitto binding and enter `binding-mqtt1` in the `binding` list in the `addons.cfg` file.
    Create a new file `services/mqtt.cfg` and enter the following content:

    mosquitto.url=tcp://localhost:1883
    mosquitto.clientId=OpenHAB2
    mosquitto.user=<user>
    mosquitto.pwd=<password>

    Then restart openhab with `sudo /etc/init.d/openhab2 restart`.