anthonywebb / homebridge-cbus

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

Homebridge shutting down at startup #48

Closed DarylMc closed 7 years ago

DarylMc commented 7 years ago

I just tried a new install on pi3 with Jessie Lite Homebridge connects to CGate then shuts down. Any ideas? Thanks

Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

    ┌────────────┐
    │ 031-45-154 │
    └────────────┘

  cbus:client sent command '[100] dbgetxml //OFFICE' +62ms
[5/3/2017, 1:50:40 PM] Homebridge is running on port 51826.
  cbus:client rx snippet 343 'Begin XML snippet' +21ms
  cbus:client rx snippet 347 '<?xml version="1.0" encoding="utf-8"?>' +1ms
  cbus:client rx snippet 347 '<Installation><OID>a513d610-11dd-1035-9156-ed18f01c1456</OID><DBVersion>2.3</DBVersion><Version>1.0…' +1ms
  cbus:client rx response { commandId: 100, code: 344, matched: false, processed: false, type: 'response', raw: '[100] 344 End XML snippet' } +12ms
  cbus:client matched request '[100] dbgetxml //OFFICE' with response '[100] 344 End XML snippet' (0 pending requests) +3ms
pi@raspberrypi:~ $ npm test
npm ERR! Linux 4.9.24-v7+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "test"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! path /home/pi/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/home/pi/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/pi/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /home/pi/.npm/_logs/2017-05-03T03_51_58_134Z-debug.log
DarylMc commented 7 years ago

I'm sure CGate is all good and it looks like the close connection command came from the pi ip address

20170505-110145 899 sys Debug: New Command Context: cc008 = AccessContext Session /192.168.1.8#6
20170505-110145 766 cmd5 - Response: 201 Service ready: Clipsal C-Gate Version: v2.10.6 (build 3169) #cmd-syntax=1.0
20170505-110145 761 cmd5 - Command: [99] events e7s0c0
20170505-110145 766 cmd5 - Response: [99] 200 OK.
20170505-110145 761 cmd5 - Command: [100] dbgetxml //SHED2
20170505-110146 766 cmd5 - Response: [100] 343-Begin XML snippet
20170505-110146 766 cmd5 - Response: [100] 344 End XML snippet
20170505-110146 804 cmd5 - Host:/192.168.1.8 closed command interface from port: 45980
greiginsydney commented 7 years ago

@DarylMc Mine's reporting same (also Pi / Jessie):


    ââââââââââââââ
    â 031-45-154 â
    ââââââââââââââ
  cbus:client sent command '[100] dbgetxml //19P' +436ms
[5/6/2017, 6:42:09 AM] Homebridge is running on port 51826.
  cbus:client rx snippet 343 'Begin XML snippet' +1s
  cbus:client rx snippet 347 '<?xml version="1.0" encoding="utf-8"?>' +18ms
  cbus:client rx snippet 347 '<Installation><OID>e6dc5840-1090-1035-bd5f-cce56739c70e</OID><DBVersion>2.3</DBVersion><Version>1.0â¦' +94ms
  cbus:client rx response { commandId: 100, code: 344, matched: false, processed: false, type: 'response', raw: '[100] 344 End XML snippet' } +33ms
  cbus:client matched request '[100] dbgetxml //19P' with response '[100] 344 End XML snippet' (0 pending requests) +8ms
homebridge@raspberrypi:~$ 
greiginsydney commented 7 years ago

I'd like to revert to v0.60 to test - my last known working release - but I can't see how... Anyone?

DarylMc commented 7 years ago

I was able to revert to an original image of homebridge-cbus 0.5.0 and all working nicely again. Ran sudo npm update -g. to update all the NPM packages. Deleted .homebridge/persist files before starting homebridge. Had the same problems as the new builds I tried see above. I would also like to try a previous build of homebridge-cbus

simonhac commented 7 years ago

@greiginsydney and @DarylMc, it looks like you are both having the same problem -- homebridge quits right after downloading the database.

looking at the code it is likely that we are catching an exception and exiting here.

the error message in the previous line isn't making its way to the console, which must be an unintended behaviour of the logging library. looking into it.

simonhac commented 7 years ago

