anthonywebb / homebridge-cbus

CBus plugin for homebridge
MIT License
35 stars 20 forks source link

Badly formed netid. #115

Open martinjgreenn opened 3 years ago

martinjgreenn commented 3 years ago

I have homebridge and homebridge-cbus installed on CentOS 8. C-Gate is installed and I have verified I can connect on 127.0.0.1 20023:


> Connected to 127.0.0.1.
> Escape character is '^]'.
> 201 Service ready: Clipsal C-Gate Version: v2.11.4 (build 3251) #cmd-syntax=1.0
> noop
> 200 OK.
> project use HOME
> 200 OK.
> net open 254
> 200 OK: //HOME/254
> tree 254
> 320- Network name:254 type=Lorax address=192.168.1.9:10001 state=ok
> 320-  Unit count=7
> 320- Units:
> 320-//HOME/254/p/1 ($1) type=RELDN12 app=56($38),255($ff) state=ok groups=1,6,3,4,5
> 320-//HOME/254/p/3 ($3) type=PC_SHAC app=255($ff),255($ff) state=ok groups=
> 320-//HOME/254/p/4 ($4) type=SYS_SHAC app=255($ff),255($ff) state=ok groups=
> 320-//HOME/254/p/13 ($d) type=KEYGL5 app=56($38),255($ff) state=ok groups=
> 320-//HOME/254/p/20 ($14) type=KEYE1 app=56($38),255($ff) state=ok groups=6
> 320-//HOME/254/p/21 ($15) type=KEYE1 app=56($38),255($ff) state=ok groups=3
> 320-//HOME/254/p/255 ($ff) type=KEYE2 app=56($38),255($ff) state=ok groups=1,4
> 320-Applications:
> 320- Application 56 ($38) [lighting]
> 320- Groups:
> 320-  //HOME/254/56/1 ($1) level=255 state=ok units=1,255
> 320-  //HOME/254/56/3 ($3) level=0 state=ok units=1,21
> 320-  //HOME/254/56/4 ($4) level=255 state=ok units=1,255
> 320-  //HOME/254/56/5 ($5) level=0 state=ok units=1
> 320-  //HOME/254/56/6 ($6) level=255 state=ok units=1,20
> 320- Application 223 ($df) [clock]
> 320- Net Vars:
> 320 -end-
> 

Config is:

> {
>     "bridge": {
>         "name": "Homebridge 44D3",
>         "username": "0E:D2:8A:EA:44:D3",
>         "port": 51155,
>         "pin": "931-21-892"
>     },
>     "accessories": [],
>     "platforms": [
>         {
>             "name": "Config",
>             "port": 8581,
>             "platform": "config"
>         },
>             {
>                 "platform": "homebridge-cbus.CBus",
>                 "name": "CBus",
>                 "client_ip_address": "127.0.0.1",
>                 "client_cbusname": "HOME",
>                 "client_debug": false,
>                 "platform_export": "my-devices.json",
>                 "accessories": [
>                     {
>                         "type": "light",
>                         "id": 1,
>                         "name": "Dining Lights",
>                         "network": "254"
>                     }
>                 ]
>             }
>     ]
> }

However when I restart Homebridge it crashes with: [4/27/2021, 8:09:26 AM] [HB Supervisor] Starting Homebridge with extra flags: -I [4/27/2021, 8:09:26 AM] [HB Supervisor] Started Homebridge v1.3.4 with PID: 55186 Initializing HAP-NodeJS v0.9.4... [4/27/2021, 8:09:26 AM] Loaded config.json with 0 accessories and 2 platforms. [4/27/2021, 8:09:26 AM] Loaded 0 cached accessories from cachedAccessories. [4/27/2021, 8:09:26 AM] --- [4/27/2021, 8:09:27 AM] Loaded plugin: homebridge-cbus@1.1.0 [4/27/2021, 8:09:27 AM] Registering platform 'homebridge-cbus.CBus' [4/27/2021, 8:09:27 AM] --- [4/27/2021, 8:09:27 AM] Loaded plugin: homebridge-config-ui-x@4.41.0 [4/27/2021, 8:09:27 AM] Registering platform 'homebridge-config-ui-x.config' [4/27/2021, 8:09:27 AM] --- [4/27/2021, 8:09:27 AM] Loaded plugin: homebridge-nest@4.5.3 [4/27/2021, 8:09:27 AM] Registering platform 'homebridge-nest.Nest' [4/27/2021, 8:09:27 AM] --- [4/27/2021, 8:09:27 AM] Loading 2 platforms... [4/27/2021, 8:09:27 AM] [Config] Initializing config platform... [4/27/2021, 8:09:27 AM] [Config] Running in Service Mode [4/27/2021, 8:09:27 AM] [CBus] Initializing homebridge-cbus.CBus platform... 2021-04-26T22:09:27.114Z cbus:platform Loading the accessories list… 2021-04-26T22:09:27.116Z cbus:platform Registering the accessories list… [4/27/2021, 8:09:27 AM] Initializing platform accessory 'Dining Lights'... Preparing Advertiser for 'Homebridge 44D3 4936' using bonjour-hap backend! Setup Payload: X-HM://00250DHESDLEH Enter this code with your HomeKit app on your iOS device to pair with Homebridge:

