otaviojr / node-red-contrib-smartthings

Allows you to control your devices and get their status using NodeRed
MIT License
32 stars 16 forks source link

TypeError: Cannot read property 'token' of null #5

Closed gcaley closed 4 years ago

gcaley commented 4 years ago

Hi all, Ive tried running NodeRed as the standard DockerHub container and now also as a newbuilt Ubuntu 16.04, following the install for the latest node.js and all the requisites for NodeRed. I consistently get this error after configuring the SmartThings token

4 Nov 22:16:33 - [info] Server now running at http://127.0.0.1:1880/ HTTP REQUEST: devices: 3e19d.30b56663c : temperatureMeasurement TypeError: Cannot read property 'token' of null at /home/gcaley/node-red/node_modules/node-red-contrib-smartthings/smartthings/smartthings-config.js:97:21 at Layer.handle [as handle_request] (/home/gcaley/node-red/node_modules/express/lib/router/layer.js:95:5) at next (/home/gcaley/node-red/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/gcaley/node-red/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/home/gcaley/node-red/node_modules/express/lib/router/layer.js:95:5) at /home/gcaley/node-red/node_modules/express/lib/router/index.js:281:22 at param (/home/gcaley/node-red/node_modules/express/lib/router/index.js:354:14) at param (/home/gcaley/node-red/node_modules/express/lib/router/index.js:365:14) at param (/home/gcaley/node-red/node_modules/express/lib/router/index.js:365:14) at Function.process_params (/home/gcaley/node-red/node_modules/express/lib/router/index.js:410:3) at next (/home/gcaley/node-red/node_modules/express/lib/router/index.js:275:10) at expressInit (/home/gcaley/node-red/node_modules/express/lib/middleware/init.js:40:5) at Layer.handle [as handle_request] (/home/gcaley/node-red/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/gcaley/node-red/node_modules/express/lib/router/index.js:317:13) at /home/gcaley/node-red/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/gcaley/node-red/node_modules/express/lib/router/index.js:335:12) at next (/home/gcaley/node-red/node_modules/express/lib/router/index.js:275:10) at query (/home/gcaley/node-red/node_modules/express/lib/middleware/query.js:45:5) at Layer.handle [as handle_request] (/home/gcaley/node-red/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/gcaley/node-red/node_modules/express/lib/router/index.js:317:13) at /home/gcaley/node-red/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/gcaley/node-red/node_modules/express/lib/router/index.js:335:12)

4 Nov 22:26:00 - [info] Node-RED version: v1.0.3 4 Nov 22:26:00 - [info] Node.js version: v13.0.1 4 Nov 22:26:00 - [info] Linux 4.4.0-131-generic x64 LE 4 Nov 22:26:00 - [info] Loading palette nodes SmartthingsConfigNode 4 Nov 22:26:01 - [info] Settings file : /home/gcaley/.node-red/settings.js 4 Nov 22:26:01 - [info] Context store : 'default' [module=memory] 4 Nov 22:26:01 - [info] User directory : /home/gcaley/.node-red 4 Nov 22:26:01 - [warn] Projects disabled : editorTheme.projects.enabled=false 4 Nov 22:26:01 - [info] Flows file : /home/gcaley/.node-red/flows_nodered.json 4 Nov 22:26:01 - [info] Creating new flow file

I used the personal access token creation as mentioned in the docs, I assigned all the priveleges Any ideas? Thanks.

otaviojr commented 4 years ago

This error, on this line, indicate that you don't have select the account combo box with a valid config at temperature node.

Do you have?

Screenshot from 2019-11-05 00-37-54

It should be something like the picture above.

regards, Otávio Ribeiro

otaviojr commented 4 years ago

It's like the conf node once selected at the account combo could not be found.

Do you have more than one config? Do you have deleted some config?

I'm trying to understand what is going on...

regards, Otávio Ribeiro

otaviojr commented 4 years ago

