Skip to content

A Journey in to MQTT With Roller Shutters, Mosquitto, HomeAssistant & Low Powered Micro-Controllers

A Journey in to MQTT With Roller Shutters, Mosquitto, HomeAssistant & Low Powered Micro-Controllers

gemma

Published January 02, 2023

Original author: Shane Baldacchino · ItalyOriginal source (new tab)

A Journey in to MQTT With Roller Shutters, Mosquitto, HomeAssistant & Low Powered Micro-Controllers

Components

Hardware components

Project description

The Arduino needs to know what to do. I thought about explaining this but I think for those techincally inclined the code speaks volume below but in essence we are

  1. Establishing an IP connection
  2. Connecting to the MQTT Broker, Mosquitto
  3. Subscribing to topics
  4. Listening for MQTT messages
  5. Taking action on received messages
  6. Publishing updates to MQTT broker on state change

 

// INCLUDE SYSTEM LIBRARIES 
 #include <util.h>
    #include <Ethernet2.h>
    #include <SPI.h>
    #include <PubSubClient.h>
    
    //Setup Ethernet Controller
    byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0XD0, 0x66 };
    byte gateway[] = { 10, 0, 0, 1 }; 
    byte subnet[] = { 255, 255, 255, 0 }; 
    IPAddress ip(10, 0, 0, 50 );

    // Initialize the Ethernet server library
    // with the IP address and port you want to use
    // (port 80 is defaudlt for HTTP):
    EthernetServer server(80);

Comments

Comments