@greiginsydney and @DarylMc -- i can't get it to bomb for me using greig's config.json file, unfortunately.

if either of you are up for helping to debug this one, please change this line in cgate-database.js from:

log(`${chalk.red.bold(`ERROR`)} failed to load C-Gate database: ${ex.stack}`);

to

console.error(`${chalk.red.bold(`ERROR`)} failed to load C-Gate database: ${ex.stack}`);

...then at least we'll know why the database parse is failing.

simonhac commented 7 years ago

out of interest, are you running G-Gate on the same host, or perhaps on windows?

cmlpreston commented 7 years ago

I think I was having the same issue with homebridge immediately exiting. I've made the suggested change and see this:

`pi@pi:~/.homebridge$ homebridge WARNING The program 'node' uses the Apple Bonjour compatibility layer of Avahi. WARNING Please fix your application to use the native API of Avahi! WARNING For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node WARNING The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi. WARNING Please fix your application to use the native API of Avahi! WARNING For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister [5/7/2017, 4:11:51 PM] Loaded plugin: homebridge-cbus [5/7/2017, 4:11:51 PM] Registering platform 'homebridge-cbus.CBus' [5/7/2017, 4:11:51 PM] --- [5/7/2017, 4:11:51 PM] Loaded config.json with 0 accessories and 1 platforms. [5/7/2017, 4:11:51 PM] --- [5/7/2017, 4:11:51 PM] Loading 1 platforms... [5/7/2017, 4:11:51 PM] [CBus] Initializing homebridge-cbus.CBus platform... cbus:client Opening connection to C-Gate… +0ms [5/7/2017, 4:11:52 PM] Loading 0 accessories... cbus:client C-Gate connection open. +57ms cbus:client Connected to C-Gate server v2.10.6 (build 3145), syntax v1.0 +26ms cbus:client Configuring C-Gate session… +0ms cbus:client C-Gate session estabished and configured at 20023:127.0.0.1 +8ms cbus:platform Loading the accessories list… +9ms cbus:platform Registering the accessories list… +33ms [5/7/2017, 4:11:52 PM] [CBus] Initializing platform accessory 'Lounge'... Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

┌────────────┐     
│ 031-45-154 │     
└────────────┘     

cbus:client sent command '[100] dbgetxml //26NICH' +144ms [5/7/2017, 4:11:52 PM] Homebridge is running on port 51826. cbus:client rx snippet 343 'Begin XML snippet' +652ms cbus:client rx snippet 347 '<?xml version="1.0" encoding="utf-8"?>' +5ms cbus:client rx snippet 347 '50cd40c0-1451-1035-a98c-8dd06e1960092.31.0…' +38ms cbus:client rx response { commandId: 100, code: 344, matched: false, processed: false, type: 'response', raw: '[100] 344 End XML snippet' } +31ms cbus:client matched request '[100] dbgetxml //26NICH' with response '[100] 344 End XML snippet' (0 pending requests) +8ms ERROR failed to load C-Gate database: Error: ENOENT: no such file or directory, open './resources/unit-types.json' at Object.fs.openSync (fs.js:584:18) at Object.fs.readFileSync (fs.js:491:33) at _getUnitTypeInfo (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/lib/cgate-database.js:45:24) at _extractGroupAddresses (/home/pi/.nvm/versions/node/v7.10.0/lib/nodemodules/homebridge-cbus/lib/cgate-database.js:158:21) at .forEach.srcUnit (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/lib/cgate-database.js:206:18) at arrayEach (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:537:11) at Function.forEach (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9359:14) at _extractUnits (/home/pi/.nvm/versions/node/v7.10.0/lib/nodemodules/homebridge-cbus/lib/cgate-database.js:134:4) at .forEach.network (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/lib/cgate-database.js:241:3) at arrayEach (/home/pi/.nvm/versions/node/v7.10.0/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:537:11) `

cmlpreston commented 7 years ago

I have a local instance of c-gate running on the pi, which is reachable via Toolkit etc. on other hosts.

cmlpreston commented 7 years ago

I just tried starting homebridge from .../node_modules/homebridge-cbus and it seems to not exit, presumably because ./resources/unit-types.json is now found.

