Ardu-Pi-PHP Combo to web works, butt ugly

Hey Gang,

I am finally back to the remote control for the farm water well NG powered 454 Chevy engine from this fall. While chatting with the farmers, I found out that the single most interesting thing a farmer could know, is the soil moisture levels 4-6 inches below the surface.

This helped me realizing how dry is 160+ acre circle would make the perfect starting point for the multi sensor and relay control of the water well pump. Giving the farmer info, about the status of his dirt, saves NG costs and wear and tear on his well pump, if he doesn’t need to water the circle yet.

This has the Pi with HD cam on outside to test LCD monitor display

I have built a working AC based probe for 6+ inches below the surface, powered by an uno. I have a RasPi plugged into the Uno via USB. I have the RasPi listening to its serial port and record all activity as a CSV file. I have a PHP script setup as an index page and when you hit the URL you get the CSV file displayed and updated, in real time as you refresh your page.

That works, but wow is it fugly displayed on a web page and gets longer and longer every few seconds. is the url for the RasPi that is hosting the Ardu.

Any thoughts on how to improve the PHP side of this, to parse the CSV results of the serial port to the top of the page vs added to bottom?

PHP code is


$file_handle = fopen("widgets.csv", "r");

while (!feof($file_handle) ) {

$line_of_text = fgetcsv($file_handle, 1024);

print $line_of_text[0] . $line_of_text[1]. $line_of_text[2] . "




and assembled and ready for out door testing. I am adding temp & humidity next to the read out once I get the CSV pretty. Then we start adding relays, and control feed back of the start/stop, RPM and engine operating temps after this gets cleaned up.

I have zero experience with PHP, and found this code, with almost zero tuning, to work. My issue is getting the CSV to report the lastest results of the file to the top of the web page, instead of at the bottom of each page. Is there an easy change to this code, that I could implement to reverse the CSV parsing?

If anyone is interested in the steps to getting a Ardu>Pi>PHP> Web beside what is above, ask away. It took me 3 days of hitting my head against a wall, to figure out this solution which took the Pi CPU usage from 50% to 5% once I got it working.

I would instead write the data to a MySQL database, then just read the last record from that :)

I agree, getting it to record to MySQL is prob the next major step. I have upgraded the RasPi to LAMP status. Any suggestions on how to kick start the automation to a db would work?

I was able to get the code fixed so that it is now producing the latest monitor result to the top of the web page instead of the bottom. This helps clean up the result significantly. Next is to prob chop off the full loading of the results, and have it return just the latest result.

New PHP Code

  $file = file("widget.csv");
  $file = array_reverse($file);
  foreach($file as $f){
      echo $f."

results for the Ardu serial monitor are here.