├── .gitignore ├── doc └── auriol_protocol_v20.pdf ├── auriol-reader-screenshot.png ├── scripts ├── auriol-start.sh ├── auriol-watchdog.sh └── auriol-restarter.sh ├── www ├── pitemp.php ├── trans.php ├── temperature24h.plt ├── rain30d.plt └── meteo.php ├── reader ├── db.h ├── makefile ├── db.c └── auriol-reader.c ├── .gitattributes ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | auriol-reader -------------------------------------------------------------------------------- /doc/auriol_protocol_v20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yu55/auriol_reader/HEAD/doc/auriol_protocol_v20.pdf -------------------------------------------------------------------------------- /auriol-reader-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yu55/auriol_reader/HEAD/auriol-reader-screenshot.png -------------------------------------------------------------------------------- /scripts/auriol-start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Start the server again 4 | script -qc ../reader/auriol-reader 5 | -------------------------------------------------------------------------------- /www/pitemp.php: -------------------------------------------------------------------------------- 1 | 2 |
 3 | 
12 | 
13 | 
14 | 


--------------------------------------------------------------------------------
/www/trans.php:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
12 | 
13 | 
14 | 


--------------------------------------------------------------------------------
/scripts/auriol-watchdog.sh:
--------------------------------------------------------------------------------
 1 | #!/bin/bash
 2 | service=auriol-reader
 3 | 
 4 | if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
 5 | then
 6 | echo "$service is running!!!"
 7 | else
 8 | ( cd /home/pi/repositories/auriol_reader/scripts ; ./auriol-restarter.sh )
 9 | fi
10 | 
11 | 


--------------------------------------------------------------------------------
/scripts/auriol-restarter.sh:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | cd /home/pi/repositories/auriol_reader/scripts
 4 | 
 5 | # Kill
 6 | killall auriol-reader
 7 | 
 8 | #DATE=$(date +"%Y%m%d%H%M")
 9 | #mv output-auriol.log output-auriol_$DATE.log
10 | 
11 | # Start the server again
12 | screen -S auriol -d -m ./auriol-start.sh
13 | 


--------------------------------------------------------------------------------
/reader/db.h:
--------------------------------------------------------------------------------
 1 | #ifndef AURIOL_DB_H_
 2 | #define AURIOL_DB_H_
 3 | 
 4 | void initializeDatabase();
 5 | void savePluviometer(float amount);
 6 | void saveTemperature(float temperature);
 7 | void saveHumidity(unsigned int humidity);
 8 | void saveWind(float speed, float gust, unsigned int direction);
 9 | 
10 | #endif
11 | 


--------------------------------------------------------------------------------
/reader/makefile:
--------------------------------------------------------------------------------
 1 | # File to compile the auriol-reader
 2 | 
 3 | # TODO
 4 | # Create an install target to place
 5 | # - auriol-reader in /usr/local/bin
 6 | # - start-up scripts in /etc/init.d and /etc/rcX.d
 7 | # - Webb pages in /var/www/auriol-reader and config file in /etc/apache2/sites-*
 8 | 
 9 | all: clean auriol-reader
10 | 
11 | auriol-reader: auriol-reader.c
12 | 	gcc -Wall -ansi -o auriol-reader -I/usr/local/include -L/usr/local/lib -lwiringPi -lrt -lm -lsqlite3 auriol-reader.c db.c
13 | 
14 | clean:
15 | 	- rm -f auriol-reader
16 | 


--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
 1 | # Auto detect text files and perform LF normalization
 2 | * text=auto
 3 | 
 4 | # Custom for Visual Studio
 5 | *.cs     diff=csharp
 6 | *.sln    merge=union
 7 | *.csproj merge=union
 8 | *.vbproj merge=union
 9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 | 
12 | # Standard to msysgit
13 | *.doc	 diff=astextplain
14 | *.DOC	 diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot  diff=astextplain
18 | *.DOT  diff=astextplain
19 | *.pdf  diff=astextplain
20 | *.PDF	 diff=astextplain
21 | *.rtf	 diff=astextplain
22 | *.RTF	 diff=astextplain
23 | 


--------------------------------------------------------------------------------
/www/temperature24h.plt:
--------------------------------------------------------------------------------
 1 | #!/usr/local/bin/gnuplot -persist
 2 | set terminal png size 640,240 enhanced font "Helvetica,8"
 3 | set output '/var/www/tmp/temperature24h.png'
 4 | 
 5 | set title "Temperatura powietrza za ostanie 24 godziny"
 6 | unset multiplot
 7 | unset key
 8 | set style data lines
 9 | set grid ytics lc rgb "#bbbbbb" lw 1 lt 0
10 | set grid xtics lc rgb "#bbbbbb" lw 1 lt 0
11 | set datafile separator "|"
12 | set xdata time
13 | set timefmt "%Y-%m-%d %H:%M:%S"
14 | set format x "%H:%M"
15 | set x2tics
16 | set x2data time
17 | set format x2 "%H:%M"
18 | unset mx2tics
19 | set y2tics
20 | set xrange ["`date --date='24 hours ago' +'%Y-%m-%d %H:%M:%S'`":"`date +'%Y-%m-%d %H:%M:%S'`"]
21 | set x2range ["`date --date='24 hours ago' +'%Y-%m-%d %H:%M:%S'`":"`date +'%Y-%m-%d %H:%M:%S'`"]
22 | 
23 | plot "< sqlite3 /var/local/auriol-db.sl3  \"SELECT created, temperature FROM temperature WHERE created > datetime('now','localtime','-1 day')\"" using 1:2
24 | 
25 | 


--------------------------------------------------------------------------------
/www/rain30d.plt:
--------------------------------------------------------------------------------
 1 | #!/usr/local/bin/gnuplot -persist
 2 | set terminal png size 640,240 enhanced font "Helvetica,8"
 3 | set output '/var/www/tmp/rain30d.png'
 4 | 
 5 | set title "Opady atmosferyczne za ostatnie 30 dni"
 6 | unset multiplot
 7 | unset key
 8 | set grid ytics lc rgb "#bbbbbb" lw 1 lt 0
 9 | set grid xtics lc rgb "#bbbbbb" lw 1 lt 0
10 | set datafile separator "|"
11 | set xdata time
12 | set timefmt "%Y-%m-%d"
13 | set format x "%m-%d"
14 | set mxtics
15 | set boxwidth 0.5 relative
16 | set style fill solid 1.0
17 | set x2tics
18 | set x2data time
19 | set format x2 "%m-%d"
20 | set mx2tics
21 | set y2tics
22 | set xrange ["`date --date='30 days ago' +%Y-%m-%d`":"`date +%Y-%m-%d`"]
23 | set x2range ["`date --date='30 days ago' +%Y-%m-%d`":"`date +%Y-%m-%d`"]
24 | 
25 | plot "< sqlite3 /var/local/auriol-db.sl3  \"SELECT strftime('%Y-%m-%d', created) AS day,  MAX(amount)-MIN(amount) FROM pluviometer WHERE created > datetime('now','localtime','-30 day') GROUP BY day\"" using 1:2 with boxes lc rgb "blue"
26 | 
27 | 


--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
 1 | # auriol-reader
 2 | This repository contains AURIOL H13726 / Ventus W155 weather stations radio transmissions decoder application for Raspberry Pi. Application obtains data through a 433.92 MHz RF wireless receiver module (AUREL RX-4MM5++/F, simple chinese XY-MK-5V or other similar) connected to GPIO pin, decodes this data, prints it to `stdout` and saves in SQLite database.
 3 | 
 4 | ![auriol-reader-screenshot.png](auriol-reader-screenshot.png?raw=true "View of data received from AURIOL H13726 weather station via auriol-reader")
 5 | 
 6 | ## Repository layout
 7 | * `doc` - additional documentation
 8 | * `reader` - decoder application
 9 | * `scripts` - some scripts to make `auriol-reader` work continuously and start after reboot
