- Thu Sep 17, 2015 4:42 am
#29225
You've just run into the classic beginner's problem on a forum where you've asked in quite a confused way about something relatively complex, which means the answer is probably going to be quite complex and so people don't respond because it's going to take too much time.
But I'll try to give you some pointers for how to approach solving the problem on your own because it's doable, but you need to get it clear how all of this stuff works (not meaning to be patronising, just honest!). I haven't used lua on NodeMCU so can't give you specifics, but once you break down your problem then it should be pretty easy to ask on the NodeMCU part of the forum.
So, you want to click a button on a website and have something happen on the ESP. The solution depends on how quick you need the response to be. If it's not urgent, then you can store the value of the switch on the server and then have the ESP poll using HTTP occasionally and checking the value. There are a bunch of services out there which will let you do this (search for IoT platform) but Thingspeak is probably easiest at this point (though it pains me to say that...) if you don't want to build it yourself.
If you want an immediate response, then you want to keep a socket open to the web server which can then push out a message as soon as the switch changes state. This is more complex on the server side, but again, there are a bunch of services you could use to do this part so you don't have to build it yourself.
So that should get you started. If you look for examples on either making a HTTP request form lua or keeping a socket open it should get you going.
Hope that helps,
Ben