0

I'm here because I couldn't find any answer anywhere and the problem seems pretty easy and hard in a same time.

I have a website, for exemple : My_website.host.fr I have arduino's sensors at home, for exemple temperature sensor in my garage, servomotor in shutter, etc... with Wifi-module.

I want to, as a User, access the website, update some information on the website, for exemple : I want the shutter down, so I put it to 0 on the website, and the arduino will, for exemple each X seconds check if the value has changed, if it does then it updates itself and so lower the shutter.

So, by this, i'll never have to connect directly through an @ip to my arduino, without hosting a server at home which could be hacked or anything, the arduino update itself with the infos that are on the website,

So from my arduino I must ? I have no idea, get the source code of the web page and search for some value, or, from the web page, update a file with PHP variables and retrieve that file with my arduino then read it for the values ?

I don't know if it's clear tho and I have no idea how to manage it.

Sorry about the bad english sentence or words, not main language;

Thank for the help i'm kind of lost.

  • 1
    You will have to make a web API. Make it as simple as possible. E.g. "GET /shutter" would return just 0 or 1. – Edgar Bonet Jun 28 '16 at 12:59
  • 1
    MQTT might be a good solution for this... – Majenko Jun 28 '16 at 13:09
  • You're in luck! A lot of people are doing, or trying to do similar things. One way of doing it is using a provider like adafruit.io. I imagine there are many other providers out there. Or will be. – jogco Jun 28 '16 at 13:34
  • Could you please provide more information about the server? Is this a website you own? If so, does your hosting provider allow you to put scripts? If so, in what language(s)? You mentioned PHP, is it supported by your provider? If so, do you know some PHP? I'm asking all this because your discussion with st2000 is revolving around scrapping data from HTML, which would be a very bad idea if you can easily have the server deliver text/plain. – Edgar Bonet Jul 1 '16 at 8:56
2

From your comment of Jul 1st, I understand that you can program your server in PHP. Then, and to expand on my own comments, I am only recommending that, whatever Web API you design, you keep it as simple as possible. For example, for telling the Arduino whether it should keep the shutter open or closed, you could write something like this in PHP:

header('Content-Type: text/plain');

if (user_wants_shutter_open())
    echo "open";
else
    echo "close";

In particular, it makes absolutely no sense to write a PHP program that generates an HTML document. Consider that the Arduino is a very low powered platform: there is no point in having it process more than a handful of bytes when you only want to communicate a single bit of information. And you should know that there is really nothing wrong with using HTTP to transport plain text (but you should use the header Content-Type: text/plain). If you want to send a more complex set of data, you could use something like text/tab-separated-values, or maybe even application/json.

Concerning web scrapping, it is a solution to a specific problem, the problem being that the server returns the information in a format that is not very well suited for machine consumption. You do not have this problem. Obviously, you could create the problem by having your PHP return an HTML document, and then you could apply the solution. My point is that it is better to avoid creating the problem in the first place: just return the information in a format that is as easy to parse as possible.

| improve this answer | |
1

I believe the term you want to search on is "web scraping". Assuming you are fine with people knowing the state of "things" in your home, you can simply leave the states up on your public web page. That is, you click on a button on your web page and change the text from "shutter up" to "shutter down". Mean while, your Arduino is "web scraping" the same page looking for "shutter" and acting on the next word "up" or "down".

In this blog, someone has posted his Arduino "web scrapping" code. I have not tried it, so do some research before considering this particular solution.

| improve this answer | |
  • Indeed it's web scraping ! Well, public people can access the states of my arduino's sensors right, first they have to know the site used to, the reals pages used to it (according on the fact that the website will be a food website fake pages). Just thinking that it gives so much more security isn't ? Connecting to your home @IP seems so unsafe, that anyone can access and even open doors... – Gastric penguin Jun 28 '16 at 16:32
  • Web scraping is for the case when you do not control the server, and have to extract the desired information from unstructured HTML. In this instance the OP controls the server. He can return the needed data in whatever format is easiest to digest for the Arduino. It would be silly to embed that data into an HTML document, only to have the Arduino remove all that crap through pattern matching. – Edgar Bonet Jun 28 '16 at 19:35
  • Agreed, but web scraping is an easy concept. And he may not have access to features like CGI scripts and scripting languages like PERL, ect on the web server computer. Also, he may not have a dedicated home IP address. So the web server (assumed located else where) may not be able to send information home (yes, there are dns look up services he could subscribe to to get around this). He can look into all these things and more if he needs to. But for getting started, I still think scraping is the easiest concept to grasp. – st2000 Jun 29 '16 at 4:26
  • So, If I understand well and to sum up all this, I must, with my arduino, get the SOURCE CODE of the page (can it be in php :V and so it retrieves the html output from server ?), then look for datas to seek and update itself considering the values of the datas ? You saying, that the easiest to control things in my home, would be to ssh the main that control the nodes ? Despite all the weakness it can has about security this is the easiest way ? Tho my apologies again about my bad spelling, and thank you for your help – Gastric penguin Jun 30 '16 at 16:29
  • I understood you wanted to control things in your home with an Arduino using a web page far removed from your home. I suggested you write a web page of which had text that changed through button presses. Then to have your Arduino periodically read the web page using HTTP. I did not say anything about a Secure SHell layer (SSH). After all, what's to keep secret? Anybody can view this web page. Keep in mind there are many ways to do this. And if you are that interested in security, you may find an Arduino insufficient. – st2000 Jun 30 '16 at 21:27
1

Another option is Blynk who offer a server, a smartphone app, and a set of libraries and example sketches for Arduino. Also an active and helpful online user community, where the developers participate.

The server does not make view-able web pages; its job is to enable the Arduino and the app to communicate with each other.

The app lets the user quickly and easily configure a custom control panel which can communicate both ways with your Arduino.

The Arduino Blynk libraries can be installed and an example program compiled and uploaded a few minutes, with support for I/O port reading and writing already built-in. Online documentation describes how to expand the example code to do more specific things. Blynk is still under active development, meaning the documentation isn't always as detailed as one might like, that bugs are being fixed and occasional new ones appear, and new features are being developed.

I use it myself and teach other people how to, and I find it a really quick and easy to use platform for interactive remote control of my Arduino-based gadgets.

For example, I am using it right now to develop a ventilation controller for room- and window-fans. It will mix the room air in winter when the heat rises to the ceiling, and ventilate or just mix the room in summer depending on the floor, ceiling, and outdoor temperatures. It will report back to the smartphone which fans are on and off; allow me to turn any of them on or off; and display a history of the temperatures and fan states.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.