10 | * `www` - some examples of primitive web pages showing data received by `auriol-reader`
11 | 
12 | ## Installation
13 | * This project uses Wiring Pi library (http://wiringpi.com/) so it should be installed first.
14 | * Secondly the `libsqlite3-dev` package is required.
15 | * Clone this repository, `cd` into `reader` directory, execute `make` and project should compile.
16 | 
17 | ## Running
18 | * connect receiver module output signal to Raspberry GPIO27
19 | * execute application with root privileges: `sudo ./auriol-reader`
20 | * observe decoded data on standard output and in `/var/local/auriol-db.sl3` database
21 | 
22 | ## Additional notes
23 | * If different GPIO pin must be used check how pins are numbered in Wiring Pi (http://wiringpi.com/pins/) and modify constant `RECIEVE_PIN` in `reader/auriol-reader.c` source code file (e.g. GPIO27 is pin 2 in Wiring Pi).
24 | * If nothing is visible on `stdout` that means decoder cannot recognize incoming impulses and some calibration might be needed - please check `reader/auriol-reader.c` for constants `SYNCHRO_LENGTH`, `SEPARATOR_LENGTH`, `ZERO_LENGTH`, `ONE_LENGTH`, `LENGTHS_MARGIN`. Setting these constants to proper values is critical for the decoder to be able to recognize data in incoming transmissions from weather station instruments. Note that `auriol-reader` consumes 100% CPU (because of constantly polling GPIO pin connected to receiver hardware) and running other process with heavy CPU usage will result in slower GPIO polling so the decoder simply won't recognize data for given constants configuration. You may also want to tweak these values on newer, faster Raspberry Pi models (faster than my own Model B Revision 2.0).
25 | 
26 | 


--------------------------------------------------------------------------------
/www/meteo.php:
--------------------------------------------------------------------------------
  1 | 
  2 |     
  3 |         Sportowa8 Meteo
  4 |         
  5 |         
 11 |     
 12 | 
 13 | 

Sportowa8 Meteo (stacja pogody AURIOL H13726)

14 | "; 18 | echo ""; 19 | echo ""; 20 | 21 | $results = $db->query("SELECT created, temperature FROM temperature ORDER BY created DESC LIMIT 1;"); 22 | $created = " "; 23 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 24 | 25 | $temperature = number_format($row['temperature'], 1); 26 | $created = $row['created']; 27 | echo ""; 28 | echo "Temperatura powietrza {$temperature} ℃"; 29 | echo ""; 30 | } 31 | $result = $results->finalize(); 32 | 33 | $results = $db->query("SELECT min(temperature) AS tmin, max(temperature) AS tmax FROM temperature WHERE created > datetime('now','localtime','-1 day');"); 34 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 35 | 36 | $temperature = number_format($row['tmin'], 1); 37 | echo ""; 38 | echo "Minimalna temperatura powietrza za ostatnie 24 godziny {$temperature} ℃"; 39 | echo ""; 40 | 41 | $temperature = number_format($row['tmax'], 1); 42 | echo ""; 43 | echo "Maksymalna temperatura powietrza za ostatnie 24 godziny {$temperature} ℃"; 44 | echo ""; 45 | } 46 | $result = $results->finalize(); 47 | 48 | echo ""; 49 | echo "Ostatnia aktualizacja bazy danych {$created}"; 50 | echo ""; 51 | 52 | echo ""; 53 | 54 | echo "
"; 55 | 56 | echo ""; 57 | echo ""; 58 | echo ""; 59 | 60 | $results = $db->query("SELECT (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-118 minute') ORDER BY created DESC LIMIT 1) - (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-118 minute') ORDER BY created ASC LIMIT 1) AS rain1h;"); 61 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 62 | 63 | $rain1h = number_format($row['rain1h'], 2); 64 | echo ""; 65 | echo ""; 66 | echo ""; 67 | } 68 | $result = $results->finalize(); 69 | 70 | $results = $db->query("SELECT (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-1 day') ORDER BY created DESC LIMIT 1) - (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-1 day') ORDER BY created ASC LIMIT 1) AS rain24h;"); 71 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 72 | 73 | $rain24h = number_format($row['rain24h'], 2); 74 | echo ""; 75 | echo " "; 76 | echo ""; 77 | } 78 | $result = $results->finalize(); 79 | 80 | $results = $db->query("SELECT (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-1 day') ORDER BY created DESC LIMIT 1) - (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-7 day') ORDER BY created ASC LIMIT 1) AS rain7d;"); 81 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 82 | 83 | $rain7d = number_format($row['rain7d'], 2); 84 | echo ""; 85 | echo " "; 86 | echo ""; 87 | } 88 | $result = $results->finalize(); 89 | 90 | $results = $db->query("SELECT (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-1 month') ORDER BY created DESC LIMIT 1) - (SELECT amount FROM pluviometer WHERE created > datetime('now','localtime','-1 month') ORDER BY created ASC LIMIT 1) AS rain30days;"); 91 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 92 | 93 | $rain30days = number_format($row['rain30days'], 2); 94 | echo ""; 95 | echo " "; 96 | echo ""; 97 | } 98 | $result = $results->finalize(); 99 | 100 | $results = $db->query("SELECT created FROM pluviometer ORDER BY created DESC LIMIT 1;"); 101 | while ($row = $results->fetchArray(SQLITE3_ASSOC)) { 102 | 103 | echo ""; 104 | echo ""; 105 | echo ""; 106 | } 107 | $result = $results->finalize(); 108 | 109 | echo "
Opad atmosferyczny za ostatnią godzinę {$rain1h} mm
Opad atmosferyczny za ostatnie 24 godziny {$rain24h} mm
Opad atmosferyczny za ostatnie 7 dni {$rain7d} mm
Opad atmosferyczny za ostatnie 30 dni {$rain30days} mm
Ostatnia aktualizacja bazy danych {$row['created']}
"; 110 | 111 | exec('gnuplot temperature24h.plt'); 112 | 113 | exec('gnuplot rain30d.plt'); 114 | ?> 115 |
116 | temperature24h 117 |
118 |
119 | rain30d 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /reader/db.c: -------------------------------------------------------------------------------- 1 | #include "db.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define DB_FILENAME "/var/local/auriol-db.sl3" 11 | #define M_PI 3.14159265358979323846 /* pi */ 12 | #define TEMP_DIFF 10 13 | #define WIND_SAVE_INTERVALL 3600.0 /* (double) Intervall to save wind data in seconds */ 14 | #define WIND_SAMPLES 120 /* WIND_SAMPLES = WIND_SAVE_INTERVALL / 30 */ 15 | 16 | #ifdef LANGUAGE_ENGLISH 17 | static const char LANG_DB_ERROR_OPENING[] = "ERROR: Can not open database!"; 18 | static const char LANG_DB_PLUVIOMETER_QUERY[] = 19 | "\nERROR in Pluviometer query: SQLite returned Error Code: %i.\n"; 20 | static const char LANG_DB_TEMP_QUERY[] = 21 | "\nERROR in Temperature query: SQLite returned Error Code: %i.\n"; 22 | static const char LANG_DB_TEMP_DIFF[] = 23 | "\nWARNING: Temperature difference out of bonds (%f to %f). Data will NOT be saved!\n"; 24 | static const char LANG_DB_CREATE_TBL[] = 25 | "ERROR: Could not create database table! Error Msg: %s.\n%s\n"; 26 | static const char LANG_DB_HUMID_DIFF[] = 27 | "\nWARNING: Humidity value out of bonds (%i %%). Data will NOT be saved!\n"; 28 | static const char LANG_DB_WIND_QUERY[] = 29 | "\nERROR in Wind query: SQLite returned Error Code: %i.\n\"%s\"\n"; 30 | 31 | #else 32 | static const char LANG_DB_ERROR_OPENING[] = 33 | "Can not open database. Dying. Bye bye."; 34 | static const char LANG_DB_PLUVIOMETER_QUERY[] = 35 | "\nSomething went wrong when inserting pluviometer data into DB. Error code: %i.\n"; 36 | static const char LANG_DB_TEMP_QUERY[] = 37 | "\nSomething went wrong when inserting temperature into DB. Error code: %i.\n"; 38 | static const char LANG_DB_TEMP_DIFF[] = 39 | "\nWARNING! Temp jump from %f to %f too big. Temp won't be recorded!\n"; 40 | static const char LANG_DB_CREATE_TBL[] = 41 | "ERROR: Could not create database table! Error Msg: %s.\n%s\n"; 42 | static const char LANG_DB_HUMID_DIFF[] = 43 | "\nWARNING: Humidity value out of bonds (%i %%). Data will NOT be saved!\n"; 44 | static const char LANG_DB_WIND_QUERY[] = 45 | "\nERROR in Wind query: SQLite returned Error Code: %i.\n\"%s\"\n"; 46 | #endif 47 | 48 | static const char *SQL_CREATE_TABLE[] = { 49 | "CREATE TABLE IF NOT EXISTS pluviometer( created DATETIME, amount DECIMAL(10,2));", 50 | "CREATE TABLE IF NOT EXISTS temperature( created DATETIME, amount DECIMAL(4,1));", 51 | "CREATE TABLE IF NOT EXISTS humidity( created DATETIME, amount TINYINT);", 52 | "CREATE TABLE IF NOT EXISTS wind( created DATETIME, speed DECIMAL(3,1), gust DECIMAL(3,1), direction SMALLINT );" 53 | }; 54 | 55 | static const char *SQL_CREATE_INDEX[] = { 56 | "CREATE INDEX IF NOT EXISTS ix_pluviometer_created ON pluviometer(created);", 57 | "CREATE INDEX IF NOT EXISTS ix_temperature_created ON temperature(created);", 58 | "CREATE INDEX IF NOT EXISTS ix_humidity_created ON humidity(created);", 59 | "CREATE INDEX IF NOT EXISTS ix_wind_created ON wind(created);" 60 | }; 61 | 62 | sqlite3 *conn; 63 | int error = 0; 64 | struct tm *local; 65 | time_t t; 66 | 67 | void initializeDatabase() 68 | { 69 | char *errMsg = 0; 70 | int i; 71 | /* Open database */ 72 | error = sqlite3_open(DB_FILENAME, &conn); 73 | if (error) { 74 | fprintf(stderr, LANG_DB_ERROR_OPENING); 75 | exit(3); 76 | } 77 | /* Create database tables and indices, if not exits */ 78 | for (i = 0; i < 4; i++) { 79 | error = sqlite3_exec(conn, SQL_CREATE_TABLE[i], 0, 0, &errMsg); 80 | if (error != SQLITE_OK) { 81 | fprintf(stderr, LANG_DB_CREATE_TBL, errMsg, 82 | SQL_CREATE_TABLE[i]); 83 | exit(4); 84 | } 85 | 86 | error = sqlite3_exec(conn, SQL_CREATE_INDEX[i], 0, 0, &errMsg); 87 | if (error != SQLITE_OK) { 88 | fprintf(stderr, LANG_DB_CREATE_TBL, errMsg, 89 | SQL_CREATE_INDEX[i]); 90 | exit(4); 91 | } 92 | } 93 | } 94 | 95 | void savePluviometer(float amount) 96 | { 97 | static signed int old_hour = -1; 98 | static float old_value = -FLT_MAX; 99 | 100 | t = time(NULL); 101 | local = localtime(&t); 102 | 103 | /* Store if value has changed or older than an hour */ 104 | if (old_hour != local->tm_hour || old_value < amount) { 105 | char query[1024] = " "; 106 | sprintf(query, 107 | "INSERT INTO pluviometer VALUES (datetime('now', 'localtime'), %.2f);", 108 | amount); 109 | error = sqlite3_exec(conn, query, 0, 0, 0); 110 | if (error != SQLITE_OK) { 111 | fprintf(stderr, LANG_DB_PLUVIOMETER_QUERY, error); 112 | exit(5); 113 | } 114 | } 115 | 116 | old_hour = local->tm_hour; 117 | old_value = amount; 118 | } 119 | 120 | void saveTemperature(float temperature) 121 | { 122 | static signed int t_old_min = -1; 123 | static float old_value = -FLT_MAX; 124 | 125 | t = time(NULL); 126 | local = localtime(&t); 127 | 128 | /* Store if value has changed or not from same minute */ 129 | if (t_old_min != local->tm_min || old_value != temperature) { 130 | 131 | /* Check for invalid values */ 132 | float difference = old_value - temperature; 133 | if ((difference < -TEMP_DIFF || difference > TEMP_DIFF) 134 | && old_value != -FLT_MAX) { 135 | printf(LANG_DB_TEMP_DIFF, old_value, temperature); 136 | return; 137 | } 138 | 139 | char query[1024] = " "; 140 | sprintf(query, 141 | "INSERT INTO temperature VALUES (datetime('now', 'localtime'), %.1f);", 142 | temperature); 143 | error = sqlite3_exec(conn, query, 0, 0, 0); 144 | 145 | if (error != SQLITE_OK) { 146 | fprintf(stderr, LANG_DB_TEMP_QUERY, error); 147 | exit(6); 148 | } 149 | } 150 | 151 | t_old_min = local->tm_min; 152 | old_value = temperature; 153 | } 154 | 155 | void saveHumidity(unsigned int humidity) 156 | { 157 | static signed int h_old_min = -1; 158 | static float old_value = -FLT_MAX; 159 | 160 | t = time(NULL); 161 | local = localtime(&t); 162 | 163 | /* Store if value has changed or not from same minute */ 164 | if (h_old_min != local->tm_min || old_value != humidity) { 165 | 166 | /* Check for invalid values */ 167 | if (humidity <= 0 || humidity > 100) { 168 | fprintf(stderr, LANG_DB_HUMID_DIFF, humidity); 169 | return; 170 | } 171 | 172 | char query[1024] = " "; 173 | sprintf(query, 174 | "INSERT INTO humidity VALUES (datetime('now', 'localtime'), %i);", 175 | humidity); 176 | error = sqlite3_exec(conn, query, 0, 0, 0); 177 | 178 | if (error != SQLITE_OK) { 179 | fprintf(stderr, LANG_DB_PLUVIOMETER_QUERY, error); 180 | exit(7); 181 | } 182 | } 183 | 184 | h_old_min = local->tm_min; 185 | old_value = humidity; 186 | } 187 | 188 | void saveWind(float speed, float gust, unsigned int dir) 189 | { 190 | static time_t temp_time = 0; 191 | static time_t old_time = 0; 192 | static signed int counter = 0; 193 | static float windSpeed[WIND_SAMPLES] = { -1.0 }; 194 | static float windGust[WIND_SAMPLES] = { -1.0 }; 195 | static int windDir[WIND_SAMPLES] = { -1 }; 196 | static int rowid = 0; 197 | static int saved = 0; 198 | 199 | float x, y, rad; 200 | unsigned int i; 201 | 202 | time(&t); 203 | 204 | /* Check a new reading (aprox. every 30s). Discard incomplete data */ 205 | if (difftime(t, temp_time) > 20.0) { 206 | if (windSpeed[counter] > -1.0 && windGust[counter] > -1.0) 207 | counter++; 208 | i = counter % WIND_SAMPLES; 209 | windSpeed[i] = -1.0; 210 | windGust[i] = -1.0; 211 | windDir[i] = -1; 212 | temp_time = time(NULL); 213 | saved = 0; 214 | } 215 | 216 | /* Store current wind data */ 217 | i = counter % WIND_SAMPLES; 218 | if (speed > -1.0) { 219 | windSpeed[i] = speed; 220 | } else if (gust > -1.0) { 221 | windGust[i] = gust; 222 | windDir[i] = dir; 223 | } 224 | 225 | /* Return if only one value available or already saved */ 226 | if (windSpeed[i] < 0.0 || windGust[i] < 0.0 || saved == 1) 227 | return; 228 | 229 | /* Calculate averages 230 | * Wind dir from http://www.control.com/thread/1026210133 231 | * By M.A.Saghafi on 11 October, 2010 - 8:26 am and M Barnes on 18 May, 2011 - 6:48 am */ 232 | ++counter; 233 | speed = 0.0; 234 | for (i = 0; i < counter; i++) { 235 | #if DEBUG > 2 236 | fprintf(stderr, 237 | "[AVG] %i: Speed: %.1f\tGust: %.1f\tDir: %i\tc: %i\n", 238 | i, windSpeed[i], windGust[i], windDir[i], counter); 239 | #endif 240 | dir = i % WIND_SAMPLES; 241 | rad = M_PI / 180 * windDir[dir]; 242 | x += -windSpeed[dir] * sin(rad); 243 | y += -windSpeed[dir] * cos(rad); 244 | speed += windSpeed[dir]; 245 | if (windGust[dir] > gust) 246 | gust = windGust[dir]; 247 | } 248 | 249 | speed = speed / counter; 250 | x = x / counter; 251 | y = y / counter; 252 | 253 | if (x == 0) 254 | dir = 0; 255 | else if (x > 0) 256 | dir = 270 - 180 / M_PI * atan(y / x); 257 | else 258 | dir = 90 - 180 / M_PI * atan(y / x); 259 | dir = dir % 360; 260 | 261 | /* Update row if time < WIND_SAVE_INTERVALL */ 262 | char query[128] = " "; 263 | if (difftime(t, old_time) < WIND_SAVE_INTERVALL && rowid > 0) { 264 | sprintf(query, 265 | "UPDATE wind SET created=datetime('now','localtime'), speed=%.1f, gust=%.1f, direction=%i WHERE rowid=%i;", 266 | speed, gust, dir, rowid); 267 | error = sqlite3_exec(conn, query, 0, 0, 0); 268 | if (error != SQLITE_OK) 269 | fprintf(stderr, LANG_DB_WIND_QUERY, error, query); 270 | 271 | --counter; 272 | /* Insert a new row */ 273 | } else { 274 | sprintf(query, 275 | "INSERT INTO wind VALUES (datetime('now', 'localtime'), %.1f, %.1f, %i);", 276 | speed, gust, dir); 277 | error = sqlite3_exec(conn, query, 0, 0, 0); 278 | if (error != SQLITE_OK) 279 | fprintf(stderr, LANG_DB_WIND_QUERY, error, query); 280 | 281 | rowid = (int)sqlite3_last_insert_rowid(conn); 282 | counter = 0; 283 | old_time = time(NULL); 284 | windGust[0] = -1.0; 285 | windDir[0] = -1.0; 286 | } 287 | saved = 1; 288 | #if DEBUG > 1 289 | fprintf(stderr, "Query: %s\n", query); 290 | #endif 291 | } 292 | -------------------------------------------------------------------------------- /reader/auriol-reader.c: -------------------------------------------------------------------------------- 1 | #define LANGUAGE_ENGLISH 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "db.h" 10 | 11 | #define DEBUG 0 12 | #define RECIEVE_PIN 2 13 | 14 | /* Below values are experimental and depend on how fast particular Raspberry Pi is */ 15 | /* Below values define how many polled "1" from receiver hardware mean given logical signal */ 16 | /* Values used in this code work on Pi Model B Revision 2.0 (000e) without running other heavy CPU processes */ 17 | #define SYNCHRO_LENGTH 168 /* 168; 9 ms */ 18 | #define SEPARATOR_LENGTH 8 /* 8..9; 1 ms */ 19 | #define ZERO_LENGTH 38 /* 38; 2 ms */ 20 | #define ONE_LENGTH 76 /* 76..78; 4 ms */ 21 | #define LENGTHS_MARGIN 7 /* 5..7; .5 ms */ 22 | 23 | #ifdef LANGUAGE_ENGLISH 24 | static const char LANG_PROGRAM_TITLE[] = 25 | "433 MHz Wireless Weather Station Decoder running on Raspberry Pi.\n"; 26 | static const char LANG_BATTERY_OK[] = " Battery: OK\n"; 27 | static const char LANG_BATTERY_REPLACE[] = 28 | " Battery: Replace (<2.6V)!\n"; 29 | static const char LANG_TRANS_FILE_OPEN_ERR[] = 30 | "ERROR: Could not open transmission data file!"; 31 | static const char LANG_TRANS_FILE_END[] = "End of transmission data."; 32 | static const char LANG_INFO_PLUVIOMETER[] = "Rain: %.2f mm"; 33 | static const char LANG_INFO_WIND_AVG[] = "Wind Speed: %.1f m/s"; 34 | static const char LANG_INFO_WIND_DIR_GUST[] = 35 | "Wind Direction: %i deg Wind Gust: %.1f m/s"; 36 | static const char LANG_INFO_TEMP_HUMIDITY[] = 37 | "Temperature: %.1f C Humidity: %i %%"; 38 | static const char LANG_INFO_CRC_DIFFER[] = 39 | "ReceivedChecksum: %02x CalculatedChecksum: %02x Equal: %d\n"; 40 | static const char LANG_WARNING_CRC[] = 41 | "WARNING: Checksum failed. Data will NOT be saved!\n"; 42 | static const char LANG_DATE_TIME[] = "[%i-%02i-%02i %02i:%02i:%02i] "; 43 | 44 | #else 45 | static const char LANG_PROGRAM_TITLE[] = 46 | "Dekoder czujnikow bezprzewodowych 433 MHz na Raspberry Pi uruchomiony.\n"; 47 | static const char LANG_BATTERY_OK[] = " Bateria: OK\n"; 48 | static const char LANG_BATTERY_REPLACE[] = 49 | " Bateria: do wymiany (napiecie < 2.6V)\n"; 50 | static const char LANG_TRANS_FILE_OPEN_ERR[] = 51 | "Could not open file with transmission data. Terminating. Good-bye!"; 52 | static const char LANG_TRANS_FILE_END[] = 53 | "Reached end of file with transmission data. Terminating. Good-bye!"; 54 | static const char LANG_INFO_PLUVIOMETER[] = "Deszczomierz: %.2f mm"; 55 | static const char LANG_INFO_WIND_AVG[] = "Srednia predkosc wiatru: %.2f m/s"; 56 | static const char LANG_INFO_WIND_DIR_GUST[] = 57 | "Kierunek wiatru: %i stopni Poryw: %.2f m/s"; 58 | static const char LANG_INFO_TEMP_HUMIDITY[] = 59 | "Temperatura: %.2f C Wilgotnosc: %i %%"; 60 | static const char LANG_INFO_CRC_DIFFER[] = 61 | "readedChecksum=%02x computedChecksum=%02x equal=%d\n"; 62 | static const char LANG_WARNING_CRC[] = 63 | "WARNING! Checksum not confirmed. Data will NOT be saved in database\n"; 64 | static const char LANG_DATE_TIME[] = "[%i-%02i-%02i %02i:%02i:%02i] "; 65 | #endif 66 | 67 | unsigned char readLevel(); 68 | int findEncodedBitLength(unsigned char level); 69 | void resetRecording(); 70 | void printArray(); 71 | void decodeBitLength(int length); 72 | void decodeArray(); 73 | void decodePluviometer(); 74 | void decodeWindData(); 75 | bool combinedSensorChecksumConfirmed(); 76 | void printTime(); 77 | 78 | FILE *pFile = NULL; 79 | int globalLevelsCounter = 0; 80 | int levelsCounter = 0; 81 | int levelOneCounter = 0; 82 | unsigned char previousEncodedBitInRange = 0; 83 | unsigned char recording = 0; 84 | unsigned char encodedBits[36] = 85 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 87 | }; 88 | 89 | unsigned char encodedBitsIndex = 0; 90 | 91 | int main(int argc, char *argv[]) 92 | { 93 | initializeDatabase(); 94 | 95 | wiringPiSetup(); 96 | 97 | printTime(); 98 | printf(LANG_PROGRAM_TITLE); 99 | 100 | while (1) { 101 | int level = digitalRead(RECIEVE_PIN); 102 | 103 | int bitLength = findEncodedBitLength(level); 104 | decodeBitLength(bitLength); 105 | 106 | delayMicroseconds(50); 107 | 108 | globalLevelsCounter++; 109 | } 110 | return 0; 111 | } 112 | 113 | /* Read GPIO level */ 114 | unsigned char readLevel() 115 | { 116 | int c = fgetc(pFile); 117 | if (c != EOF) { 118 | return c - '0'; 119 | } else { 120 | puts(LANG_TRANS_FILE_END); 121 | exit(2); 122 | } 123 | } 124 | 125 | /* Analyze transmission bit after bit */ 126 | int findEncodedBitLength(unsigned char level) 127 | { 128 | levelsCounter++; 129 | 130 | /* Out of range */ 131 | if (levelsCounter > 132 | SYNCHRO_LENGTH + LENGTHS_MARGIN + SEPARATOR_LENGTH + 133 | LENGTHS_MARGIN) { 134 | levelsCounter = 1; 135 | resetRecording(); 136 | previousEncodedBitInRange = 1; 137 | } 138 | 139 | int encodedBitLength = -1; 140 | if (level == 0) { 141 | if (levelOneCounter > SEPARATOR_LENGTH - LENGTHS_MARGIN 142 | && levelOneCounter < SEPARATOR_LENGTH + LENGTHS_MARGIN) { 143 | if (previousEncodedBitInRange) { 144 | encodedBitLength = 145 | levelsCounter - levelOneCounter; 146 | } 147 | levelsCounter = 0; 148 | previousEncodedBitInRange = 1; 149 | } 150 | levelOneCounter = 0; 151 | } else { 152 | levelOneCounter++; 153 | } 154 | return encodedBitLength; 155 | } 156 | 157 | void resetRecording() 158 | { 159 | recording = 0; 160 | memset(encodedBits, 2, sizeof(encodedBits[0]) * 36); 161 | encodedBitsIndex = 0; 162 | } 163 | 164 | void decodeBitLength(int length) 165 | { 166 | /* Signal length too short */ 167 | if (length < ZERO_LENGTH - LENGTHS_MARGIN) { 168 | return; 169 | } 170 | 171 | /* Sync bit - Start of data package */ 172 | if (length > SYNCHRO_LENGTH - LENGTHS_MARGIN * 2 173 | && length < SYNCHRO_LENGTH + LENGTHS_MARGIN * 2 && !recording) { 174 | resetRecording(); 175 | recording = 1; 176 | 177 | /* One */ 178 | } else if (length > ONE_LENGTH - LENGTHS_MARGIN 179 | && length < ONE_LENGTH + LENGTHS_MARGIN && recording) { 180 | encodedBits[encodedBitsIndex++] = 1; 181 | 182 | /* Zero */ 183 | } else if (length > ZERO_LENGTH - LENGTHS_MARGIN 184 | && length < ZERO_LENGTH + LENGTHS_MARGIN && recording) { 185 | encodedBits[encodedBitsIndex++] = 0; 186 | 187 | /* Sync bit - End of data package */ 188 | } else if (length > SYNCHRO_LENGTH - LENGTHS_MARGIN * 2 189 | && length < SYNCHRO_LENGTH + LENGTHS_MARGIN * 2 190 | && recording) { 191 | decodeArray(); 192 | resetRecording(); 193 | recording = 1; 194 | 195 | /* Signal length too long */ 196 | } else if (recording) { 197 | resetRecording(); 198 | } 199 | } 200 | 201 | void printArray() 202 | { 203 | if (encodedBitsIndex == 0) 204 | return; 205 | #if DEBUG > 1 206 | int i; 207 | struct tm *local; 208 | time_t t = time(NULL); 209 | local = localtime(&t); 210 | 211 | fprintf(stderr, LANG_DATE_TIME, (local->tm_year + 1900), 212 | (local->tm_mon) + 1, local->tm_mday, local->tm_hour, 213 | local->tm_min, local->tm_sec); 214 | 215 | for (i = 0; i < 36; i++) 216 | fprintf(stderr, "%i", encodedBits[i]); 217 | fprintf(stderr, "\n"); 218 | #endif 219 | } 220 | 221 | void decodeArray() 222 | { 223 | if (encodedBitsIndex < 36) { 224 | return; 225 | } 226 | printArray(); 227 | decodePluviometer(); 228 | decodeWindData(); 229 | } 230 | 231 | void decodePluviometer() 232 | { 233 | if (encodedBits[9] && encodedBits[10] && !encodedBits[11] 234 | && encodedBits[12] && encodedBits[13] && !encodedBits[14] 235 | && !encodedBits[15]) { 236 | unsigned int rain = 0; 237 | int i; 238 | for (i = 16; i < 32; i++) { 239 | rain |= encodedBits[i] << (i - 16); 240 | } 241 | 242 | printTime(); 243 | float rainFinal = (float)rain / 4; 244 | printf(LANG_INFO_PLUVIOMETER, (float)rainFinal); 245 | savePluviometer(rainFinal); 246 | 247 | if (encodedBits[8]) { 248 | printf(LANG_BATTERY_REPLACE); 249 | } else { 250 | printf(LANG_BATTERY_OK); 251 | } 252 | } 253 | } 254 | 255 | void decodeWindData() 256 | { 257 | /* Average Wind Speed */ 258 | if (encodedBits[9] && encodedBits[10] && encodedBits[12] 259 | && !encodedBits[13] && !encodedBits[14] && !encodedBits[15] 260 | && !encodedBits[16] 261 | && !encodedBits[17] && !encodedBits[18] && !encodedBits[19] 262 | && !encodedBits[20] && !encodedBits[21] && !encodedBits[22] 263 | && !encodedBits[23]) { 264 | unsigned int windAverageSpeed = 0; 265 | int i; 266 | for (i = 24; i < 32; i++) { 267 | windAverageSpeed |= encodedBits[i] << (i - 24); 268 | } 269 | 270 | printTime(); 271 | printf(LANG_INFO_WIND_AVG, (float)windAverageSpeed / 5); 272 | 273 | if (encodedBits[8]) { 274 | printf(LANG_BATTERY_REPLACE); 275 | } else { 276 | printf(LANG_BATTERY_OK); 277 | } 278 | 279 | saveWind((float)windAverageSpeed / 5, -1.0, -1); 280 | 281 | /* Wind gust & direction */ 282 | } else if (encodedBits[9] && encodedBits[10] && encodedBits[12] 283 | && encodedBits[13] && encodedBits[14]) { 284 | unsigned int direction = 0; 285 | unsigned int windGust = 0; 286 | int i; 287 | for (i = 15; i < 24; i++) { 288 | direction |= encodedBits[i] << (i - 15); 289 | } 290 | for (i = 24; i < 32; i++) { 291 | windGust |= encodedBits[i] << (i - 24); 292 | } 293 | 294 | printTime(); 295 | printf(LANG_INFO_WIND_DIR_GUST, direction, (float)windGust / 5); 296 | 297 | if (encodedBits[8]) { 298 | printf(LANG_BATTERY_REPLACE); 299 | } else { 300 | printf(LANG_BATTERY_OK); 301 | } 302 | 303 | saveWind(-1.0, (float)windGust / 5, direction); 304 | 305 | /* Temperature & Humidity */ 306 | } else if (!encodedBits[9] || !encodedBits[10]) { 307 | int temperature = 0; 308 | int i; 309 | for (i = 12; i < 23; i++) { 310 | temperature |= encodedBits[i] << (i - 12); 311 | } 312 | if (encodedBits[23]) { 313 | temperature = -2048 + temperature; 314 | } 315 | float temperatureFinal = (float)temperature / 10; 316 | 317 | unsigned int humidityOnes = 0; 318 | for (i = 24; i < 28; i++) { 319 | humidityOnes |= encodedBits[i] << (i - 24); 320 | } 321 | 322 | unsigned int humidityTens = 0; 323 | for (i = 28; i < 32; i++) { 324 | humidityTens |= encodedBits[i] << (i - 28); 325 | } 326 | 327 | unsigned int humidity = humidityTens * 10 + humidityOnes; 328 | 329 | printTime(); 330 | printf(LANG_INFO_TEMP_HUMIDITY, temperatureFinal, humidity); 331 | 332 | if (encodedBits[8]) { 333 | printf(LANG_BATTERY_REPLACE); 334 | } else { 335 | printf(LANG_BATTERY_OK); 336 | } 337 | 338 | if (combinedSensorChecksumConfirmed()) { 339 | saveTemperature(temperatureFinal); 340 | saveHumidity(humidity); 341 | } else { 342 | fprintf(stderr, LANG_WARNING_CRC); 343 | } 344 | } 345 | } 346 | 347 | bool combinedSensorChecksumConfirmed() 348 | { 349 | unsigned char computedChecksum = 0x0F; 350 | int i = 0, j = 0; 351 | for (i = 0; i < 32; i += 4) { 352 | unsigned char nibble = 0; 353 | for (j = 0; j < 4; j++) { 354 | nibble |= encodedBits[i + j] << (j); 355 | } 356 | computedChecksum -= nibble; 357 | } 358 | computedChecksum &= 0x0F; 359 | 360 | unsigned int readedChecksum = 0x00; 361 | for (i = 32; i < 36; i++) { 362 | readedChecksum |= encodedBits[i] << (i - 32); 363 | } 364 | 365 | bool checksumsAreEqual = (readedChecksum == computedChecksum); 366 | 367 | if (!checksumsAreEqual) { 368 | printTime(); 369 | fprintf(stderr, LANG_INFO_CRC_DIFFER, readedChecksum, 370 | computedChecksum, checksumsAreEqual); 371 | } 372 | 373 | return checksumsAreEqual; 374 | } 375 | 376 | void printTime() 377 | { 378 | struct tm *local; 379 | time_t t; 380 | 381 | t = time(NULL); 382 | local = localtime(&t); 383 | printf(LANG_DATE_TIME, (local->tm_year + 1900), (local->tm_mon) + 1, 384 | local->tm_mday, local->tm_hour, local->tm_min, local->tm_sec); 385 | } 386 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------