Connect wired alarm system sensors to SmartThings with a NodeMCU ESP8266 [deprecated]

@heythisisnate Yes, I’ve noticed the same issue.

Edited: I see that you have updated your code. I will try that and let you know how it goes. Thanks again!!

I just added a lot of documentation and a step-by-step how to setup guide on my Github project:

I hope this helps those of you who were intimidated to try it. Post here with any questions/feedback.

1 Like

I got the following error trying to generate the token

Oh No! Something Went Wrong!
500: Internal Server Error
Reference Id
**************************** (No idea if I need to keep that secure)
Tue Feb 07 21:59:33 UTC 2017

edit: Turns out that error is because I’m dumb. I forgot to save the SmartApp after enabling OAuth.

@flyize This looks like an error internal to SmartThings platform. Are you sure that you “published” the SmartApp first before trying the OAuth flow? I saw a similar error once when I forgot to click publish.

Edited my edit so that it’s more obvious. You were correct.

Now I’m having issues with ESPlorer. Mine shows that it’s connected to COM4, but every time I try to upload something, it just shows the word ERROR after each line.

I tried another program and it doesn’t seem to be working either. How do I determine if its my lack of knowledge or a bad board?

Thank you @flyize and @Raymond_Lopez for helping with the details over DM! We’ve found a couple problems, and I just updated the README with more complete instructions.

  1. I left out the step about flashing the NodeMCU firmware. I didn’t originally think this was necessary but apparently it is! Before you can load the lua code, you have to re-flash the device’s firmware.
  2. Since I wrote this code, it looks like the NodeMCU firmware team has released a new major version, 2.0.0, which apparently has some compatibility problems with the HTTP library :cry:. For that reason, I’ve included the exact firmware binary in my repo that I know works.

When I have some time I’ll look into debugging my application on the newer firmware.

I hope this helps anyone who was blocked on this.


Just a FYI for anyone using this, I made a couple minor updates to my code and documentation this morning based on some feedback from the community. It’s all on Github. Enjoy!

Nate, the write up is excellent. the only issue im experiencing now is the smart app not updating the device status. The testing with the pins show open and close on esplorer but its not getting updated to smartthings. I have went through the whole process twice re-doing the device handlers, devices and smartapp. Using the get and post test works perfect also. It seems that they may be an error in the background with the smartapp not communicating. any way to pull logs and show if its making communication with the smartthings api?

nevermind its working perfect now. I did the device handler, smart app allover again and its working. again, thanks for this write up.

I’m glad you got it working. I’m on the road today so sorry I haven’t been able help more. If you still have problems later feel free to DM me.

First of all - thanks for the excellent write up - I got most of the things done… struggled with a bad USB cable and almost gave up, but persevered and I have the firmware flashed…

Coming to the problem - I am unable to move forward on the Oauth - I keep getting the 500: Internal server error… Have been trying various things like making sure the cloud sensor smart app is saved and published… but havent had any luck…

Any other tips to debug this will be appreciated!

No thread hijack intended. Great work by @heythisisnate on his solution! Nothing but respect for his work, as it has opened my eyes to other possibilities.

Here is another possible option for those already familiar with the Arduino ThingShield platform. My new library does all of its communications via the hub. I am not saying one method is better than another. I am just providing this as an option for using a NodeMCU ESP8266 with SmartThings, via the Arduino IDE.

Re-did Step 5 ( Oauth code generation) and thing started to work!

I’ve redone everything twice now, and it all works until I test one of the pins and it will say “Front Door is 0” then keeps returning “HTTP client: Connection timeout” Any thoughts on what I screwed up?

check to make sure your Oauth steps were correct. this most likely means it cant communicate to the smartthings portal. At least this was my case and once i re-ran the process again it worked.

@ogiewon Thanks! Actually your ST_Anything 1.0 project was my inspiration for this. I got my first ST hub in early January and came across your posts/project around that time. It got me hooked on the idea of connecting ST to my wired alarm system. I was disappointed that the ThingShield could no longer be purchased, so thats when I started exploring options with the ESP8266. It’s great to see that your ST_Anything project now works via LAN, because it does look like it does a lot more than just simple contact/motion sensors and has quite a community following. Well done!

I’m very interested how your code sends network requests to the hub. I couldn’t find any ST documentation on that. Everything I read pointed to using OAuth for HTTP communication. Is this documented? Can you point me to the file in your Github that does the actual HTTP calls (I looked briefly, couldn’t find it)?

There are some distinct advantages of using OAuth API calls instead of direct to hub communication. You don’t have to set any static IP address assignments on your LAN. Also, the device doesn’t even have to be on the same LAN as your hub. This could be really useful if you wanted to monitor things in remote locations but not set up a whole new hub there.

Thanks for the note and keep hacking away on this stuff! You guys are a key part of what makes this community great. I also love the fact that you work on ST_Anything with your son. I very much hope to get my daughters into coding one day … but they’re still a little young for that. We’re focusing on reading first. :wink:

1 Like

@Nate_Newsome I have seen infrequent HTTP timeouts in normal operation (the code is setup to handle/retry in this case), but you shouldn’t be seeing every request timeout. I’m not sure exactly what could be causing that. A couple things to check:

  1. Are you using the right firmware version? @flyize reported similar HTTP timeout messages last week and using the firmware I provided in my Github fixed it.
  2. Is TLS/SSL enabled in your NodeMCU firmware? When it boots and connects you should see SSL: true near the build version output.
  3. Try removing the :443 from the end of the apiHost variable. It shouldn’t matter, but maybe this causes problems with HTTP connections. Port 443 is the default for SSL anyway.
  4. Don’t forget to add /event to the end of the url given to you from ST when setting the apiUrl variable.

If you can’t figure out the problem DM me a screenshot of your variables.lua file and I’ll see if I can spot anything.

@heythisisnate Thank you for putting this together and trouble shooting everyone’s issues.

I’m having an issue getting the init.lua file to run and get the following Error

lua: error loading module ‘credentials’ from file ‘credentials.lua’:
credentials.lua:1: unexpected symbol near '�’
stack traceback:
[C]: ?
[C]: in function 'require’
init.lua:1: in main chunk
[C]: ?

An example of my credentials.lua is

wifi_ssid = “MySSID”
wifi_password = “MyP@ssword!”
auth_token = “11aaa111-11a1-11a1-111a-a111a11a11aa”

I was wondering if the Special Characters in my password could be causing issues or if something else could be the roor? I do use @ and ! in my password.



Take a look in my new “SmartThings” v2.0 Arduino library and you will see the code that communicates with the hub. Also, in the “extras” folder of that library you will find the groovy Device Handler examples that correspond to the sketches found in the “Examples” folder.

The “SmartThings” library is truly a standalone package. My “ST_Anything” library depends heavily upon it, but users can indeed use the new “SmartThings” library without it.

And to answer your question about documentation, I have not found anything specific regarding this approach. I found another user’s example and based my work on his.