Raspberry Pi with PHP (or Arduino/ESP8266/NodeMCU) to GPIO to Relay to Gate/Garage Trigger

Ok so I got it working with your stock code. Connected to smartthings and everything.

So when I followed boards documentation, it said to upload using generic esp. Ok, fine, tried that, but had to remove the D, from D1, D2, etc. for it to compile. So I did that and compiled, but it wouldn’t ever connect to wifi. So then when I tried to upload it as NodeMCU, it would compile, and flash, but never connect to wifi. Same behavior.

Well I just put the D back in and loaded with NodeMCU, and it’s working now.

@Synthesis did you try putting the D back in front of the #s before compiling with NodeMCU?

I was finally able to get my ESP8266 to flash. Tried this morning to connect to WiFi but it seems as though nothing happens. I’m going to try what TexAMR did and add the D’s back in and see if that makes a difference.
Should the LED flash or give some indication when it’s connected?

Wow! What a great thread! Smartthings has comes a LONG way since I first purchased my Gen1 hub!

I had a small question regarding this setup… I have two garage door switches in close proximity to one another and neither have switches for the lights. Can I use one the second “custom” switch for the second garage door instead of the light?

Also, for someone who is starting from scratch and only needs to control two garage doors (no lights), would the ESP8266 be the better route (less expensive, smaller). It’s an attached garage, so WiFi should work.

Thanks again! These ESP8266 modules look awesome! Browsing the forum, it looks like I’ll be integrating my house alarm and projector in the near future!

@ctdodge no light indicators when connecting to WiFi. That would be extra/custom code.

@DITPL you can do exactly as you asked. Yes the NodeMCU is much more economical and has a smaller footprint. Wifi reception becomes the main challenge.

@ctdodge no light indicators when connecting to WiFi. That would be extra/custom code.

So the only way I can tell if it connected is by looking at my router?

Does the rpi have to be on the same lan for it to work? I’ve plugged in the public ip of my rpi in smartthings, and can’t get the smartthings app to display any into on the pi. There are no errors in the logs, see below. (I redacted my ip) The pi is in a DMZ, and I can access the webpage from anywhere. This public ip is only temporary while I’m testing some different things.

a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug POST / HTTP/1.1 
Accept: */* 
User-Agent: Linux UPnP/1.0 SmartThings 
HOST: xx.xx.xx.xx:80 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 8 

Refresh=
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug The method is POST
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug POST body is: Refresh=
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug Uses which method: POST
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug The Header is [HOST:xx.xx.xx.xx:80, Content-Type:application/x-www-form-urlencoded]
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:24 PM: debug The device id configured is: 8102C804:0050
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:22 PM: debug Resetting tiles.
a6e71554-b8b4-4bcd-ae99-6f71e6b0ac00  1:21:20 PM: debug POST / HTTP/1.1

If u pull up the serial monitor in the arduino ide, you can see it connect in there. Keep your uart or ftdi connected and it will tell you what’s going on.

A long time ago I tested with an external IP. Worked fine but you never know when ST will lock down API’s. Start with a LAN device on the same subnet as the ST. Then once you prove success, go with external and verify with standard browsers along with Fiddler where you can compose HTTP comm messages.

OK, definitely making progress. I flashed the 8266 and it connects to wifi. I add a thing with your DTH. I guess the setup is wrong though because when I try any button it just says “trying” and then off. Looking at the serial monitor it has IP: 192.168.0.106; Use this URL to connect: http://192.168.0.106/; and HTTPUpdateServer ready! Open following location: http://192.168.0.106:81/update in your browser.

I have the DTH set up as follows:
Device IP Address: 192.168.0.106
Device Port: 81
URL Path: HTTP://192.168.0.106:81/
GET
Main trigger momentary: on
Main Pin number: 1
Custom trigger monentary: on
Custom pin number: 2
Everything else is off

When I go to My Home is shows as off, I hit the button and says trying for about 2 seconds then back to off
I go into the device itself and hit Main triggered and it just says trying
Does that look right?

Go her first, try the buttons with serial monitor open and see if they are activating. That will let you know if the esp is setup correctly. If that all works, then you can move on to making sure it works in smartthings.

What are/how do you get the BCM format pin#? I know the defaults are 4 and 21, but I’m not sure what those mean. Trying to modify the code to add more relays.

I modified the esp code, and have it all working from webpage. I’ve modified the device handler, but these pins is where I’m hung up. I don’t think they would have the same “BCM format pin”.

It’s only for the Raspberry Pi (and other Linux that supports gpio) PHP code sample, does not apply to any of the Arduino sketches.

I am able to see the ESP from my browser, I can click the buttons and the relay activates. When I try the same from ST I get no response. I’m guessing something is incorrect in my settings.

Obviously my IP is what it is, my port is 81. What do I enter for the URL path - the whole URL or something else? For the ESP I use “GET” - correct? Pin number in BCM format I have 1 for main and 2 for custom. Should it be JSON or HTML? Should I have User Auth enabled? I didn’t set up a userid or password in the code

Here is a picture of mine. Everything is default minus the IP, and “GET”

Then I had to hit refresh a few times all all was well.

Port is 80, not 81.

Looks like the port was indeed changed to 81 which should not be an issue… For any of the Arduino samples, all you have to do is change to GET instead of POST. Do not use BCM pins as I mentioned above. That will only be respected by PHP.

Still no go. Just to verify - this IS the correct DTH I should be using, right/

I tried removing from ST and re-pairing. That seems to go OK, set the config with my IP, Port and GET - with nothing else touched. I click buttons and it just says “trying”. I can access the 8266 from my browser at the stated IP and I can click buttons and see & hear the relays work, but from ST app I get nothing.

When I add the device in IDE I name it ESP8266, Device Network ID = ESP8266,Type = “Generic HTTP Device”, Location = Home, Hub = Home Hub, Hit create. Add a Thing, it sees the 8266, hit Save and configure.

Does it seem like I’m missing a crucial step?

It all looks right… here are the typical steps:

  1. Compile and flash my code as is… just to start with. Don’t modify pins, etc.
  2. Be on the same subnet as the ST hub.
  3. Add the DTH to ST IDE
  4. Create a new Device in ST and assign the DTH you created in step above. Scroll to bottom to find it. Give a random/unique ID to the device.
  5. Change POST (which is PHP only) to GET method in the newly created DT.
  6. Try refreshing and triggering while watching the logs in ST API
  7. Add more logging to the groovy code if need be.

I can promise you it works :slight_smile: but you are running a different chip then I am working with. Correct me if that’s wrong. I test on NodeMCU (both versions of chip) and WeMos D1 Mini clones.

UPDATE: try port 80 just in case… change minimal stuff first.

Hey port 80 just like @flyize recommended above is your first try… don’t change defaults unless you have to. In your case, port 81 is used by the IDE for OTA updates. This should explain all of your problems. Give it a shot and post back.

Would it be easy to add some code in the web UI that would allow us to choose which item goes in the ‘main’ SmartThings button? Right now, I’m using one simply for the DHT and would love to have the temperature displayed in the Things list rather than Off (which means nothing for DHT).

edit: “Easy” being a relative term, cause it would probably take me months to do that… :smiley: