Giter Club home page Giter Club logo

arduino-homebridge-mqtt's Introduction

Arduino Homebridge MQTT

Build Status

Arduino library for connecting to Homebridge.

Dependancies:

Installation Guide

Usage

// Switch example
#include <Arduino.h>
#include <WiFiManager.h> // You can you anything else to connect to WiFi.
#include <ArduinoHomebridgeMqtt.h>        

const IPAddress MQTT_SERVER = IPAddress(192, 168, 1, 48); // Put your MQTT server IP address here.
const int OUTPUT_PIN = D1;
const char* NAME = "flex_lamp"; // Accessory name must be unique
const char* SERVICE_NAME = "Light"; // Service name. 
const char* SERVICE = "Switch"; // Service as defined in Homebridge

WiFiManager wifiManager;
ArduinoHomebridgeMqtt arduinoHomebridgeMqtt;

// This function gets called when there is a message from homebridge eg. when value(s) is set via Home app.
void callback(const char* name, const char* serviceName, const char* characteristic, int value) {
  if (strcmp(name, NAME) == 0) { // Check to see if the message is for this accessory.
    if (strcmp(serviceName, SERVICE_NAME) == 0) { // Check if the message is to set the value for service "Light".
      digitalWrite(OUTPUT_PIN, value);
    }
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(OUTPUT_PIN, OUTPUT);
  wifiManager.autoConnect();
  arduinoHomebridgeMqtt.onSetValueFromHomebridge(callback);
  arduinoHomebridgeMqtt.connect(MQTT_SERVER);
  arduinoHomebridgeMqtt.addAccessory(NAME, SERVICE_NAME, SERVICE); // If running the first time, you need to add the accessory first.
  arduinoHomebridgeMqtt.getAccessory(NAME); // Get accessory states
}

void loop() {
  arduinoHomebridgeMqtt.loop();
}

arduino-homebridge-mqtt's People

Contributors

andylee830914 avatar micampe avatar per1234 avatar waritsan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

arduino-homebridge-mqtt's Issues

getAccessories false, name undefined

Hi,
I installed the library and setup an mqtt broker with mosca. I modified the 'SwitchExample' example to work on an esp8266 and tried to make it just turn on and off the builtin led over homebridge. The esp connects to the network and shows up in my router and mosca command line. Homebridge communicates to mosca just fine and everything I configure shows up in the homekit app. For some reason though, the esp does not really talk well to homebridge. Every time I reset the esp (it almost instantly shows up in mosca readout) the homebridge status spits out a 'getAccessories false, name '7893338' undefined. [0]'. I have tried and tried and I can't find any mention of names in the arduino code other than the service name (which I am guessing is for it to get the proper responses from homebridge). Can somebody please help me with this? I have been struggling with this for the past three days :(

Here's my esp code
`#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "ArduinoHomebridgeMqtt.h"

const IPAddress MQTT_SERVER = IPAddress(192, 168, 8, 109);
const int OUTPUT_PIN = LED_BUILTIN;
const char* SERVICE_NAME = "light";
const char* SERVICE = "Switch";

const char* ssid = "Hardi";
const char* password = "8J9Y0B33378";

ArduinoHomebridgeMqtt arduinoHomebridgeMqtt;

void callback(const char* serviceName, const char* characteristic, int value) {
if (strcmp(serviceName, SERVICE_NAME) == 0) {
digitalWrite(OUTPUT_PIN, value);
}
}

void setup() {
Serial.begin(9600);
pinMode(OUTPUT_PIN, OUTPUT);
WiFi.begin(ssid, password);
arduinoHomebridgeMqtt.onSetValueFromHomebridge(callback);
arduinoHomebridgeMqtt.connect(MQTT_SERVER);
arduinoHomebridgeMqtt.getAccessory();
}

void loop() {
arduinoHomebridgeMqtt.loop();
}`

Thanks to anyone who tackles this

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.