I'm setting this up for the first time so I can't say how well it's working otherwise (yet)!

Edit: working fine. Lounge light turned on from iPhone. Fantastic!

DarylMc commented 7 years ago

Hi Simon I am trying. Cant find cgate-database.js

cmlpreston commented 7 years ago

Try:

find / -name cgate-database.js

That will search your entire filesystem for it :-)

DarylMc commented 7 years ago

Thanks cmlpreston Will have to remember that. /usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js

Simon I updated the cgate-database.js

 cbus:client sent command '[100] dbgetxml //OFFICE' +128ms
[5/7/2017, 7:37:13 PM] Homebridge is running on port 51826.
  cbus:client rx snippet 343 'Begin XML snippet' +23ms
  cbus:client rx snippet 347 '<?xml version="1.0" encoding="utf-8"?>' +1ms
  cbus:client rx snippet 347 '<Installation><OID>5dfac3f0-1535-1035-8458-bfab833a67e0</OID><DBVersion>2.3</DBVersion><Version>1.0…' +1ms
  cbus:client rx response { commandId: 100, code: 344, matched: false, processed: false, type: 'response', raw: '[100] 344 End XML snippet' } +14ms
  cbus:client matched request '[100] dbgetxml //OFFICE' with response '[100] 344 End XML snippet' (0 pending requests) +3ms
ERROR failed to load C-Gate database: Error: ENOENT: no such file or directory, open './resources/unit-types.json'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at _getUnitTypeInfo (/usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js:45:24)
    at _extractGroupAddresses (/usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js:156:21)
    at _.forEach.srcUnit (/usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js:204:18)
    at arrayEach (/usr/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/usr/lib/node_modules/homebridge-cbus/node_modules/lodash/lodash.js:9359:14)
    at _extractUnits (/usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js:132:4)
    at _.forEach.network (/usr/lib/node_modules/homebridge-cbus/lib/cgate-database.js:239:3)
cmlpreston commented 7 years ago

Try running homebridge from /usr/lib/node_modules/homebridge-cbus

I bet it doesn't quit immediately.

DarylMc commented 7 years ago

@simonhac @cmlpreston Starting homebridge from /usr/lib/node_modules/homebridge-cbus worked. I had to remove home on the iPhone and set it up again but it seems to be all working nicely. Adding accessories to the phone app is much improved from what I remember of v0.5.0. Great stuff

simonhac commented 7 years ago

thanks @DarylMc -- you've led me straight to the answer. working on it now.

DarylMc commented 7 years ago

I just want to mention that when I installed homebridge-cbus I used sudo npm install -g homebridge-cbus

simonhac commented 7 years ago

@anthonywebb i've fixed this in PR #49.

thanks @DarylMc and @greiginsydney for your help and patience.

anthonywebb commented 7 years ago

@DarylMc @greiginsydney @simonhac version 0.6.2 has been published with the fix. Thanks all!

DarylMc commented 7 years ago

Hello @simonhac @anthonywebb I have made a spreadsheet with start to finish instructions for Homebridge, Homebridge-CBus, CGate on raspberry pi3 Jessie Lite. CGate and Homebridge running as service with autostart for both. I've tried it out a few times and I think it is accurate for now.

I posted it on CBus forum but then I removed it because I think I should ask the contributors first. I would like to share an image for pi3 but it is quite large and I'm working on reducing it to a minimal size. Then I plan to upload the image to my OneDrive. Someone should then be able to install the image and update 4 or 5 files and get it all running. What do you think?

It's all quite new right now but I think it is running well. Perhaps the CGate is a little sluggish compared to running it on a more powerful machine but I'm giving it a good test right now.

simonhac commented 7 years ago

thanks @DarylMc -- i've taken a very brief look through it, will be able to look at it more closely in the next week.

i doubt that cgate is sluggish on the RPi. if cgate ever uses more than 5% of the CPU i'd be very surprised.

we should move the installation instructions into the project wiki (currently empty).

i encourage you to take a look at docker as a way of distributing the configuration.

DarylMc commented 7 years ago

