gismo141 / homebridge-server

Server plugin for homebridge
https://gismo141.github.io/configure-your-homebridge-2/
152 stars 20 forks source link

HomeBridge Server on Windows 10 Log Path trouble #30

Open Dirtrunner702 opened 7 years ago

Dirtrunner702 commented 7 years ago

Hello! First off thank you for your amazing work. Its very fancy! I have a few things I would like help with. I am currently running HomeBridge Server on Windows 10 and it seems to be running ok. The problem I have is that if I add anything other than "system" for the log path entry here: "platform": "Server", "port" : 8765, "name" : "Homebridge Server", "log" : "", "restart" : ""

The service does not start. Ive tried windows variable paths, UNC paths such as "C:\Users\Username\output.log and even c:\users\username\Output.log.

Neither option works and therefor stops the service from running. I can leave it systemd but when I click the log tab in the interface the service crashes.

Also, for the restart value I want to either stop/start the task or even just execute shutdown /r /t 0 and I have a script that starts the service on reboot. Neither option seems to be allowed and does not allow the service to start.

Any advice?

gismo141 commented 7 years ago

Whooohooo the first Windows user and thanks for the feedback! ;)

Okay this one might be a tough one to debug because I have no machine with Windows around but I'll try my best.

Could you please try to use forward-slashes in the file-paths? E.g.:

"log": "C:/Users/Username/output.log"

or

"log": "C:\\Users\Username\output.log"

Does one of these work?

Dirtrunner702 commented 7 years ago

Hey! Yea man! Its been a fun project to tackle with the setup and I'm looking forward to doing all the cool things with it up and running completely!

So I tried the first suggestion "log": "C:/Users/HomeBridge/output.log". The service starts correctly but when trying to view the log it crashes and gives this error , see below.

C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\bin>Node Homebridge [1/19/2017, 12:00:41 AM] Loaded plugin: homebridge-http [1/19/2017, 12:00:41 AM] Registering accessory 'homebridge-http.Http' [1/19/2017, 12:00:41 AM] --- [1/19/2017, 12:00:41 AM] Loaded plugin: homebridge-server [1/19/2017, 12:00:41 AM] Registering platform 'homebridge-server.Server' [1/19/2017, 12:00:41 AM] --- [1/19/2017, 12:00:41 AM] Loaded config.json with 0 accessories and 1 platforms. [1/19/2017, 12:00:41 AM] --- [1/19/2017, 12:00:41 AM] Loading 1 platforms... [1/19/2017, 12:00:41 AM] [Homebridge Server] Initializing Server platform... [1/19/2017, 12:00:41 AM] Loading 0 accessories... Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

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

[1/19/2017, 12:00:41 AM] [Homebridge Server] is listening on: http://192.168.86.130:8765 [1/19/2017, 12:00:42 AM] Homebridge is running on port 51826. C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:453 return log(err); ^ TypeError: log is not a function at ReadFileContext.callback (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:453:34) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)

The second suggestion "log": "C:\Users\HomeBridge\output.log" Does not allow the service to start and throws the following error.

C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\bin>Node Homebridge [1/18/2017, 11:57:58 PM] Loaded plugin: homebridge-http [1/18/2017, 11:57:58 PM] Registering accessory 'homebridge-http.Http' [1/18/2017, 11:57:58 PM] --- [1/18/2017, 11:57:58 PM] Loaded plugin: homebridge-server [1/18/2017, 11:57:58 PM] Registering platform 'homebridge-server.Server' [1/18/2017, 11:57:58 PM] --- [1/18/2017, 11:57:58 PM] There was a problem reading your config.json file. [1/18/2017, 11:57:58 PM] Please try pasting your config.json file here to validate it: http://jsonlint.com [1/18/2017, 11:57:58 PM] C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:197 throw err; ^

SyntaxError: Unexpected token H at Object.parse (native) at Server._loadConfig (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:191:19) at new Server (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:52:38) at module.exports (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\lib\cli.js:26:16) at Object. (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge\bin\Homebridge:17:22) at Module._compile (module.js:425:26) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Function.Module.runMain (module.js:457:10)

