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

clearly I didn’t read well enough and didn’t update the php file.
my bad - thanks for the quick follow-up!

Howdy @JZst, how’ve your been, I have a quick question regarding your HTTP device type, is it possible to just make a http get request to a fix endpoint without parsing back anything? I’ve just discovered the ESP8266 and it is way cheaper than an RPi, it has wifi and can host a webserver on its own.

EDIT: please disregard, successfully implemented :slight_smile:

Seriously :slight_smile: does it really run PHP on that tiny wifi thing?

Please let me know, VERY interested! Nice cheap alternative and you can hide this in walls/electrical-boxes, etc. unlike the larger Pi.

I’m not sure if it can run PHP, but I’ve tested with either LUA (using ESPtool) or C++ (using Arduino IDE)

It works great for triggering GPIO pins, what I did was I created a webserver on an ESP8266 that control a pin, then use your HTTP device to send GET request to that server and trigger the pin.

This is the device I purchased

EDIT: I think you can still use PHP on a host machine like RPi, then from within the PHP, “curl” to that local endpoint on ESP8266.

I see, so like a remote GPIO controller… very cool, thanks for sharing! The reason for my PHP question was because I thought you were literally using my index.php on that tiny board. Doesn’t seem to be the case, however, it is a remotely capable relay (and it’s wifi) which is definitely of interest. Thanks again!

Yeah I only use the groovy code to send HTTP requests to those tiny boards, anyway I’m buying a handful of them now to make all my IR controlled appliances smart :smiley:

Again thanks for your HTTP device type.

You’re most welcome!

I totally bought the Amazon toy, dangit :slight_smile: if you’re hosting any sample code, or if able to PM me some code sample, I’d really appreciate it. You’re doing it the way I see myself using it (via HTTP for ease of access) and I’d love a nice head start on that code.

All the best!

Yeah absolutelty, but the code is mostly examples and I just modify a little to fit my needs.

This is the sketch I used on a node. Check out IRsend irsend(2), I have a IR LED on GPIO2. SO after I compile and upload it to an ESP8266 node, I get a webserver in pure HTML and some buttons, now from the ST HTTP device handler of yours, I just send a GET request to that path http://192.168.29.124/ir?raw=123456789, then eventually it’ll trigger the GPIO pin.

Basically you only need to connect the board to your pc and use Arduino IDE to program. I can write up the steps I performed if you like.

Been looking for hours at the toy and wow, these get smaller and smaller with many more bells and whistles minus the high price.

The only question that nobody seems to concentrate on or document in detail is simply how to connect the nodeMCU to the local WiFi. Is that via the Esplorer tool?

I may pose a few questions once the thing arrives in a few days, if you don’t mind — and I certainly don’t mind hijacking my own thread when in reality it may expand my/this project to possibly include MQTT rather than just HTTP, but we’ll see.

Haha you’re right, let’s create another thread when you receive the boards. Anyway, there’s currently 2 ways to program this ESP8266, one using LUA via Esplorer and one using C++ via Arduino IDE. I prefer the latter one simply because I couldn’t find any example codes in LUA :smile:

For Wifi connectivity (demonstrated using webserver), if you flash the board to Nodemcu and use LUA via Esplorer, you can use this example to connect to wifi, very straight forward. Or if you prefer Arduino type, use this example to deploy one.

A big different between those 2 is:

  • In esplorer using LUA, you only flash the board once, and then an OS is deployed to the node, which means you can run scripts in real-time. If you want the script to run on boot, simply create a file called “init.lua”.
  • In Arduino IDE using C++, you compile your program and upload it to the board each time you change the code (sort of flashing it), and to run that program on boot, just make sure you leave GPIO0 empty.

Just try them out and see what you like. Also hit me up anytime :slight_smile:

i ordered 2 boards as well, I should get them tomorrow . Will probably go the c++ route. I use and Arduino and Raspberry talking over rf24 but it’s not giving me the range I want . So maybe this will be better.

FYI, same product at less than $5 but gotta wait for China shipping. http://www.ebay.com/itm/191607499973

I really like what @Casper is doing with IR and how straight forward that seems. Very flexible alternative to the Logitech Harmony products.

@Casper, definitely start a thread because we’ll be controlling our TV’s via SmartThings soon enough :slight_smile:

Yeah ebay definitely has lower price, but I have Prime membership on Amazon so can’t beat 8 bucks and free 2 days shipping.

I’ve been controlling my living room TV with this Echo + ST + IR transmitter using your HTTP device, also last night I just finished editing your code to create the fan device type on ESP8266, works great.

That is VERY cool! I will be messing with this soon enough :slight_smile:

I have Prime also but my need is to tinker and not super immediate. You should definitely start up a new device thread with the ESP8266. I may be able to help with some generic device which allows creation of as many buttons as you want in the child device and each button can have a different/unique function.

I just played with @blebson’s new D-Link code (awesome VIDEO integration) which uses child devices and it seems that the number of buttons and their definition can dynamic but not 100% sure on that.

Unfortunately it’s not dynamic, each camera has it’s own unique DTH which is called by the child SmartApp.

Yeah I thought I’d have to take that statement back :slight_smile: there’s no way to do an array and build tiles/commands dynamically. You’d think that’s a reasonable ability to have in this sort of an environment.

Maybe at some point in the future :slight_smile:

Thanks to @Casper and pointing out that I should be doing createEvent and sendEvent with “switch” because that’s the capability of this device and automation/other-apps look for that state not “mainswitch” like I had. Anyway the code has been updated with a simplified way of allowing voice control to run against either the main switch or optionally ON will toggle main switch while the OFF voice command will toggle the custom switch.

BTW, check out @Casper’s IR project with an ESP8266 using this same technique to do an HTTP GET to that tiny wifi Arduino-like board… super-cool implementation and I’ll be messing with a lot more of this for the few buttons on each remote control that are either too far from my lazy reach or lost in the dark. More importantly, I’m looking for Alexa controlled. I bugged him to put this project/post up because it’s way too cool of a project, thanks for doing that buddy and making it easier for a quick start when the toys get here.

1 Like

Code updated for full ESP8266 / NodeMCU support. It’s pretty solid with 3.3v relays in accomplishing the same thing as the Raspberry Pi does with the 5v relays. It connects/restarts super-fast too. I will update the post once I truly put this device to work in my Garage for triggering the door & the light as I wanted.

What to expect: changing of pins is NOT available and would have to be done via Arduino sketch changes (code sample now supplied by me). Currently D1 and D2 are the pins for main & custom buttons. No status tiles will work as this device has no OS. However, I did successfully incorporate the reboot feature. I
could not incorporate authentication because this isn’t really PHP with it’s
nice API’s. I am not nuts enough to program HTTP auth (base64
encoding/decoding) in C++ for this project ---- FIXED ---- see line 80 of the Arduino sketch :slight_smile: just a bit out of scope even if I could find the code online.

Enjoy and as always feel free to give feedback.

UPDATE: I modified the first post with more info about the NodeMCU support.

2016-06-18 — Arduino code updated to include (but comment out) ability to do HTTP basic authentication.

I also updated the first post with some stuff along with pics & wiring diagrams, etc.