/* hw2300.c * * Version 1.0 * * Control WS2300 weather station * * Copyright 2003-2005, Kenneth Lavrsen * This program is published under the GNU General Public license * * Update History: * 1.0 2008 Dec 10 Thomas Guenneguez Inital version sent to Kenneth */ #include "rw2300.h" /******************************************************************** * print_usage prints a short user guide * * Input: none * * Output: prints to stdout * * Returns: exits program * ********************************************************************/ void print_usage(void) { printf("\n"); printf("hw2300 - Read data from your WS-2300 weather station.\n"); printf("Version %s (C)2004 Kenneth Lavrsen.\n", VERSION); printf("This program is released under the GNU General Public License (GPL)\n\n"); printf("Usage:\n"); printf("With default config file: hw2300 lst-file\n"); printf("With given config file: hw2300 lst-file config-file\n"); exit(0); } /********** MAIN PROGRAM ************************************************ * * This program reads all current and min/max data from a WS2300 * weather station and write it to an LST file. * * It takes two parameters. lst_file_path and config_file_path * * If the config_file_path parameter is omitted the program will look * at the default paths. See the open2300.conf-dist file for info * ***********************************************************************/ int main(int argc, char *argv[]) { WEATHERSTATION ws2300; char datestring[50]; //used to hold the date stamp for the log file const char *directions[]= {"N","NNE","NE","ENE","E","ESE","SE","SSE", "S","SSW","SW","WSW","W","WNW","NW","NNW"}; double winddir[6]; char tendency[15]; char forecast[15]; int tendency_int, forecast_int; struct config_type config; double tempfloat; int tempint; struct timestamp currenttime; time_t basictime; //char datestring[100]; //used to hold the date stamp for the log file FILE *fileptr; if (argc < 1 || argc > 2) { print_usage(); exit(-1); } get_configuration(&config, argv[2]); if ( (ws2300 = open_weatherstation(config.serial_device_name)) < 0 ) { printf("Cannot open serial device %s\n", config.serial_device_name); exit(-1); } fileptr = fopen(argv[1], "w"); if (fileptr == NULL) { printf("Cannot open file %s\n",argv[1]); exit(-1); } /* File header */ fprintf(fileptr, "[header]\n"); fprintf(fileptr, "programm_name = \"hw2300\"\n"); fprintf(fileptr, "programm_version = \"Ver. %s beta release\"\n", VERSION); fprintf(fileptr, "file_name = \"%s\"\n", argv[1]); fprintf(fileptr, "file_format_version = \"ver. 1.0\"\n\n"); /* date, time */ basictime = time(NULL); fprintf(fileptr, "[time]\n"); tempfloat = (double) basictime + 2208988800; fprintf(fileptr, "last_actualisation = %.0Lf\n", tempfloat); strftime(datestring, sizeof(datestring), "%a %b %d %H:%m:%S %Y", localtime(&basictime)); fprintf(fileptr, "last_actualisation_date_string = \"%s\"\n", datestring); fprintf(fileptr, "\n"); /* tendency_forecast */ tendency_forecast(ws2300, tendency, forecast); if ( strcmp(tendency, "Steady")) tendency_int = 0; else if ( strcmp(tendency, "Rising")) tendency_int = 1; else if ( strcmp(tendency, "Falling")) tendency_int = 2; else tendency_int = -1; if ( strcmp(forecast, "Rainy")) forecast_int = 0; else if (strcmp(forecast, "Cloudy")) forecast_int = 1; else if ( strcmp(forecast, "Sunny")) forecast_int = 2; else forecast_int = -1; fprintf(fileptr, "[weather_picture]\n"); fprintf(fileptr, "comment = \"-1=not valid, 0=rain, 1=cloud, 2=sun\"\n"); fprintf(fileptr, "number = %i\n\n", forecast_int); fprintf(fileptr, "[weather_tendency]\n"); fprintf(fileptr, "comment_1 = \"-1=not valid, 0=no change of air pressure\"\n"); fprintf(fileptr, "comment_2 = \" 1=air pressure rising, 2=air pressure falling\"\n"); fprintf(fileptr, "number = %i\n\n", tendency_int); /* */ fprintf(fileptr, "[indoor_temperature]\n"); fprintf(fileptr, "deg_C = \"%.1f\"\n", temperature_indoor(ws2300, CELCIUS)); fprintf(fileptr, "deg_F = \"%.1f\"\n\n", temperature_indoor(ws2300, FAHRENHEIT)); /* */ fprintf(fileptr, "[outdoor_temperature]\n"); fprintf(fileptr, "deg_C = \"%.1f\"\n", temperature_outdoor(ws2300, CELCIUS)); fprintf(fileptr, "deg_F = \"%.1f\"\n\n", temperature_outdoor(ws2300, FAHRENHEIT)); /* */ fprintf(fileptr, "[indoor_humidity]\n"); fprintf(fileptr, "percent = \"%.i\"\n\n", humidity_indoor(ws2300)); /* */ fprintf(fileptr, "[outdoor_humidity]\n"); fprintf(fileptr, "percent = \"%.i\"\n\n", humidity_outdoor(ws2300)); /* */ fprintf(fileptr, "[dewpoint]\n"); fprintf(fileptr, "deg_C = \"%.1f\"\n", dewpoint(ws2300, CELCIUS)); fprintf(fileptr, "deg_F = \"%.1f\"\n\n", dewpoint(ws2300, FAHRENHEIT)); /* */ fprintf(fileptr, "[windchill]\n"); fprintf(fileptr, "deg_C = \"%.1f\"\n", windchill(ws2300, CELCIUS)); fprintf(fileptr, "deg_F = \"%.1f\"\n\n", windchill(ws2300, FAHRENHEIT)); /* */ fprintf(fileptr, "[wind_speed]\n"); fprintf(fileptr, "mps = \"%.1f\"\n", wind_all(ws2300, METERS_PER_SECOND, &tempint, winddir)); fprintf(fileptr, "kmh = \"%.1f\"\n", wind_all(ws2300, KILOMETERS_PER_HOUR, &tempint, winddir)); fprintf(fileptr, "mph = \"%.1f\"\n", wind_all(ws2300, MILES_PER_HOUR, &tempint, winddir)); fprintf(fileptr, "[wind_direction]\n"); wind_all(ws2300, METERS_PER_SECOND, &tempint, winddir); fprintf(fileptr, "deg = \"%.1f\"\n", winddir[0]); fprintf(fileptr, "name = \"%s\"\n\n", directions[tempint]); /* */ fprintf(fileptr, "[rain_total]\n"); fprintf(fileptr, "mm = \"%.1f\"\n", rain_total_all(ws2300, MILLIMETERS, ¤ttime)); fprintf(fileptr, "inch = \"%.2f\"\n\n", rain_total_all(ws2300, INCHES, ¤ttime)); /* */ fprintf(fileptr, "[rain_24h]\n"); fprintf(fileptr, "mm = \"%.1f\"\n", rain_24h_all(ws2300, MILLIMETERS, &tempfloat, ¤ttime)); fprintf(fileptr, "inch = \"%.2f\"\n\n", rain_24h_all(ws2300, INCHES, &tempfloat, ¤ttime)); /* */ fprintf(fileptr, "[rain_1h]\n"); fprintf(fileptr, "mm = \"%.1f\"\n", rain_1h_all(ws2300, MILLIMETERS, &tempfloat, ¤ttime)); fprintf(fileptr, "inch = \"%.2f\"\n\n", rain_1h_all(ws2300, INCHES, &tempfloat, ¤ttime)); /* */ fprintf(fileptr, "[pressure_absolute]\n"); fprintf(fileptr, "hpa = \"%.1f\"\n", abs_pressure(ws2300, HECTOPASCAL)); fprintf(fileptr, "inhg = \"%.2f\"\n\n", abs_pressure(ws2300, INCHES_HG)); fprintf(fileptr, "[pressure_relative]\n"); fprintf(fileptr, "hpa = \"%.1f\"\n", rel_pressure(ws2300, HECTOPASCAL)); fprintf(fileptr, "inhg = \"%.2f\"\n\n", rel_pressure(ws2300, INCHES_HG)); fflush(fileptr); fclose(fileptr); close_weatherstation(ws2300); return (0); }