Sending data from a webpage to Arduino yun

Hi ...

After following the topic [SOLVED] Yun MySQL connection - Arduino Yún - Arduino Forum I can to send data of different sensors to a MySQL database hosted on the Arduino YUN (Linino) and display this data in a webpage using PHP.

I need help with how I can to send a data obtained on a PHP script to the microprocessor Atheros for to control the sensors through this webpage for example turn on or off an LED depending on the data obtained from queries to the BDD.

Thanks in advance for any help....

Follow

http://forum.arduino.cc/index.php?topic=254440.msg1805842#msg1805842

to install php software and setup uhttpd.

nano /www/led.php
<?php
if (isset($_POST["led"])){
$led=$_POST["led"];
require ("/usr/lib/php/bridge/bridgeclient.class.php");
$client = new bridgeclient();
$client->put("D13",$led);
} else {
$led="OFF";
}
echo  $led;
?>
<form id="form" action="led.php" method="post">
    <input onChange="this.form.submit();" type="radio" name="led" value="OFF" <?php  echo(($led=="OFF")?"checked='checked'":"");  ?>>OFF

    <input onChange="this.form.submit();" type="radio" name="led" value="ON" <?php  echo(($led=="ON")?"checked='checked'":"");  ?> >ON

</form>

ATmega32u4 code:

#include <Bridge.h>
void setup() {
  pinMode(13, OUTPUT);  // initialize digital pin 13 as an output.
  Bridge.begin();
  Serial.begin(9600);
  while (!Serial);
}
void loop() {
  Serial.println("start");
  char pin13[5];
  Bridge.get("D13", pin13, 5);
  Serial.println(pin13);
  String eval = String(pin13);
  if (eval == "ON") {
    digitalWrite(13, HIGH);
  }
  if (eval == "OFF") {
    digitalWrite(13, LOW);
  }
  delay(1000);
}

Browse "http://192.168.0.102/led.php" to switch led.

This is an interesting solution! Compared to the Bridge Example, where all of the network decoding/handling is handled in the sketch, I like how all of the networking heavy lifting is done on the Linux side and only the low-level hardware I/O is done in the sketch. I think it's a much better allocation of effort.

Of course, it's not quite like the Bridge Example, because it actually loads a web page instead of calling an API. But you can still get/set data remotely through use of the /data/put and /data/get URLs (where the heavy lifting is still being done on the Linux side and no effort is required in the sketch.)

ShapeShifter:
I like how all of the networking heavy lifting is done on the Linux side and only the low-level hardware I/O is done in the sketch. I think it's a much better allocation of effort.

Agree 110%.

But why bring horrible PHP into it when Python is so much nicer and is already on the Yun?

...R