S
S
Sprite1052014-07-09 20:37:39
PHP
Sprite105, 2014-07-09 20:37:39

How to control Arduino from internet?

Hello forumers!
Soon I'm leaving for vacation, I live in the private sector, and I have some household. So, the essence of the problem is that I understand electronics, radio engineering, but not very much with programming. I made engines, everything works with a bang to open the doors, but you need to turn on this miracle via the Internet. I looked in the direction of Arduino, I think it will be 100% suitable for my task.
At home, the server works around the clock, so I want the arduina to contact the server folder (OpenServer) and read the numbers from the file (As I understand it, it won’t work any other way). All I can do is organize a php + html page with some values ​​written to a file.
So, the question is, "How to write a program for arduino, what would we say with 6 lines of a file with values ​​0 or 1 on / off the relay?"
There is this code in index.php on the server:

<?
$file = fopen ("config.txt","r+"); 
if ($file) 
{ 
// Считываем содержимое в массив, разбиение происходит по строкам 
$file_array = file("config.txt"); 
// заменяем строку, например 3-ую 
$p =intval($_GET['p']); 

//Код записи значений до 10 строки..
if ($p==1) {$file_array[1]="1\r\n";}
elseif ($p==2) {$file_array[2]="1\r\n";}
elseif ($p==3) {$file_array[3]="1\r\n";}
elseif ($p==4) {$file_array[4]="1\r\n";}
elseif ($p==5) {$file_array[5]="1\r\n";}
elseif ($p==6) {$file_array[6]="1\r\n";}


elseif ($p==11) {$file_array[1]="0\r\n";}
elseif ($p==22) {$file_array[2]="0\r\n";}
elseif ($p==33) {$file_array[3]="0\r\n";}
elseif ($p==44) {$file_array[4]="0\r\n";}
elseif ($p==55) {$file_array[5]="0\r\n";}
elseif ($p==66) {$file_array[6]="0\r\n";}

// Записываем массив обратно в файл 
foreach ($file_array as $value) 
{ 
fwrite ($file, $value); 
} 
fclose ( $file); 
} 
else 
{ 
echo("Ошибка открытия файла"); 
} 
?>

And now it needs to be checked from the arduino and for example:
If line 1 == 0 turn off the power on pin 1;
If line 2== 1 turn on power on pin 2;
................................................. ................................................. .........
Actually interested in the code for the Arduino as a whole, if possible. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
svd71, 2014-07-09
@Sprite105

There are two types of implementation: one is long and expensive and the second is simpler.
The first one is what you want. An Ethernet Shield is required, in it you need to write a timer to read a specific request via TCP / IP from any available server where you can place your data. Then analyze the resulting code and do what you need.
Second option. If there is already a home server, then what is it worth to connect Arduino to it and, at the request of the script, transmit the necessary data via the COM port and read the response?

S
Sprite105, 2014-07-09
@Sprite105

svd71
The second option.
If possible, can you write this code? If it doesn't make it difficult, of course. Once again, I repeat that in programming I am a complete 0.

V
Vladimir, 2014-07-09
@noonv

Lots of options.
You can do this , or you can connect to a router like TP-LINK TL-MR3020 .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question