Giter VIP home page Giter VIP logo

raspberryespmqtt's Introduction

RaspberryESPMqtt

All steps to install a working Moquitto broker on RaspberryPi

Install Raspbian, enable wifi and ssh

diskutil list
  • find sd card disk#
diskutil unmountDisk /dev/disk#
sudo dd bs=1m if=image.img of=/dev/rdisk#
cp ./wpa_supplicant.conf /Volumes/boot/wpa_supplicant.conf
touch /Volumes/boot/ssh
diskutil unmountDisk /dev/disk#
ssh [email protected] 
raspberry

Install NodeJS

cd ~
wget https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux-armv6l.tar.xz
tar -xf node-v10.15.1-linux-armv6l.tar.xz
rm -rf node-v10.15.1-linux-armv6l.tar.xz
cd node-v10.15.1-linux-armv6l
sudo cp -R * /usr/local/
cd /usr/bin
sudo ln -s /usr/local/bin/node node
cd ~
rm -rf ./node-v10.15.1-linux-armv6l
node -v

Add Mosquitto user

sudo adduser mosquitto
sudo adduser mosquitto sudo
exit
ssh [email protected] 
raspberry

Install Mosquitto

sudo apt-get install mosquitto mosquitto-clients

if you have errors

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-stretch.list
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

then add configurations

sudo nano /etc/mosquitto/conf.d/mosquitto.conf

# Config file for mosquitto
#
# See mosquitto.conf(5) for more information.
user mosquitto
max_queued_messages 200
message_size_limit 0
allow_zero_length_clientid true
allow_duplicate_messages false
listener 1883
autosave_interval 900
autosave_on_changes false
persistence true
persistence_file mosquitto.db
allow_anonymous true
password_file /etc/mosquitto/passwd
require_certificate false
# End Config file

sudo mosquitto_passwd -c /etc/mosquitto/passwd pi
sudo systemctl restart mosquitto
sudo systemctl status mosquitto
sudo journalctl -fu mosquitto

Install Homebridge

Add homebridge user

sudo adduser homebridge
sudo adduser homebridge sudo
exit
ssh [email protected] 
raspberry

Homebridge

sudo apt-get install libavahi-compat-libdnssd-dev
sudo npm install -g --unsafe-perm homebridge

Plugin

sudo npm install -g homebridge-mqtt-switch-tasmota

sudo nano /home/homebridge/.homebridge/config.json
{
  "bridge": {
    "name": "Homebridge",
    "username": "B1:7C:B0:C6:69:9A",
    "port": 51826,
    "pin": "918-19-408"
  },
  "description": "SmartHome with Homebridge",
  "platforms": [],
  "accessories": [
    {
      "accessory": "mqtt-switch-tasmota",
      "switchType": "outlet",
      "name": "Stereo mansarda",
      "url": "mqtt://192.168.1.9",
      "username": "homebridge",
      "password": "raspberry",
      "topics": {
        "statusGet": "Home/sonoff_stereo/stat/POWER",
        "statusSet": "Home/sonoff_stereo/cmnd/POWER",
        "stateGet": "Home/sonoff_stereo/tele/STATE"
      },
      "onValue": "ON",
      "offValue": "OFF",
      "activityTopic": "Home/sonoff_stereo/tele/LWT",
      "activityParameter": "Online",
      "startCmd": "Home/sonoff_stereo/cmnd/TelePeriod",
      "startParameter": "60",
      "manufacturer": "ITEAD",
      "model": "Sonoff",
      "serialNumberMAC": ""
    }
  ]
}

Autostart with systemd

which homebridge
sudo nano /etc/default/homebridge

# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/homebridge

# If you uncomment the following line, homebridge will log more 
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*

sudo nano /etc/systemd/system/homebridge.service
[Unit]
Description=Node.js HomeKit Server 
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

sudo mkdir /var/homebridge
sudo cp ~/.homebridge/config.json /var/homebridge/
sudo cp -r ~/.homebridge/persist /var/homebridge
sudo chmod -R 0777 /var/homebridge
sudo systemctl daemon-reload
sudo systemctl enable homebridge

raspberryespmqtt's People

Contributors

gabibbocode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.