Docker? Oh no Another new term I have to Google :) My concern is I don't want to go publishing stuff other people have put a lot of work into. I took the link off CBus forum but here it is if you want to have a look. https://1drv.ms/x/s!AminzOc-NC4UgZkIljFWzUxChgBeKg

DarylMc commented 7 years ago

Hi Simon So I have CGate and Homebridge running on the pi. Yeah CPU use seems low. iPad as Home hub. It just seems to be the iPhone not the iPad but when I go in and out of wifi network phone seems to take a while to sync. Just mentioning it. I'm going to use it for a bit more to see what's going on.

DarylMc commented 7 years ago

All this is probably the wrong place to mention things but CGate exe zip on CIS website has had a few updates in the last few days. It's now a version which matches matrix for the latest Toolkit. http://www2.clipsal.com/cis/technical/downloads/c-gate There is a new Toolkit too.

simonhac commented 7 years ago

CPU usage for cgate is low because what it does is not CPU intensive. it'd run on a machine 1/10th the speed -- just needs a bunch of RAM as java is a bit of a hog.

out of interest, why are you using ser2sock? i don't need serial because i have an ethernet CNI, but for those with a serial CNI, doesn't cgate include serial drivers?

thanks for the note about the cgate update -- i wish they'd publish a durable link, something like http://cis.clipsal.com.au/downloads/CGate/cgate-LATEST.zip.

DarylMc commented 7 years ago

Hi Simon I'm not sure about ser2sock. I just followed these instructions. http://addictedtopi.tumblr.com/post/96351714013/installing-c-gate-on-a-raspberry-pi The latest CGate also supports Java 8 http://203.41.170.20/downloads/Toolkit/C-Bus%20Toolkit%201.15%20Release%20Notes.pdf

anthonywebb commented 7 years ago

@DarylMc a rpi image has long been on my list of things to get to. I think it will be a real nice addition too. Thanks for your hard work on it! I'd love to get the wiki hooked up and get some solid documentation in the works.

DarylMc commented 7 years ago

I think there might have been some issues. So far the known limitations include:

  1. The SerialIO library needs manual copying of files to work with 64-bit JREs.
  2. The SerialIO library does not work on Linux ARM.
DarylMc commented 7 years ago

Does that mean I can skip some stuff?

simonhac commented 7 years ago

Does that mean I can skip some stuff?

i guess ser2sock is needed for anyone with a serial CNI -- glad i don't have one: serial is a pain on modern computers...

DarylMc commented 7 years ago

Thanks @anthonywebb I have my nephew working to help me make a smaller image. I did look at the idea of a curl bash setup. It looks pretty clever. Maybe it could import all the config files too? I'm happy to put an image up on my OneDrive page once I shrink it.

DarylMc commented 7 years ago

@simonhac I use a serial device server connected to RS232 PCI. In effect it is a CNI So I don't quite understand but can I skip some of those steps?

DarylMc commented 7 years ago

Clipsal CNI is a pretty sold piece of hardware but mine died after 10 years. I had 2 CNI on the network for a while which can be useful. Maybe less relevant now days with CGate running on something like the pi. I haven't looked back since using a Moxa serial device server connected to RS232 PCI and I think it is a far better setup than Clipsal CNI. Cheaper too. I think CNI was updated from the one I had. It had painful configuration and you only have to search the CBus forum to see how many problems people had setting it up. Later model CNI's must be better because I don't see so many people having problems now days.

DarylMc commented 7 years ago

@simonhac Hello Simon I removed the ser2sock instructions from spreadsheet because I am using CNI. Updated spreadsheet for latest CGate and Java V8. All running well at this point in time. If iPhone wifi is turned off and on it takes about 6 seconds after Home is opened to update status. Maybe less. I need to use it for a bit.

I've been working on a curl bash script to get a lot of the install done automatically. This is what I have so far running on my NAS web server. cd /home/pi sudo apt-get update sudo apt-get upgrade -y sudo apt-get update sudo apt-get install git -y curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install nodejs sudo apt-get install -y libavahi-compat-libdnssd-dev sudo npm install -g -y --unsafe-perm homebridge sudo npm install -g homebridge-cbus sudo apt-get update && sudo apt-get install -y oracle-java8-jdk wget http://203.41.170.20/downloads/CGate/cgate-2.11.0_3233.zip unzip cgate-2.11.0_3233.zip sudo mv cgate /usr/local/bin sudo apt-get install -y telnet

