SEARCH THE KNOWLEDGE BASE
OR BROWSE BY CATEGORY
Standalone WiFi modules sending data to web
While Roving’s WiFi products are excellent as serial to Wi-Fi interfaces, they can also perform useful functionality as stand-alone devices.
Here we describe setting up the module to send all of its sensor data – both digital and analogue – to a PHP script on a remote server. In this way, a stand-alone Roving Networks Wi-Fi module can update a remote server as long as it has a connection. While idle, the module goes to standby, so power consumption is kept to a minimum.
The following script is used within TeraTerm (a free download, and available on Roving's support pages) to set up the module.
;this macro all sent with 5 msec character delay
timeout=3
sendln 'reboot'
wait '*READY*'
send '$$$'
wait 'CMD'
sendln 'factory RESET'
wait 'AOK'
sendln 'set wlan join 0' ;Stop device connecting while we set up
wait 'AOK'
pause 5
sendln 'set wlan ssid YourRouter' ;Local SSID to connect to wait 'AOK'
sendln 'set wlan phrase password' ;WLAN password for local access point
wait 'AOK'
sendln 'set wlan auth 2' ;Using WPA in this example
wait 'AOK'
sendln 'set sys iofunc 0x50' ;red for TCP connection, green for WLAN
wait 'AOK'
sendln 'set wlan join 1' ;Connect to LAN
wait 'AOK'
sendln 'set time zone 0' ;GMT / UTC time zone
wait 'AOK'
sendln 'set time enable 1' ;Enable RTC
wait 'AOK'
sendln 'set ip proto 18' ;turn on HTTP mode=0x10 + TCP mode = 0x2
wait 'AOK'
sendln 'set dns name www.yoursite.com' ;name of your webserver
wait 'AOK'
sendln 'set ip host 0' ;so module will use DNS
wait 'AOK'
sendln 'set ip remote 80' ;standard webserver port
wait 'AOK'
sendln 'set com remote GET$/userprog.php?DATA='
;sample server application
wait 'AOK'
sendln 'set q sensor 0xff' ;sets module to sample all 8 sensor channels
wait 'AOK'
sendln 'set sys auto 60' ;automatically make the connection every 60 seconds
wait 'AOK'
sendln 'set option format 0x1f' ;send the header plus the sampled binary data converted to ASCII format
wait 'AOK'
sendln 'set option device PHPdemo' ;Set an ID to identify this 'application'
wait 'AOK'
sendln 'save'
wait 'config'
sendln 'reboot'
So, with the module set up, the following PHP code should be placed on the server (yoursite.com) in the above example :
<?php
$data=$_GET["DATA"];
$mac=$_GET["mac"];
$rtc=$_GET["rtc"];
$id=$_GET["id"];
$bss=$_GET["bss"];
$bat=$_GET["bat"];
$io=$_GET["io"];
$wake=$_GET["wake"];
$seq=$_GET["seq"];
$rtc_val=hexdec($rtc);
$rtc_sec=$rtc_val % 60; $rtc_val/=60;
$rtc_min=$rtc_val % 60; $rtc_val/=60;
$rtc_hr =$rtc_val % 24; $rtc_val/=24;
echo "Got data " . $data . " " . $rtc;
$file_name="userdata.htm";
$dataf=fopen($file_name, 'w') or die();
flock($dataf, 2) or die();
fputs($dataf,"<html>\n");
fputs($dataf,"<head>\n<title>User Data</title></head>\n");
fputs($dataf,"<body>\n");
fputs($dataf,"Id: " . $id . "<br>");
fputs($dataf,"Mac: " . $mac . "<br>");
fputs($dataf,"Data: " . $data . "<br>");
fputs($dataf,"RTC: " . $rtc . "<br>");
fputs($dataf,"ID: " . $id . "<br>");
fputs($dataf,"BSS: " . $bss . "<br>");
fputs($dataf,"Bat: " . $bat . "<br>");
fputs($dataf,"IO: " . $io . "<br>");
fputs($dataf,"Wake: " . $wake . "<br>");
fputs($dataf,"Seq: " . $seq . "<br>");
fclose($dataf);
?>
The PHP code accepts the data from the module and writes a standard HTML file to the webserver. You can now browse to www.yoursite.com/userdata.htm to see the data posted by the module. Obviously, the PHP could archive the data to a file on the server, the demo code above merely shows the last received data, it does not store any history. There is an example running at www.miodem.com/userdata.htm at the time of writing - although we can't guarantee its long term availability.
This shows how simple it is to create independent, low cost sensors using Roving’s WiFi products.
![]()
Submitted January 2012 by Simon Taylor, Avnet Embedded
| ARTICLE RATING 5 out of 5 (2 votes) |
Rate this article |
RELATED ARTICLES
| Added January 26, 2012 in Modules, Wi-Fi |