General area when it fits no where else

Moderator: Mmiscool

User avatar
By livetv
#48661 @forlotto

I like where you're going with this. If you want the server to be on your side of the router then we don't care about ports, just IP addresses just like you said.

forlotto wrote:So here is the idea to turn my ACUnit on:

This is sent from remote host first
http://serverip/prTGs21zw=0 "On for my ac"
http://serverip/prTGs21zw=1 "Off for my ac"
http://serverip/prTGs21zw=r "Read Status Of My AC"

The server will receive this and translate it to:
http://192.168.1.133/msg?pin=1stat=0 "on for ac"
http://192.168.1.133/msg?pin=1stat=1 "off for ac"
http://192.168.1.133/msg?stat=r "read ac status"


So I modified the previous code to do what you're suggesting (although I think you've malformed the requests to the ESPs. I think that ...msg?pin=1stat=1 should be ...msg?pin=1&stat=1).

Code: Select all$dev=array(
    array('name'=>'Gdoor', 'esp_ip'=>'192.168.1.133', 'pin'=>3 ),
    array('name'=>'ACunit', 'esp_ip'=>'192.168.1.133', 'pin'=>1 ),
    array('name'=>'Light1', 'esp_ip'=>'192.168.1.134', 'pin'=>1 )
    );

foreach ($dev as $k=>$v) {
    $cmd=$_REQUEST[$dev[$k]['name']];
    if ($cmd!='') {
        $url="http://" . $dev[$k]['esp_ip'] . "/msg?";
   if ($cmd!='r') $url .= "pin=" . $dev[$k]['pin'] . "&";
   $url .= "stat=" . $cmd;
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $output = curl_exec($curl);   
        curl_close($curl);
        print $output;
    }
}


You can replace the somewhat readable device names with anything more cryptic if you like. This code supports multiple ESPs having different ip addresses on your local subnet and keeps track of the proper pin for each device. I'm doing something similar but more complex, allowing control of pwo, servo, temp, etc. in addition to digital I/O.

When you request the status of a pin, the target ESP can just return that to the server which will echo it to your browser. You could have the server generate a page using AJAX to make all those on/off/r calls for you at the click of a button. Not hard if you know javascript and then you have one nifty single page control panel with buttons and status displays for all your devices - and which works on your PC or phone with no typing necessary.
User avatar
By forlotto
#49351 Excellent thanks livetv

I am curious what your setup is I think a full featured php setup for basic would be an excellent project one that would basically do translation, control, etc of all necessary data as well as echoing return data.

As you explained pwo I think everything is pretty much covered by your example here except the echoing of data to the browser how to request and echo html data in its entirety for instance if I were to use a black background and green text maintain all html data and have it echoed there may be something on stack exchange but your example seems to be fairly bang up if I am reading it right.

I recall doing echoing for a timer based page that I was going to try to do purely in java and html but kinda got stuck and wasted far too much time trying to figure it out. The code was all just the form data that I managed to research. Next came the hangup how to translate it to the database to properly setup 10 timers for each day of each week for 8 separate pins. Just far to much handling for me at the time I have zero experience working with weekly timer code. Not that I am asking for a handout here on the weekly timer front. But the short of it is I echoed the data back in a nice neat table errr but can't remember how I did it...
errrr not so sure on echoing the page as is to the browser but this is most excellent a great start I see how I could use a key for each command to each ip with each value!

I still have one more question other than how to echo data...

What are the limitations of the array your shared how many elements per key how many keys total I suspect once I get rolling I will have quite a few requests stored in this array 1 for each on/off for each pin on each device and 1 read possibly some pwo as well either way this is a great start to something.

reminds me a bit of the lua code I used when first starting off with esp8266
User avatar
By livetv
#49515
forlotto wrote:What are the limitations of the array your shared how many elements per key how many keys total I suspect once I get rolling I will have quite a few requests stored in this array 1 for each on/off for each pin on each device and 1 read possibly some pwo as well either way this is a great start to something


Practically speaking, there is no limit to the array (except server space but unless you're thinking about tens of thousands of devices, this is not an issue). Just add more lines in the format you see... Just no comma on the very last one.

As for echos back to your browser, the current code echoes whatever the ESP addressed returns on the web call. That may be a bit ungainly as you noticed if you have several of these handling many devices. What you could do is consolidate values in a database (or even a text file) on the server and have it return a formatted table. The code for this is fairly simple but dependent on what you want to see and it might not be too short.

Another way would be to initiate the call to the server through AJAX in your browser. The code above does not change, but then you'd have to have your browser accept the response from a device and update a line in a table. The flow would start with a call to the server which returns the status of all devices in the form of a table and it returns the javascript that both powers the AJAX calls and updates the table with ESP responses.

Does that help?
User avatar
By forlotto
#49577 Ahhh interesting so it will return the correct information from the response thus showing the status of stuff already if I am using msg branch it should get the return message and display it properly within the browser wow quite the solution really just a matter of application now.

Good to know that there is almost no limitation with the exception of having so many wireless devices that I would likely microwave myself in my own home excellent that was the answer I was hoping for.

Thank You very much for the follow up livetv I will have to see what I can do in the future as of now there are some things I feel I need to learn before going all in but this is an excellent start.

I see one fella requesting MQTT support and kingdem pretty much dumped the keys to the kingdem and a better understanding however what leaves me a bit on the sidelines with MQTT is that it requires a third party server called a broker unless I were to host that broker I'd prefer to steer clear for obvious reasons. Its moving way too close to someone grabbing statistics down to when I wipe my @zz ... Not that it isn't a great technology but hey why should someone know when I turn my lights on/off and possibly sell that data collected to the highest bidder so they can solicit products or get statistics for some crazy computer simulation on how to perfectly control the masses. With great data comes great power I think we already share enough against our will. I am in amazement how much people use this data already to pick out types of people and essentially exploit them.

I had a buddy in insurance sales that showed me papers on how they classify people to basically have an edge how right the data was about me seemed spooky enough to learn a few things from my habbits and how to break some of them so I am not such an obvious card. Not to mention these companies get rich off it in the process not that I am against capitalistic goals but gaining capitol by selling the actions of someone else no matter how it is done to me is worse than downloading and selling music second hand as you have crossed the line into someones personal life. That is equivalent not only to selling something second hand but breaking and entering with force (Force being the agreement to an EULA that no body reads mind you!) and pretty much legally stealing your info.

If you share some of them big profits with me I'd say have at it collect my data but me being able to post a message or a picture somewhere is hardly fair trade especially when they not only make money off of this but the targeted advertisements. To each their own but this is just the way I see it and believe others should see it as well. Not that I may not try it or am bent out of shape about it I guess the morality of it all is likely not going to fair well for society and future generations. One thing we should never give up if we want a decent quality of life is privacy and the ability to have some sanctuary and these types of things are incrementally moving in the opposite direction of that.

Sorry for the rant! But for the record I do now believe MQTT will be useful and likely there is a broker server that is open source as well.

I however will take the road less traveled and enjoy and thank you for your example.

Thanks livetv truly a blessing to see the example given it is a collage course in a post!

-forlotto