Skip to content

Commit

Permalink
Merge pull request #1 from Ths2-9Y-LqJt6/0.1
Browse files Browse the repository at this point in the history
0.1 ftw
  • Loading branch information
Ths2-9Y-LqJt6 authored Mar 23, 2017
2 parents e17bcb6 + e78051f commit 1768f3b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 14 deletions.
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ Yet Another Pi Weather Station (YANPIWS)- My explorations in getting a Rasberry

## Background

With a daily workflow that invoves checking out a repo, making
With a daily workflow that involves checking out a repo, making
commits, and the stopping work, it only made sense that I'd
do the same for my efforts to write a little weather app for my
Pi. This habbit means my work is always backed up and ready
for others to review.
Pi. This habit means my work is always backed up and ready
for others to review or for me to load up on the another computer.

Goals for this project are:

* Show live weather from local, wireless sensors
* Show past weather from local, wireless sensors
* Show current time
* Show sunset/sunrise times
* Show moonrise/moonset times
* Show weather forecast from some provider
* Show show current weather from some provider
* Show live weather from local, wireless sensors
* Show past weather from local, wireless sensors

## Hardware

Expand All @@ -33,11 +33,11 @@ we'll use the USB SDR dongle to read the temps from the sensors
with a a call like this:

```
rtl_433 -C customary -F json -q | parse.php
rtl_433 -C customary -F json -q | php -f parse_and_save.php
```

And then, since I'm a PHP guy, we'll have that parse.php, be,
you know php, that parses it, but my proof of concept looks
And then, since I'm a PHP guy, we'll have that ``parse_and_save.php``,
be, you know php, that parses it, but my proof of concept looks
like this (thanks
http://stackoverflow.com/a/11968298):

Expand All @@ -46,11 +46,11 @@ http://stackoverflow.com/a/11968298):
<?php

while($f = fgets(STDIN)){
parseJson($f);
parseJson($f);
}

function parseJson($jsonLine){
print_r(json_decode($jsonLine));
print_r(json_decode($jsonLine));
}
```

Expand All @@ -63,14 +63,23 @@ use an existing LAMP set up or do LAMP on the pi like so:
sudo apt-get install apache2 php5 php5-mysql mysql-server
```

And then some nice charts via something like http://canvasjs.com/html5-javascript-dynamic-chart/
And then show the data in some nice charts via something like http://canvasjs.com/html5-javascript-dynamic-chart/

Finally, use chrome to show it full screen:

* autoboot chrome full screen https://blog.gordonturner.com/2016/12/29/raspberry-pi-full-screen-browser-raspbian-november-2016/
* add --incognito to remove errors https://superuser.com/questions/461035/disable-google-chrome-session-restore-functionality#618972

## Conclusion
## data

currently we're writting it in CSV to the ``data`` folder:

```csv
DATE,ID,TEMP,HUMIDITY
2017-03-22 23:26:22,109,57.92,25
2017-03-22 23:26:55,211,72.5,34
```

## Version History

Not a lot of stuff here now - but sit tight - i'll try and
impress you!
0.1 - Mar 22, 2017 - parsing data, writing to CSV, crude readme, no html output
36 changes: 36 additions & 0 deletions data/2017-03-22
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
2017-03-22 23:08:31,211,72.5,34
2017-03-22 23:08:45,109,58.46,25
2017-03-22 23:09:19,211,72.5,34
2017-03-22 23:09:34,109,58.46,25
2017-03-22 23:10:07,211,72.5,34
2017-03-22 23:10:21,109,58.46,25
2017-03-22 23:10:55,211,72.5,34
2017-03-22 23:11:10,109,58.46,25
2017-03-22 23:11:43,211,72.5,34
2017-03-22 23:11:58,109,58.46,25
2017-03-22 23:12:31,211,72.5,34
2017-03-22 23:12:46,109,58.28,25
2017-03-22 23:13:19,211,72.5,34
2017-03-22 23:13:34,109,58.28,25
2017-03-22 23:14:07,211,72.5,34
2017-03-22 23:14:22,109,58.28,25
2017-03-22 23:14:55,211,72.5,34
2017-03-22 23:15:10,109,58.28,25
2017-03-22 23:15:43,211,72.5,34
2017-03-22 23:15:57,109,58.28,25
2017-03-22 23:16:31,211,72.5,34
2017-03-22 23:16:46,109,58.28,25
2017-03-22 23:17:19,211,72.5,34
2017-03-22 23:17:34,109,58.28,25
2017-03-22 23:18:07,211,72.5,34
2017-03-22 23:18:22,109,58.1,25
2017-03-22 23:18:55,211,72.5,34
2017-03-22 23:20:31,211,72.5,34
2017-03-22 23:20:46,109,58.1,25
2017-03-22 23:21:19,211,72.5,34
2017-03-22 23:21:34,109,58.1,25
2017-03-22 23:22:07,211,72.5,34
2017-03-22 23:26:07,211,72.5,34
2017-03-22 23:26:22,109,57.92,25
2017-03-22 23:26:55,211,72.5,34
2017-03-22 23:27:10,109,57.92,25
50 changes: 50 additions & 0 deletions parse_and_save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/php
<?php

$knownKeys = array(
'time',
'id',
'temperature_F',
'humidity',
);
$path = "./data";

while($f = fgets(STDIN)){
$dataObject = json_decode($f);
$saveMeArray = array();

foreach ($knownKeys as $key) {
$saveMeArray[] = cleanseData($dataObject->$key);
}

$today = date('Y-m-d', time());
saveArrayToCsv($path, $today, $saveMeArray);
}

/**
* we likely shouldn't trust data sent over unencrypted
* un-authenticated channels. Let's make sure it's on the
* up and up. uses regex to replace all but "^0-9\. :-"
* @param string $data input to cleanse
* @return string
*/
function cleanseData($data)
{
$data = trim($data);
return preg_replace("/[^0-9\. :-]+/", "", $data);
}

/**
* @param string $path
* @param array $array of k/v pairs to save
*/
function saveArrayToCsv($path, $file, $array)
{
if (is_dir($path) && is_writable($path . '/' . $file) && is_array($array) && sizeof($array) > 0) {
echo 'It\'s ' . $array[2] . ' at ID ' . $array[1] . " - data written to " . $path . '/' . $file ."\n";
file_put_contents($path . '/' . $file, implode(',' , $array) . "\n",FILE_APPEND);
} else {
echo "failed to write to $path - not a dir, not writable or invalid/empty array passed :(";
}
}

0 comments on commit 1768f3b

Please sign in to comment.