Make sure you dont have any line breaks after the last record. That will get rid of the blank line. I simply backspaced the last empty row from your data.
See here:http://galaxyinternet.us/jackbarnes/read_csv_reverse_advanced.php?rows=6
Make sure you dont have any line breaks after the last record. That will get rid of the blank line. I simply backspaced the last empty row from your data.
See here:http://galaxyinternet.us/jackbarnes/read_csv_reverse_advanced.php?rows=6
As Jim commented, this isn’t really CSV, its a txt log file saved as a CSV. It appears that the single space is always in the file, as the putty serial monitor updates the logs from the Arduino serial data. I added Jims Hack to index.php for bammo.info and it works perfectly.
In the future, I will be adding more sensors to the output display. They will be reported as a single row of info. The historical results are for diagnostic work, if the sensors report a significant change in results.
This unit is for my wifes garden, but I have professional farmer friends, following this build who are interested in building these units for near their giant water irrigation well circles, where they could see what the condition is of the moisture of the soil remotely (4-6 inches below soil top), before turning on the 750 gallon per minute beasts.
Thank you again both Jim & Benanamen.
If you are to log more data then I would consider changing the way the pi works
You could build this as a SaaS app, where other farmers can buy∕build your device, set up wifi and just let it do its magic. Then it will post data to your API which the users again can log in to. By getting data systematically instead of reading a huge text-file you’re able to do all sorts of fun stuff. Like building graphs which let them compare with last week/month/year, etc etc.
Jim,
Agree completely, this is the direction that this project is headed. First was to prove I could get the Ardu to Pi reporting in the field (garage in a giant pot at moment) wirelessly to the web. Once the next batch of sensors arrive, I will be redoing the coding and looking towards developing a solution like yours.
Any suggestions on must read books for idiots with stupid ideas in their garage?
You will most likely see me here again in a few weeks looking lost and confused.
Best,
Jack
I’d reconsider using the Pi at all, afaik the Arduino can (with a wifi/eth shield) post data over the net on its own.
I would probably do something like this:
Generate an UUID for each arduino (you can find php functions for this). This can be used both as a identification and a licensing number.
At spesific times I would check the sensor and post data to the API
post data with the UUID:
[php]{
“id”: “8fd0cb6b-1716-4c09-9122-505cb84bf869”,
“data”: [
{
“time”: “1391969828”,
“someData”: “value”
}
]
}[/php]
if you get no response or an error from server side then store the data to a local store, so that you can post it next time you post data, it may now look something like this:
[php]{
“id”: “8fd0cb6b-1716-4c09-9122-505cb84bf869”,
“data”: [
{
“time”: “1391969828”,
“someData”: “value”
},
{
“time”: “1391944628”,
“otherData”: “value”
}
]
}[/php]
[hr]
On the server side you use json_decode to convert the json to an array of objects, and then store the data to your database.
Jim,
I have ordered a wifi shield for the Ardu, and hope that I can spend next weekend on freeing the Ardu. The irony is that a Pi with Wifi Doggle is cheaper than the standard wifi shield alone is for the Ardu. So, while I waited on the wifi shield I ordered from China to arrive, I used the Pi sitting on my work bench to prove the first concept.
There is currently a deal where you could put a GSM cell on an Ardu with free 1000 SMS per month for a year for the same cost as the Pi and or the Wifi shield. I am pondering Ardu SMS to Cloud for the end solution. It free’s the units of needing Wifi at the well site.
That sounds like a plan, less things that can (will) go wrong is better
Then you will probably get a unique number pr gsm cell, and you can just send a csv with data (real comma separated)
like this
1391969828:815
or
1391969828:815,1391944628:816
How will you catch the sms messages though?
Jim,
One of the cool features about the Pi, and why its part of this build beside on my workbench, is that I bought the IR Camera module with the near blue spectrum.
This allows the box to take photos at night, to monitor the health of the photosynthesis in the plants. The cam adds $35 but, single pictures at Dawn, Noon, Sunset and Midnight, would capture the health of the plants as they grow remotely.
http://missionscience.nasa.gov/ems/08_nearinfraredwaves.html
And that is how I sneaked Nasa into my geek garden box. lol
An added value feature for farmers willing to pay for an upgraded SaaS account. I am pondering Ardu with Cell shield with USB to Pi, with Pi controlling the Ardu and Cell via serial as needed. For Two way telcom.
The SMS is to the farmers phones. The capture of SMS data is to be decided.
A simple work around solution is to use www.freedompop.com and plug a small portable Mifi with 500 megs of free data per month of upload capacity into each box for $50ish. Then we have the Cell to Wifi handled by a free service provider and back to Ardu or Ardu with Pi Cam for upgraded monitoring.
So, now that this is stable and flowing smoothly, I was wondering how would I produce a chart of the data?
Thoughts on http://pchart.sourceforge.net/documentation.php?topic=advexemple22 should I even ponder chasing down the install parts necessary to make this work? What would the guru’s of making the data clean use to display this data if they were doing this?
Jim,
My friend who helps/mocks is a .js guy loved your idea, I have node-0.25 running, but I am so blind on .js, I figured a php solution must be easier. If you have any solutions for my install please share.
best,
Jack
a PHP solution will definitly not be easier.
If you include this and jquery all you have to do is write a php script that fetch the data you want to display and return a proper json response with labels and data. Then use a simple jquery ajax request to fetch data from PHP and insert it into the chart.
I’m sure your js-friend can help out with the js-part, if not we can do it here. Except the queries for the data all this (php+js) is possible to accomplish in like 10 lines of code.
Jim,
Check out how your script is now working at bammo.info. I have added the DHT11 sensor with temp and humidity readings to the package. Its all working dynamically, currently updating about every 20 seconds or so, just the way you built the script. Great Work. Thank You again.
However, Its displaying 12 lines of numbers on the left. Any idea how I can easily hide those? ??? :
This weekend, I hope to get the Raspi to take a picture and drop it into a folder, I will embed that picture into the index html part and display a picture from the cam.
Best,
Jack
Could you add the current .php and .csv files?
Here is the php. and drop box to csv. The CSV captures the changes to the output as i added serial prints tonight. so scroll to bottom to see latest. https://www.dropbox.com/s/3rp89526gwafd6r/widgets.csv
[php] <?php
function readLog($fileName, $rows) {
if (!file_exists($fileName)) {
return false;
}
$fl = fopen($fileName, ‘r’);
for ($x_pos = 0, $ln = 0, $output = array(); fseek($fl, $x_pos, SEEK_END) !== -1; $x_pos–) {
$char = fgetc($fl);
if ($char === “\n”) {
if (++$ln === $rows+1) { // ugly hack to remove first empty row
break;
}
continue;
}
$output[$ln] = $char . ((array_key_exists($ln, $output)) ? $output[$ln] : ‘’);
}
fclose($fl);
array_shift($output); // ugly hack to remove first empty row
return $output;
}
$rows = !empty($_GET[‘rows’]) ? (int) $_GET[‘rows’] : 12;
$data = readLog(‘widgets.csv’, $rows);
$i = 1;
foreach ($data as $line) {
echo $i . ': ’ . $line . ‘
’;
$i++;
} [/php]
[php] $i = 1;
foreach ($data as $line) {
echo $i . ': ’ . $line . ‘
’;
$i++;
}[/php]–>[php] foreach ($data as $line) {
echo $line . ‘
’;
}[/php]
That’s Beautifully clean now. Thank You again. This weekend i am going to get the near blue inferred cam working and posting night photos.
Thoughts about embedding this code into the page to keep it refreshing?
[php]$page = $_SERVER[‘PHP_SELF’];
$sec = “30”;
header(“Refresh: $sec; url=$page”);[/php]
The Garden Monitor is now working in its intended location. I have deployed the unit to the garden and have it in one of the garden beds, with it returning expected values.
I have the webcam working now for the Pi. It took this http://www.bammo.info/picam/2.jpg with its IR cam at sunset.
However, I have to admit to having totally failed at getting the html image to embed into the PHP string of Jim’s. I have about 30 failed indexnotworking.html and indexstillnotworking.php files on the poor pi.
Still, the work in progress, is still moving forward. I ordered a rain sensor to install on the outside of the monitor, to alert if it gets hit by water. It is designed to estimate the size of the rain drops, so will be adding it and its out put to www.bammo.info next.
Now working as planned. www.bammo.info is ready to show the farmer friends I have. TY for the help everyone. The Garden Box now monitors the garden and shows the latest image taken on the camera and saved to folder. I love open source projects. Thank you to Jim and B man…