在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:waritsan/arduino-homebridge-mqtt开源软件地址:https://github.com/waritsan/arduino-homebridge-mqtt开源编程语言:C++ 100.0%开源软件介绍:Arduino Homebridge MQTTArduino library for connecting to Homebridge. Dependancies:Installation GuideUsage// 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();
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论