So I’ve had the WiFly RN-XV churning out data for a little while now. I thought I’d share the PHP code that deals with that data.
The data from the RN-XV is encoded in the GET request it makes when it loads the data handling PHP page. This is the form the GET request takes:
GET /thepage.php?DATA= XXXX00001111222233334444555566667777nn
Where XXXX is the GPIO data and 0000 through to 7777 are the values of the 8 analogue inputs expressed in hexadecimal.
Below is the PHP script that receives the GET request from the RN-XV and then processes the data:
//grab the GET data $data_in = stripslashes($_GET['data']); // Split the GET data variable every 4 characters, into an array $myArray = str_split($data_in, 4); // convert the hexadecimal into decimal for the two pins I'm reading $pin19dec = base_convert($myArray,16,10); $pin20dec = base_convert($myArray,16,10); //Convert the number 0-16384 (14bit) from the ADC into 0-500mV $mV = $pin19dec * (1414.143/16384); //Convert millivolts into temperature $degC = ($mV - 500)/10; //Convert the number 0-16384 (14bit) from the ADC into 0-500mV $LightmV = $pin20dec * (1414.143/16384); $LightV = $LightmV / 1000;
I’ve made a few assumptions in the code. I worked out the ADCs were 14bit, so arrived at the value of 16384 as the number of discreet values possible. I get pretty sensible values for the temperature reading using that value, and the light sensor data is only really needed as raw data anyway.
If anyone can suggest anything to improve things, please do.