Go Down

Topic: Best way to Control an Arduino from Anywhere?? (Read 3624 times) previous topic - next topic

echi22

Hello! I am working on a project to control my home from any where in the world with internet access.

I've been able to make it work in my local wifi connection but now i want it to work with an external connection so that i can manage my home from everywhere.

I found this post http://forum.arduino.cc/index.php?topic=217398.0 and Im wondering if this is still the best solution since the post is two years old. I dont know how good is to use dynamic DNS service (like no-ip).

The first solution that came to my mind was to have a web page where i can access from everywhere and from there send a message to the arduino to turn on/off, etc.. The problem is that i dont know how to send the message from the server to the arduino since i dont have static connection.. I dont know if there is something that handles the communication between the server and the arduino in an easy way. I read about client sockets, polling, and other things.. but i dont know which is the best option..

So, the question is, which is the best option to control arduino from anywhere?

P.S. Sorry for my bad english :)

pylon

I don't know if the referred solution is the best for you but it's still the way to go if you want to contact your Arduino directly from anywhere in the world.

The other way (which is more secure) involves a publicly available web server which you control. You can install a web application on that server and also install a simple server on a different port that just listens for your Arduino to connect. Once that connection is established you may send any command received over the web page to your Arduino. That way you don't have to open your home firewall for incoming connections and if you need additional security you may implement a simple protocol that authenticates the Arduino before sending it commands.

echi22

Thank you for your answer..

Ok, so if i have a web server, is it possible for the Arduino to keep the connection with the server "for ever"? How can I do that? what language should i use in the server?

PaulS

Quote
is it possible for the Arduino to keep the connection with the server "for ever"?
Like, when you use google to search for something? Clearly, the normal use case says no. The client make a connection when it makes a GET request.

Even if the connection were persistent, that does not necessarily mean that the server can push data to it.

The best solution is to have your ISP assign you a fixed IP address (for your router). Typically, the ISP will want to charge you more for a fixed IP address, because they KNOW that the reason you want one is so that you can run a server.

The next best solution is to use the dynamic DNS service mention in that post, where the IP address of your router is change in the DNS table whenever your ISP assigns you a new IP address.

The worst solution is the one you are proposing. If you can even figure out how to make it work.
The art of getting good answers lies in asking good questions.

echi22

I made a research about this topic in google,

but when I read this
Once that connection is established you may send any command received over the web page to your Arduino.
i thought that maybe there was a way to do that.. I just asked..

"The worst solution is the one you are proposing. If you can even figure out how to make it work."

Maybe it can work if the arduino regularly makes a GET to the server asking if something has changed.. I wanted to know if that was better than the dynamic DNS solution..

Thank you for your response!

pylon

@PaulS: Not every connection over an IP network has to use the HTTP protocol. I suggested a simple TCP connection (often simplifyingly called Telnet connection) between the Arduino and the server. The solution with having a server in the public internet where the mobile client connects via web calls and the Arduino via a persistent TCP connection is definitely not the worst solution but definitely also not the easiest.

Quote
Ok, so if i have a web server, is it possible for the Arduino to keep the connection with the server "for ever"?
If you just have a web server that's not so easy but if you have an internet server that you control you can host other server processes on it not just web serving ones.

Even a standard TCP connection is not forever but it may last for a very long time given your internet connection is stable enough. So I guess this is what you meant by the quotes.

Quote
what language should i use in the server?
The one you best know. You can even do that in PHP but I personally discourage you from doing that. But Perl, Python, Ruby, Java, C++, Go, etc. would be a good fit if you have some experience in using it.
If you don't know any of these languages maybe it's better to start with an easier project to get familiar with server programming.

INTP

I use mqtt pub/sub and esp8266 modules instead of Arduinos. More secure than any method requiring a server behind your firewall.

floresta

Quote
I've been able to make it work in my local wifi connection but now i want it to work with an external connection so that i can manage my home from everywhere.
The previous post beat me to the punch.  I'm just getting started with MQTT and it looks to me as if this is currently the best solution as it gets around the need to deal with dynamic ip addresses and port forwarding.

Don

pylon

Quote
I'm just getting started with MQTT and it looks to me as if this is currently the best solution as it gets around the need to deal with dynamic ip addresses and port forwarding.
MQTT is just another protocol and it doesn't solve any of the problems you quoted. The solution is the one I drafted earlier: Get a server in the public internet and connect to it from the Arduino and let that server serve the clients. That way you have just outgoing connections from your LAN. The protocol you use for that connection is secondary. It may even be HTTP but the OP has the need to push something back to the Arduino, so a pulling-only protocol like HTTP isn't optimal. It's his decision if the overhead of a full fledged protocol like MQTT is necessary in it's application and it's about as qualified for the job as HTTP is because the sensor node (which the Arduino is in the MQTT scenario) doesn't get informed immediately but pulls it's information.

Watcher

#9
Dec 19, 2016, 09:22 pm Last Edit: Dec 19, 2016, 09:24 pm by Watcher
I have a similar setup as well. However one has to consider cybersecurity as well. The way i do it is I establish a VPN secure channel from anyware with Internet connectivity, even my smart phone. Once vpn is established the remote client gets a local ip address as if it was connected to the same lan as my arduino's ethernet shield. Then i can access my webserver runnung on my arduino as if i was at home.

Edit: The above means you have to have vpn enabled router at home properly configured.

pylon

@Watcher: The setup of a VPN on the home router as well as on it's mobile devices is usually not feasible for the average user. Also none of the current smartphone OS offer VPN connectivity off-the-shelf (L2TP and PPTP are not considered secure for years) so accessing an Arduino on the home network using a VPN is out of reach for the majority of Arduino users.

Watcher

Hi pylon:)

I agree with you that setting up a vpn at both ends can be a bit tricky.

As for smartphones and tablets however, in the case of the android platform that I am using,there are lots of free VPN clients. I am using OpenVPN for android which is free and can be downloaded just like any other app. I am using SSL VPN which I believe is secure enough for my needs (obviously debatable!)

Nevertheless I wanted to point out that just freely opening up you home network for remote access is not such a good idea.

Go Up