To give some idea what happens after that here is the pi history. History

1 sudo raspi-config 2 curl 192.168.1.4 | bash 3 homebridge 4 sudo nano /etc/init.d/cgate 5 sudo chown -R pi:pi /usr/local/bin/cgate 6 sudo chmod +x /usr/local/bin/cgate/cgate.jar 7 sudo chmod 755 /etc/init.d/cgate 8 sudo update-rc.d cgate defaults 9 nano /usr/local/bin/cgate/config/access.txt 10 sudo service cgate restart 11 nano /usr/local/bin/cgate/config/C-GateConfig.txt 12 sudo service cgate restart 13 homebridge 14 cd .homebridge 15 nano config.json 16 cd 17 homebridge 18 cd /etc/default 19 sudo nano homebridge 20 cd /etc/systemd/system 21 sudo nano homebridge.service 22 cd 23 sudo useradd -M --system homebridge 24 cd /var/lib 25 sudo mkdir homebridge 26 sudo chown -R homebridge:homebridge /var/lib/homebridge 27 sudo chmod 777 -R /var/lib/homebridge 28 cd 29 cd /var/lib/homebridge 30 sudo nano config.json 31 cd 32 sudo systemctl daemon-reload 33 sudo systemctl enable homebridge 34 sudo systemctl start homebridge 35 sudo systemctl status homebridge

Maybe an image is easier. I will get that done as soon as I can.

DarylMc commented 7 years ago

I installed telnet on the pi because I think it can help skip the step to edit cgate access. Maybe in the future I can figure out the cgate commands to create, load and save the project without running Toolkit.

simonhac commented 7 years ago

@DarylMc a lot of folks frown upon telnet -- use ssh if you have it. (i'd be surprised if it is not installed by default.)

DarylMc commented 7 years ago

I think telnet is the only way to connect to CGate

simonhac commented 7 years ago

I think telnet is the only way to connect to CGate

sure, but why do you need telnet on the RPi?

DarylMc commented 7 years ago

Just to avoid adding access in the cgate access.txt

simonhac commented 7 years ago

so are you using it just to test cgate?

DarylMc commented 7 years ago

yeah

DarylMc commented 7 years ago

and maybe if I can not use Toolkit at all then I wont need to allow any remote access to cgate

DarylMc commented 7 years ago

i see telnet doesnt have a password so not using it is ok too

DarylMc commented 7 years ago

thanks i might take that out of my list

simonhac commented 7 years ago

i'm a bit confused, but just checking that you are editing the access.txt file to include your PC running Toolkit?

DarylMc commented 7 years ago

Yes and also to Telnet to CGate and run commands like PROJECT LIST and NET LIST

DarylMc commented 7 years ago

It was just an idea but i thought why not do it on the pi itself. And maybe at some stage avoid using toolkit altogether.

DarylMc commented 7 years ago

@simonhac @anthonywebb I've managed to shrink my current working pi3 image with Jessie Lite, Homebridge, Homebridge-CBus and CGate to a 709MB zip file. Uploading it to OneDrive now. Should be there in a few hours. Yes my connection is that slow.

It's not going to be that easy for someone to use it because they still have to alter a number of files. Any suggestions?

I was going to post it on CBus forum Homebridge page. If you want me to post a link somewhere else or not at all let me know. I've already tested the image of my local zip file by writing a new SD so I'm pretty sure it is good.

DarylMc commented 7 years ago

@simonhac @anthonywebb I posted a link to my image and some notes on CBus forum. https://onedrive.live.com/?authkey=%21ANlD74Wg0RsHv98&id=142E343EE7CCA768%2119603&cid=142E343EE7CCA768 It's still going to be a bit tough for someone to install the image and edit things to get it going on their network but I hope it can help. I think the instructions are accurate. I've been trying to send commands to cgate and set up the project on pi but Toolkit is looking an easier way right now.

DarylMc commented 7 years ago

@simonhac @anthonywebb I'd post this on the wiki but it does not seem to work