在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Supereg/homebridge-http-notification-server开源软件地址:https://github.com/Supereg/homebridge-http-notification-server开源编程语言:JavaScript 100.0%开源软件介绍:homebridge-http-notification-server
The problem with such accessories is when the state of the external program changes it cannot be directly reflected in HomeKit. So one solution would be that every http accessory packs its own http server to receive state changes. But with multiple switches this becomes a mess very fast. This is where the Installation
ConfigurationThe configuration file is located in the homebridge directory and needs to be called Example: {
"hostname": "127.0.0.1",
"port": 8080,
"ssl": {
"privateKey": "/path/to/private-key.prm",
"certificate": "/path/to/certificate.cert"
}
}
How to implement 'homebridge-http-notification-server' into your projectImplementation in the homebridge accessory (receiver)First of all you need to specify a handler function in your homebridge accessory. In order to be sure, that
Example http accessory: let api;
module.exports = function (homebridgeAPI) {
api = homebridgeAPI;
homebridgeAPI.registerAccessory("homebridge-http-example-accessory", "HTTP-ACCESSORY", HTTP_ACCESSORY);
};
function HTTP_ACCESSORY(log, config) {
// Some initialization
this.name = config.name;
this.service = new Service.Switch(this.name);
this.service.getCharacteristic(Characteristic.On)
.on("get", this.getStatus.bind(this))
.on("set", this.setStatus.bind(this));
api.on('didFinishLaunching', function() {
// check if notificationRegistration is set, if not 'notificationRegistration' is probably not installed on the system
if (global.notificationRegistration && typeof global.notificationRegistration === "function") {
try {
global.notificationRegistration("accessory-identifier", this.handleNotification.bind(this), "top-secret-password");
} catch (error) {
// notificationID is already taken
}
}
}.bind(this));
}
HTTP_ACCESSORY.prototype = {
identify: function (callback) {
this.log("Identify requested!");
callback();
},
getServices: function () {
return [this.service];
},
handleNotification: function (jsonRequest) {
const service = jsonRequest.service; // value is optional and only relevant if your accessory exposes multiple services
const characteristic = jsonRequest.characteristic;
const value = jsonRequest.value;
// #testCharacteristic returns true if the service was added the specified characteristic.
// you could ad additional checks to adjust for your needs
const validCharacteristic = this.service.testCharacteristic(characteristic);
if (!validCharacteristic) {
this.log("Encountered unknown characteristic when handling notification: " + characteristic);
return; // in this example we ignore invalid requests
}
this.service.updateCharacteristic(characteristic, value);
},
getStatus: function(callback) {
// request
},
setStatus: function(on, callback) {
// request
}
}; Implementation in the http application (sender)The http application sends a request to the notification-server (inside of homebridge) to update a value of a HomeKit
characteristic. The http request must be a
In our example the url would look like the following:
The POST body would look like the following: {
"characteristic": "On",
"value": true,
"password": "your-top-secret-password",
"accessory": "example-accessory", // optional, plugin defined
"service": "switch-service", // optional, plugin defined
} Common properties:
Plugin defined properties:
Some compatible http accessories
Notify me if you want to see your project here. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论