Anyway I published a new npm version 0.0.8 which will suppress the error and return a 404. Which is the expected behavior...

regards, Otávio Ribeiro

gcaley commented 4 years ago

Thanks for the reply. I tried this with a new install, so no previous account. I created the account "SandyLane" entered the Token "acfa2a4a-2..." and then for the Device Properties I selected that created account, entered a name "Temp Test". The Device List box then says "Loading" and it is at this point I get the error above.

Ive just deleted node-red and re-installed (master branch). The i I reinstalled "npm install node-red-contrib-smartthings@0.0.8" . Strangely when i now create a ST node, it doesnt ask me to create an account, it goes straight to the device properties page, and i cant create an account, only enter an account name. Untitled

otaviojr commented 4 years ago

Hey man, my bad....

I'm uploading version 0.0.9 to solve this.... 0.0.8 was really with this problem...

gcaley commented 4 years ago

Ok thanks. That now stops the error appearing, but it just sits on the "Loading" message with no progress. Any ideas what i can check? I assume that ST is now returning the information based on the use of my token and the request made. Do you know the request that is made, i can try replicating it manually. I attach to the ST EU servers, could this be a problem (versus connecting to the US?)

otaviojr commented 4 years ago

Hi gcaley, did you manage to figure something out?

I've been trying to reproduce the problem, but, I can't...

Are you doing something unusual? Using subflows or something like that?

At the first time you have created your config, was inside the node?

regards, Otávio Ribeiro

gcaley commented 4 years ago

So I tried some debugging myself and decided to use the smartthings-node (in the container running node-red and with node-red-contrib-smartthings installed). With a sample script (below) and with my personal token, it works!! so the ST communication itself seems okay. I'm not a nodejs expert so this took about 3 hours googling :)

const smartthings = require("smartthings-node"); let st = new smartthings.SmartThings("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); st.devices.listDevicesByCapability('switch') .then(deviceList => { console.log(deviceList); })

Literally I installed node-red, nom installed your Smartthings code then went straight to the GUI and dragged a Temp sensor onto the flow, filled in the account details and token and the problem happens straight away.

gcaley commented 4 years ago

I'm investigating how I see the console.log messages from your JS scripts so I can debug further. The output through node-red's logs doesn't say anything other than HTTP request (even after turning debug level messages on), so I think need to work out how to use the node inspect command

otaviojr commented 4 years ago

Do you have saved your flow and deployed?

Can you save the flow, deploy it, even with errors, then, try to finish configuring the device.

Or, create a generic node, save and deploy the flow, only after the first deploy, add the temperature node and try to configure it...

regards, Otávio Ribeiro

gcaley commented 4 years ago

Ok, I’ll give that a try later.


From: Otávio Ribeiro notifications@github.com Sent: Thursday, November 7, 2019 3:47:22 PM To: otaviojr/node-red-contrib-smartthings node-red-contrib-smartthings@noreply.github.com Cc: Caley, Grant Grant.Caley@netapp.com; Author author@noreply.github.com Subject: Re: [otaviojr/node-red-contrib-smartthings] TypeError: Cannot read property 'token' of null (#5)

NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Do you have saved your flow and deployed?

Can you save the flow, deploy it, even with errors, then, try to finish configuring the device.

Or, create a generic node, save and deploy the flow, only after the first deploy, add the temperature node and try to configure it...

regards, Otávio Ribeiro

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/otaviojr/node-red-contrib-smartthings/issues/5?email_source=notifications&email_token=AAM7VMWNOFGQWJAZ6AOVRCDQSQ2AVA5CNFSM4JI25NQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDM3AJA#issuecomment-551137316, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAM7VMXOTDCNWOIHXOI7PNLQSQ2AVANCNFSM4JI25NQQ.

gcaley commented 4 years ago

Success! That works, if I deploy the flow then go back into that flow I then see the list of devices relevant to the selected Smartthings device type. Great news, thanks for the help with this. I will have a play this weekend and see what I can do next.