General area when it fits no where else

Moderator: Mmiscool

User avatar
By livetv
#48603
forlotto wrote:It would be great to see some examples of people with servers that can control all of their esp's from the outside world using their server.


That is what I have in mind and hope to have it working by mid-June. Some of it is done already but not tested. I use php and mysql a lot and I might be able to post a simplified version that people can adapt to their general use.

forlotto wrote:I have a bit of trouble comprehending the operation of requests remotely.


There are many ways of doing this. For a sensor to initiate a report is a simple wget() matter. Alternatively you can use one ESP as a clearing house for all ESPs on the subnet and it does Wget() reporting or perhaps uses web sockets. However, controlling the ESP remotely from the web is a different matter with different possibilities.

1. You could set up port forwarding on the router to send requests to the correct ESP based on port number. One problem with this port blocking by some ISPs.

2. You could port forward to just 1 ESP which relays commands via messages to the proper recipients, but there is a loss of speed. An advantage to this is that you can put more of the brains in that host ESP, having it handle decisions about alerts, etc.

3. I like the idea of using web sockets, but I don't yet know if there's a way to open a socket between 2 ESPs instead of 1 ESP and a browser. If this can be done, it opens astounding possibilities!

4. Where speed is not important, you could plant instructions on the server that nodes call in to when reporting. A reporting ESP simply passes an ID with its payload and receives any instructions in its "mailbox". This would be suitable for situations like AC, furnace, and water heater control when you are away from the house and polling every few minutes is an option.

There is the issue of static verses dynamic IP addresses with your ISP. If you have a static IP, no problem. If not, you could have the php script on your server receiving updates just read the IP address of your router and have the facility to report it.

One must decide where the brains of the operation will be. Will one ESP be the broker, handling traffic and making decisions? Will a server host a web site that offers all functionality? Will there be a more direct connection between ESPs on a subnet and a remote browser? There are pros and cons each way and it really does depend on what you want to do.

I'm setting up a system to remotely monitor a house and control some devices. I'll have each ESP report to a server which uses php and mysql to log the data and read the router IP address. The same server will serve up a web page accessible to a remote browser, showing sensor data, history, and a control panel for remote devices. AJAX calls (with the router IP implanted by the web server) will provide calls through the router to the ESP devices. The same server will be able to send alerts via e-mail or text if something is awry at the house.
User avatar
By villTech
#48605 have a look here, controlling esp from outside world:
viewtopic.php?f=32&t=7250&start=12#p37368

from the example, if you want to control multiple esp8266s, you can create multiple "data.json" file i.e.. data0.json, data1.json, on so on.

then on each esp, do a GET request like:
esp0: http://{server ip}/data0.json
esp1: http://{server ip}/data1.json
espn: http://{server ip}/datan.json

or you can use dbms like mysql for better data handling and php for db manipulation.

same set up from the linked thread i have in my local servers. but with mysql.

once your esp is connected to a server (local or online), you can control it regardless of its ip.
User avatar
By forlotto
#48627 So the easiest way is port forwarding to specific ports designated for each device no server required from what I can tell and then accessing them http://wanip:PORT/OtherInfoHere... Setting up port forwarding in the router is relatively easy...

However I still maintain that a server is going to be more secure.

None of these examples accomplish what I deem as useful in my case to me they are overly complex far to many elements.

The elements I want are relatively simple.

Send a get have it directed by the server based on URL to the resource on the local network and then return or respond with all relevant data. So for instance.

I want to type http://serverip/ACunit/On and have it translate the get and then get the appropriate link that will turn the unit on really simple!

I also want to type http://serverip/ACunit/status and have it return the status page I am thinking this should be as simple as hosting a page with an iframe that would load internal resource.
So I may have to get a bit more involved with this one instead I may have to take a snapshot of the page or scrape the page and output the data in another format unless I were to forward each device to a specific port.

What has been given as an example is not really in my eyes a good method once you have to start forwarding ports you might as well not even have a server imho the devices can function and return data without the need for the extras a relatively simple thing. The server is there to act as a barrier between the internet and the devices a tunnel if you will that can be a bit more easily monitored and a bit more difficult to penetrate without the knowledge of it happening at the very least. I suppose a router with good logging procedures would let you in on the penetration as well possibly IDK but as mmiscool points to give the server a route to the internal only network of IOT only via specific command sets and you should remain fairly secure providing you have a secure server.

So to recap this is what I want:

Server to translate a remote request to a local request and then preform the request to turn a device on or off. And if there is data to be returned such as temp or status of device etc... Have that data scraped or gathered locally somehow and then returned externally.

What I don't want:

To use is third party services just me and the server handling communications no dweet.io no thingspeak no thinger.io none of this as it is all really not relevant or needed for any IOT... Just another company imho collecting data about you and advertising eventually to score tons of traffic, cash, etc... When the solution is likely a lot more simplistic than you think.
Just me remotely to my local home server that communicates with my local IOT devices based on rules keeping them secure from the internet on my intranet if you will just talking about it outlout has given me some ideas.

I would like to thank all of you for the responses even though I have not settled on a solution at least I am able to better define my goals for myself if anything thus narrowing down my search of how to a bit so I can finally get started in doing so.

One more thing I would love to accomplish is timed events from the server as well. It would be great to see an example of a server based weekly timer as well anyways thanks guys!
User avatar
By livetv
#48638
forlotto wrote:However I still maintain that a server is going to be more secure.


This still concerns me. Unless the server is on your side of the router and SSL capable, the traffic is still in the open (unless we can do SSL to an ESP). I'm not sure that you aren't any better off to have a simple web page with AJAX powered buttons on it to do the actual work. But a server will get you scheduled tasks and deal with dynamic IP addresses.

When I'm forced to use unencrypted data transmission and I don't want some clown opening and closing my garage door constantly at 2:30am (just an example), I encode commands with rotating keys. A pain.


forlotto wrote:I want to type http://serverip/ACunit/On and have it translate the get and then get the appropriate link that will turn the unit on really simple!


You can do this with PHP although I'd modify the command line a little:

http://{serveraddress}/?ACunit=ON

The PHP has a bit of code that looks for your devices, like:

Code: Select all$dev=array(
    array('name'=>'Gdoor', 'esp_port'=>81,'device'=>3 ),
    array('name'=>'ACunit', 'esp_port'=>81,'device'=>1 ),
    array('name'=>'Light1', 'esp_port'=>82,'device'=>1 )
    );

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


This will allow you to define (in the array) a set of device names, the ESP which supports the device (by port forward number), and the device number on the ESP (assuming that one ESP can handle more than one device). The code looks for a device in your command line and assembles a URL including port number, device number, and command) passes on the command for that device to the ESP itself before gathering the ESP's response and returning it to you as output.

Is this the kind of thing you need? You still want to add code to store the current IP of your router (to put into the $ip variable) but that's the guts of it.