DeeeeLAN / homebridge-sleepiq

SleepIQ Homebridge plugin
18 stars 10 forks source link

Unexpected token in JSON #1

Closed 400HPMustang closed 5 years ago

400HPMustang commented 5 years ago

Just updated to latest for the bed controls, when launching homebridge I get this in my console:

`undefined:1 undefined ^

SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse () at API. (C:\Users\HTPC\AppData\Roaming\npm\node_modules\homebridge-sleepiq\API.js:109:20) at self.callback (C:\Users\HTPC\AppData\Roaming\npm\node_modules\homebridge-sleepiq\node_modules\request\request.js:185:22) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at Request.onRequestError (C:\Users\HTPC\AppData\Roaming\npm\node_modules\homebridge-sleepiq\node_modules\request\request.js:881:8) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7) at TLSSocket.socketErrorListener (_http_client.js:387:9) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)`

400HPMustang commented 5 years ago

Nevermind. I am an idiot. I put the refresh type as a string in quotes and not an integer. Please ignore me.

DeeeeLAN commented 5 years ago

All good. I will admit, I could have made those variables more robust and checked for strings and integers, but, eh. :)

400HPMustang commented 5 years ago

Incidentally is it possible to make the bed labels configurable? I’d like them to be something other than bed0left and bed0right on the user facing side. Maybe have them inherit the bed side names that were coming figured in the API?

On Feb 19, 2019, at 10:17 AM, DeeeeLAN notifications@github.com wrote:

All good. I will admit, I could have made those variables more robust and checked for strings and integers, but, eh. :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

DeeeeLAN commented 5 years ago

You can change the names in the Home app (by Apple). I am sure other apps let you change the names as well. I set those as a default name taking the bed name + side name from the API, with the expectation that you can customize it yourself to your heart's content in the app. It syncs the name back to homebridge I believe, so it maintains whatever name you set, as long as you don't delete it and re-add it.

400HPMustang commented 5 years ago

Looks like either the refresh interval wasn't the issue or something else is throwing the same error and crashing my homebridge setup all together.

Pastebin of the error https://pastebin.com/7KXGC6HX

and my config JSON is simply