┌────────────┐     
│ 931-21-892 │     
└────────────┘     
> Starting to advertise 'Homebridge 44D3 4936' using bonjour-hap backend!
> [4/27/2021, 8:09:27 AM] Homebridge v1.3.4 (Homebridge 44D3) is running on port 51155.
> ERROR failed to load C-Gate database: Error: badly formed netid: '//HOME/254/56/NaN'
>     at Function.CBusNetId.parse (/usr/local/lib/node_modules/homebridge-cbus/lib/cbus-netid.js:152:9)
>     at CGateDatabase.getNetworkEntity (/usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:341:21)
>     at /usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:281:25
>     at arrayEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:530:11)
>     at Function.forEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9410:14)
>     at /usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:279:6
>     at /usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:4967:15
>     at baseForOwn (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:3032:24)
>     at /usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:4936:18
>     at Function.forEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9410:14)
> [4/27/2021, 8:09:27 AM] [HB Supervisor] Homebridge Process Ended. Code: 1, Signal: null

It seems to be passing an invalid network address to C-Gate?

PhilPearson commented 3 years ago

I think you'll find that network is an integer value, not a string. Try "network": 254

martinjgreenn commented 3 years ago

Sorry that was me trying to fix it. Changing to an integer doesn't fix. Whether an integer, string or network not specified, results are the same. (I notice it's not a required field + it's already got the network ID in the netid)

Indeed if I remove the accessories section entirely, it produces the same error.

JasonY00 commented 3 years ago

Can you define the network under the platform definition with:

"client_network": 254,

and remove it from your accessory definition.

You should also add the default application and control ports here. See the example config file.

the error looks like it’s saying that the c-bus group address “1” is not a number (NaN). The code that’s creating the CBusNetID says that it is creating an ID that has a valid network and application address but an invalid group address. //HOME/254/56/NaN = “Invalid CBus Group Address”. It has successfully constructed the rest of the CBus ID for the get command i.e. “get 254/56/1” which is what it wants to do first to find what state the accessory is in.

Perhaps also delete and retype the accessory line just in case.

Hope this helps

Cheers

Jason

DarylMc commented 3 years ago

@martinjgreenn try this one jsonformatter.txt

DarylMc commented 3 years ago

@martinjgreenn For platform export it appears you don't have a valid path. For example on my raspberry pi it is

"platform_export": "/home/pi/my-platform.json",

DarylMc commented 3 years ago

@martinjgreenn Just in case you didn't know there is a very easy semi automated setup for raspberry pi here https://github.com/greiginsydney/Homebridge-cbus-installer

martinjgreenn commented 3 years ago

ok I imported Daryl's config and discovered c-gate had lost my project. Reimported and it errors again:

ERROR failed to load C-Gate database: Error: badly formed netid: '//HOME/254/56/NaN' at Function.CBusNetId.parse (/usr/local/lib/node_modules/homebridge-cbus/lib/cbus-netid.js:152:9) at CGateDatabase.getNetworkEntity (/usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:341:21) at /usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:281:25 at arrayEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:530:11) at Function.forEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9410:14) at /usr/local/lib/node_modules/homebridge-cbus/lib/cgate-database.js:279:6 at /usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:4967:15 at baseForOwn (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:3032:24) at /usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:4936:18 at Function.forEach (/usr/local/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9410:14) [4/27/2021, 11:54:11 AM] [HB Supervisor] Homebridge Process Ended. Code: 1, Signal: null

Update: repointing it at c-gate on my laptop and it works. Which is curious - I can see the tree and devices via telnet on linux machine. I might have a look at greginsydney's installer see if there's anything I'm missing as far as c-gate.

Thanks for help btw!

DarylMc commented 3 years ago

@martinjgreenn

Not sure but here are a few things to consider. To get cgate to load and open the project you need to edit the cgate config file located in the cgate folder. Scroll down and add your project name in these two places. eg project.default=HOME project.start=HOME Check your project file eg HOME.xml is in the tag folder of the cgate directory where you are running cgate. Check no other instances of CGate on another PC are simultaneously connecting to your CNI . Restart CGate or reboot if you made any changes

JasonY00 commented 3 years ago

Just to be safe, I would also copy your c-gate database back over from your laptop and overwrite the one you have on your CentOS. It may be corrupt. Have a look at the HOME.XML file and see if there is anything strange about the entry relating to your CBUS GA 1 entry. Make sure you do what DarylMC says above and ensure that your project.default and project.start entries are updated.

Your error:

ERROR failed to load C-Gate database: Error: badly formed netid: '//HOME/254/56/NaN'
at Function.CBusNetId.parse (/usr/local/lib/node_modules/homebridge-cbus/lib/cbus-netid.js:152:9)

is from this module:

CBusNetId.parse = function (netIdString) {
    const NETID_REGEX = /^\/\/([A-Z0-9_]{1,8})(?:\/(\d{1,3})(?:\/(p|\d{1,3})(?:\/(\d{1,3}))?)?)?\/?(\d{1,3})?$/;

    let components = netIdString.match(NETID_REGEX);
    if (!components) {
        throw new Error(`badly formed netid: '${netIdString}'`);
    }

    return new CBusNetId(components[1], components[2], components[3], components[4], components[5]);
};

It is not seeing what it is expecting (an integer) for the C-Bus Group Address after the match command and it is all falling over after that. This command is cutting up the CBus response into separate components of Database, Network, Application, Group Address and Channel (for measurement devices such as Temp Sensors). It is failing on components[4] which is the group address.

Probably more than you needed to know, but whatever the cause, this is the outcome.

Cheers

Jason