gismo141 commented 7 years ago

Okay lets try some hacking together:

First stick in your config with the path:

"log": "C:/Users/HomeBridge/output.log"

and then please open the file C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js in a text editor like notepad or alike and search for the following part:

logFile.readFile(config.log, 'utf8', function(err, log) {

replace it with:

logFile.readFile(path.normalize(config.log), 'utf8', function(err, log) {

Then save the file restart your homebridge and report back. 🙏

Dirtrunner702 commented 7 years ago

Ok did exactly as you said, Restarted Homebridge, It started fine. Went to open the log again and it crashed with the following:

C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:451 logFile.readFile(path.normalize(config.log), 'utf8', function(err, log) { ^ ReferenceError: path is not defined at Server.handleRequest (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:451:36) at emitTwo (events.js:87:13) at Server.emit (events.js:172:7) at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:527:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)

gismo141 commented 7 years ago

Grrrr.... yeah for sure I forgot something -.- sorry for that.

In the same file search for:

var http = require('http');

and add below:

var path = require('path');

It now should look like:

var http = require('http');
var path = require('path');

Then restart the service.

Dirtrunner702 commented 7 years ago

Hmm maybe now I can try another syntax for the log path? This is the error with those changes

C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:454 return log(err); ^

TypeError: log is not a function at ReadFileContext.callback (C:\Users\HomeBridge\AppData\Roaming\npm\node_modules\homebridge-server\index.js:454:34) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)

gismo141 commented 7 years ago

Okay I'll try to setup a Windows VM for testing and I'll get back to you as soon as I can. Sorry for the inconvenience :(

Otherwise if you get it up and running with a different path it would be perfect if you could drop me a message - thanks!

Dirtrunner702 commented 7 years ago

Awesome!

Thanks for the suggestions once more, but the same keeps happening as before. So for now I just have to not click the Log tab and all is good!

gismo141 commented 7 years ago

Hey @Dirtrunner702!,

Sorry for the delay on the update - last weekend I tried to setup Homebridge on Windows which wasn't as easy as thought.

Until now I am not quite sure if this solves the problem but indeed, could you please try another log-path as:

"log": "C:\Users\Username\output.log"

And if you still have the adaptions in the index.js-file then you're good to go, otherwise please reapply them first.

If this doesn't work as well, try:

"log": "C:\\Users\\Username\\output.log"

Thanks!

P.S.: Paths and alike are sadly the most difficult part in these cross-platform-projects

Dirtrunner702 commented 7 years ago

Thank you for all the help and good communication! Unfortunately both of those methods don't allow homebridge to run. The only methods that keep homebridge working but still do not output the log are the following "log": "C://Users/HomeBridge/output.log", "log": "C:/Users/HomeBridge/output.log",

Its not a huge problem as long as I do not click the Log tab!

Thank you!

I can send you a vmdk of my VM running win10 and Homebridge I can drop box it for you but its about 40GB. If it will help with development id be happy to help!

gismo141 commented 7 years ago

Oh this would indeed be a great help - could you squeeze it somehow and upload it? Feel free to write me an email and I'll try to fix it asap. Thanks!

prbreezy commented 7 years ago

Hello,

I read the post and looks like we still trying to fix the path I'm able to use Homebridge-Server on windows its run but the logs are never been written there..

I can test few recommendations if you want, just let me know.

Cheers,

i3laze commented 6 years ago

Hm.. is there a happy Windows ending? I'm using \\ in log path just fine, but the log file is neither created nor written to. When created manually, empty log is displayed in config-ui-x without errors though.

Using just homebridge.log as a full path doesn't help too - still no writes.

400HPMustang commented 5 years ago

did anyone ever get any traction on this? I'm experiencing the same issue and cannot get anything to write to a log file.

gismo141 commented 5 years ago

I am sorry but at the moment I can't provide a windows-setup - I'd be really thankful if someone with windows and some interest in node could support me! # #