Giter VIP home page Giter VIP logo

Comments (6)

KhaosT avatar KhaosT commented on May 29, 2024

@dermarder Please remove all ._ files under ./accessories/

from hap-nodejs.

connyg avatar connyg commented on May 29, 2024

Looks like a syntax error, could you attach the complete .js file?

from hap-nodejs.

dermarder avatar dermarder commented on May 29, 2024

There are no ._ files. There are only the Light_accessory.js and types.js files.
It worked after i installed everything, then i tried to pair the light with the iOS app and everything worked as it should.
After restarting the HomeKit server the error appeared.
Thanks for your help

Content of the Light_accessory.js:

// HomeKit types required
var types = require("./types.js")
var exports = module.exports = {};

var execute = function(accessory,characteristic,value){ console.log("executed accessory: " + accessory + ", and characteristic: " + characteristic + ", with value: " + value + "."); }

exports.accessory = {
displayName: "Light 1",
username: "1A:2B:3C:4D:5E:FF",
pincode: "031-45-154",
services: [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Light 1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.MANUFACTURER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Oltica",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.MODEL_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Rev-1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "A1S2NASF88EW",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.IDENTIFY_CTYPE,
onUpdate: null,
perms: ["pw"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Identify Accessory",
designedMaxLength: 1
}]
},{
sType: types.LIGHTBULB_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Light 1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.POWER_STATE_CTYPE,
onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "light service", value); },
perms: ["pw","pr","ev"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Turn On the Light",
designedMaxLength: 1
},{
cType: types.HUE_CTYPE,
onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Hue", value); },
perms: ["pw","pr","ev"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Adjust Hue of Light",
designedMinValue: 0,
designedMaxValue: 360,
designedMinStep: 1,
unit: "arcdegrees"
},{
cType: types.BRIGHTNESS_CTYPE,
onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Brightness", value); },
perms: ["pw","pr","ev"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Adjust Brightness of Light",
designedMinValue: 0,
designedMaxValue: 100,
designedMinStep: 1,
unit: "%"
},{
cType: types.SATURATION_CTYPE,
onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Saturation", value); },
perms: ["pw","pr","ev"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Adjust Saturation of Light",
designedMinValue: 0,
designedMaxValue: 100,
designedMinStep: 1,
unit: "%"
}]
}]
}

from hap-nodejs.

dermarder avatar dermarder commented on May 29, 2024

This is the content of the Core.js:

var storage = require('node-persist');

var accessory_Factor = new require("./Accessory.js");
var accessoryController_Factor = new require("./AccessoryController.js");
var service_Factor = new require("./Service.js");
var characteristic_Factor = new require("./Characteristic.js");

var targetPort = 51826;

// Get the accessories data
var fs = require('fs');
var path = require('path');

var accessoriesJSON = []

// Get user defined accessories from the accessories folder
// - user defined accessory filenames must end with "accessory.js"
fs.readdirSync(path.join(__dirname, "accessories")).forEach(function(file) {
if (file.split('
').pop()==="accessory.js") {
accessoriesJSON.push(require("./accessories/" + file).accessory);
};
});

console.log("HAP-NodeJS starting...");
storage.initSync();

var accessories = [];
var accessoryControllers = [];

//loop through accessories
for (var i = 0; i < accessoriesJSON.length; i++) {
var accessoryController = new accessoryController_Factor.AccessoryController();

//loop through services
for (var j = 0; j < accessoriesJSON[i].services.length; j++) {
    var service = new service_Factor.Service(accessoriesJSON[i].services[j].sType);

    //loop through characteristics
    for (var k = 0; k < accessoriesJSON[i].services[j].characteristics.length; k++) {
        var options = {
            type: accessoriesJSON[i].services[j].characteristics[k].cType,
            perms: accessoriesJSON[i].services[j].characteristics[k].perms,
            format: accessoriesJSON[i].services[j].characteristics[k].format,
            initialValue: accessoriesJSON[i].services[j].characteristics[k].initialValue,
            supportEvents: accessoriesJSON[i].services[j].characteristics[k].supportEvents,
            supportBonjour: accessoriesJSON[i].services[j].characteristics[k].supportBonjour,
            manfDescription: accessoriesJSON[i].services[j].characteristics[k].manfDescription,
            designedMaxLength: accessoriesJSON[i].services[j].characteristics[k].designedMaxLength,
            designedMinValue: accessoriesJSON[i].services[j].characteristics[k].designedMinValue,
            designedMaxValue: accessoriesJSON[i].services[j].characteristics[k].designedMaxValue,
            designedMinStep: accessoriesJSON[i].services[j].characteristics[k].designedMinStep,
            unit: accessoriesJSON[i].services[j].characteristics[k].unit,
        }

        var characteristic = new characteristic_Factor.Characteristic(options, accessoriesJSON[i].services[j].characteristics[k].onUpdate);

        service.addCharacteristic(characteristic);
    };  
    accessoryController.addService(service);
};

//increment targetport for each accessory
targetPort = targetPort + (i*2);

var accessory = new accessory_Factor.Accessory(accessoriesJSON[i].displayName, accessoriesJSON[i].username, storage, parseInt(targetPort), accessoriesJSON[i].pincode, accessoryController);
accessories[i] = accessory;
accessoryControllers[i] = accessoryController;
accessory.publishAccessory();

};

from hap-nodejs.

KhaosT avatar KhaosT commented on May 29, 2024

@dermarder Can you run "rm /home/pi/HAP-NodeJS/accessories/._*" and start HAP Server again?

from hap-nodejs.

dermarder avatar dermarder commented on May 29, 2024

@KhaosT It works! My server is now up and running! Thank you very much

from hap-nodejs.

Related Issues (20)

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.