Hardware Reference
In-Depth Information
var sensorID = json_data.id;
Now that we know which sensor returned some data, we can read the return_value
field inside the JSON object to know the status of the motion sensor on this module. If
this value is equal to 0 , we set the background color of the display block of this sensor to
gray. If it is equal to 1 , it means that some motion was detected. If this is the case, we
change the background color to orange as follows:
if (json_data.return_value == 0){
$("#display_" + sensorID).css("background-color","gray");
}
else {
$("#display_" +
sensorID).css("background-color","orange");
}
Let's now see the details of this PHP file that is called every time. We saw in the
JavaScript code that the PHP file also receives an argument called command . This vari-
able is retrieved inside the PHP file by:
$command = $_GET['command'];
Inside this file, we also need to include the php_serial class:
include "php_serial.class.php";
We also need to declare the right serial port for your XBee explorer device:
$serial_port = "/dev/cu.usbserial-A702LF8B";
Note
You will have to change this according to your own settings. To know which serial port
the XBee explorer board is using, simply search for devices starting with cu inside your
/dev folder if you are using Linux or OS X. If you are using Windows, you will see the
list of the serial ports in your Configuration Panel.
You now need to configure the different settings of the serial connection we are about to
open with the board:
Search WWH ::




Custom Search