• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

waritsan/arduino-homebridge-mqtt: Arduino library for connecting to Homebridge

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

waritsan/arduino-homebridge-mqtt

开源软件地址:

https://github.com/waritsan/arduino-homebridge-mqtt

开源编程语言:

C++ 100.0%

开源软件介绍:

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();
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
GiniaE/homebridge-gpio-ledstrip: RPi GPIO based LED Strip plugin for Homebridge发布时间:2022-06-14
下一篇:
Homebrew/homebrew-cask-versions: 发布时间:2022-06-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap