Data Parsing - WiShield - Wireless Temp. & Switch
hi all!
so here project: working on multi-sensor device intended control solid state relays.
as stands, using tmp102 temperature sensors report on i2c protocol arduino due. w/ wishield 1.0
the temperature data 2 sensors being sent via post method php script on colocated server.
the remote php script stores incoming data in sql database analyze using jpgraph & php.
this part working fine - have been collecting temperature data ~6mo now.
what struggling following:
getting control data remote server control solid state relay.
what use sql database control switch states (boolean function, really).
i have written php script polls database , returns following:
<switch name>,<switch state> (eg. |1,0)
i using pipe ( | ) sort of index parse incoming request code knows start looking actual control data.
i make scalable have say, 4 switches, having states returned single query of sql/php server.
so need somehow include ability intelligently parse multiple switch data.
ie: sw1,1 .. sw2,0 .. sw3,1 .. etc
as stands, if make text file (switch.php) |1,0 in it, switch set off, if text file contains |1,1 switch turned on.
when test swtich.php using sql data, web browser reports only: |1,0 or |1,1 arduino not control switch accordingly.
i hoping experienced coder have @ source (below) , make suggestions / me along way.
here source code of php script arduino told data from:
so here project: working on multi-sensor device intended control solid state relays.
as stands, using tmp102 temperature sensors report on i2c protocol arduino due. w/ wishield 1.0
the temperature data 2 sensors being sent via post method php script on colocated server.
the remote php script stores incoming data in sql database analyze using jpgraph & php.
this part working fine - have been collecting temperature data ~6mo now.
what struggling following:
getting control data remote server control solid state relay.
what use sql database control switch states (boolean function, really).
i have written php script polls database , returns following:
<switch name>,<switch state> (eg. |1,0)
i using pipe ( | ) sort of index parse incoming request code knows start looking actual control data.
i make scalable have say, 4 switches, having states returned single query of sql/php server.
so need somehow include ability intelligently parse multiple switch data.
ie: sw1,1 .. sw2,0 .. sw3,1 .. etc
as stands, if make text file (switch.php) |1,0 in it, switch set off, if text file contains |1,1 switch turned on.
when test swtich.php using sql data, web browser reports only: |1,0 or |1,1 arduino not control switch accordingly.
i hoping experienced coder have @ source (below) , make suggestions / me along way.
code: [select]
void printdata2(char* data, int len) { // how headers returned getdata routine handled
if (len > 0){
memset(datain, ' ', sizeof(datain)); // clear datain , initialize cleanly length of data packet
for (int cntchar=0; cntchar < len; cntchar++) {
char chrin = data[cntchar]; // gather data data variable 1 char @ time
if (chrin == '|') { // more advanced: if ((chrin == '|') || (indexfound != 1))
datain[ptr] = chrin; // set first datain[0] current chrin, post-increment ptr
ptr++;
indexfound = 1;
} // end of if (chrin == '|')
if (indexfound == 1) {
sscanf(datain, "%[^,], %d", sw1); // ignore switch name now, state (and hope works)
serial.println(onoff);
} // end of (indexfound == 1)
} // end of (int cntchar=0; cntchar < len; cntchar++)
} // end of (len > 0)
// uip_close(); // disconnect server - causes data packet loss reason, ie. not finish request
}here source code of php script arduino told data from:
code: [select]
<?php
include ("db.php");
$sw = $_get['sw'];
$today = date("y-m-d");
if ($dbtable == "") $dbtable = "switches";
mysql_connect($host,$login,$passwd);
@mysql_select_db($dbname) or die( "unable to connect to database");
$query = " select *
from switches
";
$result = mysql_query($query);
$cnt = 0;
$cnt2 = 0;
while($row = mysql_fetch_row($result))
{
$switchin[$cnt] = $row[0];
$statein[$cnt] = $row[1];
$datein[$cnt] = $row[2];
$cnt++;
}
mysql_free_result($result);
while($cnt2 < $cnt)
{
$dateinconv[$cnt2] = date("y-m-d h:i:s",$datein[$cnt2]);
$cnt2++;
}
$cnt3=0;
while($cnt3 < $cnt)
{
echo "|";
echo $switchin[$cnt3];
echo ",";
echo $statein[$cnt3];
$cnt3++;
} // example, outputs: |1,1
?>
if fetch switch.php browser display?
the code of printdata2 quite unclear me does, e.g. var ptr never initialized?
when separator found store datain[ptr]. why? understood need digits.
adding end-token handshake makes parsing easier. e.g. <1,0> know when have enough data new 'command'
the code of printdata2 quite unclear me does, e.g. var ptr never initialized?
when separator found store datain[ptr]. why? understood need digits.
adding end-token handshake makes parsing easier. e.g. <1,0> know when have enough data new 'command'
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Data Parsing - WiShield - Wireless Temp. & Switch
arduino
Comments
Post a Comment