"platforms": [
        {
            "platform": "SleepNumber",
            "username": "myemailaddress@gmail.com",
            "password": "mysleepnumberapppassword",
            "refreshTime": 5
        },
DeeeeLAN commented 5 years ago

Try running in debug mode and see if you can get a more detailed error.

400HPMustang commented 5 years ago

I debugged it, got it to crash but the last thing in the log before it crashes is what looks like a successful SleepNumber json query.

I'd pastebin the entire log but it's too large...I can email it to you too if you need the entire log but it doesn't look like anything useful.

[2019-2-23 08:06:31] [SleepNumber] Getting SleepIQ JSON Data...
[2019-2-23 08:06:31] [SleepNumber] SleepIQ JSON data successfully retrieved
[2019-2-23 08:06:31] [SleepNumber] SleepIQ Occupancy Data: {leftSide:false}
[2019-2-23 08:06:31] [SleepNumber] SleepIQ Sleep Number: {leftSide:100}
[2019-2-23 08:06:31] [SleepNumber] SleepIQ Occupancy Data: {rightSide:false}
[2019-2-23 08:06:31] [SleepNumber] SleepIQ Sleep Number: {rightSide:100}
[2019-2-23 08:06:33] [SleepNumber] Getting SleepIQ JSON Data...
[2019-2-23 08:06:33] [SleepNumber] SleepIQ JSON data successfully retrieved
[2019-2-23 08:06:33] [SleepNumber] SleepIQ Occupancy Data: {leftSide:false}
[2019-2-23 08:06:33] [SleepNumber] SleepIQ Sleep Number: {leftSide:100}
[2019-2-23 08:06:33] [SleepNumber] SleepIQ Occupancy Data: {rightSide:false}
[2019-2-23 08:06:33] [SleepNumber] SleepIQ Sleep Number: {rightSide:100}
[2019-2-23 08:06:35] [SleepNumber] Getting SleepIQ JSON Data...
[2019-2-23 08:06:35] [SleepNumber] SleepIQ JSON data successfully retrieved
[2019-2-23 08:06:35] [SleepNumber] SleepIQ Occupancy Data: {leftSide:false}
[2019-2-23 08:06:35] [SleepNumber] SleepIQ Sleep Number: {leftSide:100}
[2019-2-23 08:06:35] [SleepNumber] SleepIQ Occupancy Data: {rightSide:false}
[2019-2-23 08:06:35] [SleepNumber] SleepIQ Sleep Number: {rightSide:100}
DeeeeLAN commented 5 years ago

Hmm, that is really odd, because that means the function that failed had been running successfully for some time. how long did it run for before crashing? It is possible that the crash is happening because it needs to re-authenticate and get a new API key from sleep number, but if that is the case, I wonder why nobody else is having an issue. Unfortunately, I do not have very good debug statements in place, so there is not much I can do right now. I will have to add some better statements, then have you update and see if we can figure it out.

400HPMustang commented 5 years ago

It runs anywhere from one hour to a few hours. It does work once or twice in testing before it crashes.

On Feb 23, 2019, at 4:16 PM, DeeeeLAN notifications@github.com wrote:

Hmm, that is really odd, because that means the function that failed had been running successfully for some time. how long did it run for before crashing? It is possible that the crash is happening because it needs to re-authenticate and get a new API key from sleep number, but if that is the case, I wonder why nobody else is having an issue. Unfortunately, I do not have very good debug statements in place, so there is not much I can do right now. I will have to add some better statements, then have you update and see if we can figure it out.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

DeeeeLAN commented 5 years ago

I just pushed an update that will hopefully be able to give us a better picture. Update and run in debug mode again and see if you can get a better message out. I made a slight change to check for null on the line your first message indicated, so it is possible that that is all it needs and you won't crash again. Let me know once you get the crash again.

400HPMustang commented 5 years ago

@DeeeeLAN when I launch in debug mode now I get this

(node:2712) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 update listeners added. Use emit ter.setMaxListeners() to increase limit

And then it crashes...

But it did look like it was running after a reboot even though the web front end I use says its not. So I checked the logs and I've got some new messaging in the logs in general I've not seen before

2019-2-24 08:31:52] [SleepNumber] SleepIQ authentication failed, stand by for automatic reauthentication
[2019-2-24 08:31:52] [SleepNumber] SleepIQ Authenticating...
 [2019-2-24 08:31:52] [SleepNumber] Family Status GET results: {"Error":{"Code":50002,"Message":"Session is invalid"}}
 [2019-2-24 08:31:52] [SleepNumber] SleepIQ authentication failed, stand by for automatic reauthentication
 [2019-2-24 08:31:52] [SleepNumber] SleepIQ Authenticating...
 [2019-2-24 08:31:52] [SleepNumber] Login result: {"Error":{"Code":401,"Message":"Authentication token of type [class org.apache.shiro.authc.UsernamePasswordToken] could not be authenticated by any configured realms.  Please ensure that at least one realm can authenticate these tokens."}}
 [2019-2-24 08:31:52] [SleepNumber] Getting SleepIQ JSON Data...

EDIT: also finding a flood of this in the log:

[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","path":null,"host":"api.sleepiq.sleepnumber.com","port":443}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}
[2019-2-24 11:32:59] [SleepNumber] Error: familyStatus GET request returned undefined. Error: {"code":"ECONNRESET","errno":"ECONNRESET","syscall":"read"}

Not sure if any of that helps.

DeeeeLAN commented 5 years ago

Those are some strange messages, and they seem completely different from the previous ones. Are you sure your username and password are correct? The fact it failed authentication twice is concerning. I am not sure why the event listeners warning exists, but I don't think it would cause the issues you are seeing. Are you saying that is the final message before it crashes? Try running it again then attaching a complete log file here. I want to see everything in order.

400HPMustang commented 5 years ago

I’m using the same un/pwd I use for the app and website. It works for a bit then blows up and my whole homebridge install goes unresponsive.

I’ll run it again in debug and I’ll email you the log, by the time it crashes my entire log is too big for pastebin. Probably going to be later today. It’s late in my time zone.

On Mar 2, 2019, at 11:13 PM, DeeeeLAN notifications@github.com wrote:

Those are some strange messages, and they seem completely different from the previous ones. Are you sure your username and password are correct? The fact it failed authentication twice is concerning. I am not sure why the event listeners warning exists, but I don't think it would cause the issues you are seeing. Are you saying that is the final message before it crashes? Try running it again then attaching a complete log file here. I want to see everything in order.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

DeeeeLAN commented 5 years ago

Yeah that is really strange, there is some isolated issue specific to your setup it seems. When you run it, can you disable all your other Homebridge devices? That will help cut down the log file a bit. You can upload files here, just drag and drop. Or email it if you don't want it to be public.

400HPMustang commented 5 years ago

Yeah I’ll disable everything else and just capture the bed logs. I’ll have them over to you. I agree this is weird. I was starting to wonder if this has to do with passing values for different bed models or something like that.

On Mar 2, 2019, at 11:29 PM, DeeeeLAN notifications@github.com wrote:

Yeah that is really strange, there is some isolated issue specific to your setup it seems. When you run it, can you disable all your other Homebridge devices? That will help cut down the log file a bit. You can upload files here, just drag and drop. Or email it if you don't want it to be public.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

400HPMustang commented 5 years ago

@DeeeeLAN I removed all of my plugins and ran homebridge in debug mode all last night and the plugin ran fine. I re-enabled my plugins this morning and everything has been running fine for the last 4 hours. I've used bed controls multiple times this morning/afternoon with no issues. Very weird. I'm going to watch things for another day or so and if I have no crashes I'll close this out. Thank you for everything.

400HPMustang commented 5 years ago

Output.zip Here are my logs. I had to sanitize some info but nothing related to your plugin. After working for a good portion of the day I started getting 401 errors that aren't explainable. The bed was working and responsive all morning and into early afternoon. Please take a look and let me know what you find out.

DeeeeLAN commented 5 years ago

That helped a lot. It looks like your authentication token expired possibly, but it threw a different error code than the one I had previously seen (401 vs 50002). I updated to check for this, so try updating and running it. With luck, it will be fixed and we can close this issue.

Note that I pushed a major update separate from this issue related to the power base, so it is possible you will run into other bugs that I haven't found yet. If you find something weird, let me know.

400HPMustang commented 5 years ago

@DeeeeLAN just updated and tried to re-run and got this:

[2019-3-3 18:32:39] ====================
[2019-3-3 18:32:39] ERROR LOADING PLUGIN homebridge-sleepiq:
[2019-3-3 18:32:39] C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge-sleepiq\index.js:166
            } else {
              ^^^^

SyntaxError: Unexpected token else
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Plugin.load (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\plugin.js:72:23)
    at Server.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:149:14)
    at Array.forEach (<anonymous>)
    at Server._loadPlugins (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:141:22)
    at new Server (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:57:24)
    at module.exports (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\cli.js:30:16)
    at Object.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\bin\homebridge:17:22)
[2019-3-3 18:32:39] ====================

C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\api.js:122
      throw new Error("The requested platform '" + name + "' was not registered by any plugin.");
            ^
Error: The requested platform 'SleepNumber' was not registered by any plugin.
    at API.platform (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\api.js:122:13)
    at Server._loadPlatforms (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:316:45)
    at Server.run (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:86:36)
    at module.exports (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\lib\cli.js:45:10)
    at Object.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\homebridge\bin\homebridge:17:22)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
DeeeeLAN commented 5 years ago

Oops, missed a bracket. Try again.

400HPMustang commented 5 years ago

Oops, missed a bracket. Try again.

Got the latest. I'll let you know what turns up.

DeeeeLAN commented 5 years ago

so far so good?

400HPMustang commented 5 years ago

@DeeeeLAN so far so good. Been running in debug mode the last few days and nothing wonky in the logs, automations working fine, homebridge is stable. I think we're good. Closing this out. Thank you again!