Hardware Reference
In-Depth Information
We also need to receive the data every time we call the script to plot the data. This is done
by an AJAX call to the PHP file we created before:
$.ajax({
url: "readout.php",
type: "GET",
dataType: "json",
success: onDataReceived
});
Note that this code has to go inside the update() function in the JavaScript code. You
can define this function with:
function update() {
You can see that this AJAX call, if successful, calls another JavaScript function. This
function will actually take the data as an argument and plot it with the options we defined
before:
function onDataReceived(series) {
var data = [];
data.push(series);
$.plot("#placeholder", data, options);
}
All this code is contained in the update() function, and this function is called continu-
ously (every 10 milliseconds) so that the plot is always updated when a new data point
comes in:
setTimeout(update, 10);
Finally, at the end of the script, we call this function once to get the graph started:
update();
It is now time to test the page we just created. Place all the files in the datalogger
folder on your web server and make sure that the sketch is still loaded on the Arduino
board.
Search WWH ::




Custom Search