diff -Nur open2300-1.10/ham2300.c open2300-1.10/ham2300.c --- open2300-1.10/ham2300.c 1970-01-01 12:00:00.000000000 +1200 +++ open2300-1.10/ham2300.c 2006-07-31 09:28:46.000000000 +1200 @@ -0,0 +1,126 @@ +/* open2300 - ham2300.c + * + * Version 1.10 + * + * Control WS2300 weather station + * + * Copyright 2004-2005, Kenneth Lavrsen + * This program is published under the GNU General Public license + */ + +#define DEBUG 0 // ham2300 stops writing to standard out if setting this to 0 + +#include "rw2300.h" + +/********** MAIN PROGRAM ************************************************ + * + * This program reads all current weather data from a WS2300 + * and sends it to Hamweather + * + * It takes one parameter which is the config file name with path + * If this 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; + struct config_type config; + unsigned char urlline[3000] = ""; + char datestring[50]; //used to hold the date stamp for the log file + double tempfloat_a; + double tempfloat_b; + time_t basictime; + + get_configuration(&config, argv[1]); + + ws2300 = open_weatherstation(config.serial_device_name); + + + /* START WITH URL, ID AND PASSWORD */ + + sprintf(urlline, "http://%s%s?ID=%s&PASSWORD=%s", + HAMWEATHER_BASEURL,HAMWEATHER_PATH, + config.hamweather_id,config.hamweather_password); + + /* GET DATE AND TIME FOR URL */ + + time(&basictime); + basictime = basictime - atof(config.timezone) * 60 * 60; + strftime(datestring,sizeof(datestring),"&dateutc=%Y-%m-%d+%H%%3A%M%%3A%S", + localtime(&basictime)); + sprintf(urlline, "%s%s", urlline, datestring); + + + /* READ WIND SPEED AND DIRECTION - miles/hour for Hamweather */ + + tempfloat_a = wind_current(ws2300, MILES_PER_HOUR, &tempfloat_b); + sprintf(urlline,"%s&winddir=%.f", urlline, tempfloat_b); + sprintf(urlline,"%s&windspeedmph=%.1f", urlline, tempfloat_a); + + /* WRITE 0 windgust information (in case value required) */ + + sprintf(urlline,"%s&windgust=0.0", urlline); + + + /* READ TEMPERATURE OUTDOOR - deg F for Hamweather */ + + sprintf(urlline, "%s&tempf=%.2f", urlline, + temperature_outdoor(ws2300, FAHRENHEIT) ); + + + /* READ RAIN 1H - inches for Hamweather */ + + sprintf(urlline,"%s&rainin=%.2f", urlline, rain_1h(ws2300, INCHES) ); + + + /* READ RELATIVE PRESSURE - Inches of Hg for Hamweather */ + + sprintf(urlline,"%s&baromin=%.2f",urlline, + rel_pressure(ws2300, INCHES_HG) ); + + + /* READ DEWPOINT - deg F for Hamweather*/ + + sprintf(urlline, "%s&dewptf=%.2f", urlline, dewpoint(ws2300, FAHRENHEIT) ); + + + /* READ RELATIVE HUMIDITY OUTDOOR */ + + sprintf(urlline, "%s&humidity=%d", urlline, humidity_outdoor(ws2300) ); + + + /* READ RAIN 24H - inches for Hamweather + + sprintf(urlline,"%s&dailyrainin=%.2f", urlline, rain_24h(ws2300, INCHES) ); + + */ + + /* WRITE blank weather and cloud information (in case value required) */ + + sprintf(urlline,"%s&weather=%%20", urlline); + sprintf(urlline,"%s&clouds=%%20", urlline); + + + /* ADD SOFTWARE TYPE AND ACTION */ + sprintf(urlline,"%s&softwaretype=%s%s&action=updateraw",urlline, + HAMWEATHER_SOFTWARETYPE,VERSION); + + + /* SEND DATA TO WEATHER UNDERGROUND AS HTTP REQUEST */ + /* or print the URL if DEBUG is enabled in the top of this file */ + + close_weatherstation(ws2300); + + if (DEBUG) + { + printf("%s\n",urlline); + } + else + { + http_request_url(urlline, HAMWEATHER_BASEURL); + } + + return(0); +} + diff -Nur open2300-1.10/linux2300.c open2300-1.10/linux2300.c --- open2300-1.10/linux2300.c 2005-03-05 21:26:58.000000000 +1300 +++ open2300-1.10/linux2300.c 2006-07-31 09:10:56.000000000 +1200 @@ -235,13 +235,14 @@ * * Inputs: urlline - URL to Weather Underground with path and data * as a pointer to char array (string) + * baseurl - hostname of site to send data to * * Returns: 0 on success and -1 if fail. * - * Action: Send a http request to Weather Underground + * Action: Send a http request to a weather site * ********************************************************************/ -int http_request_url(char *urlline) +int http_request_url(char *urlline, char *baseurl) { int sockfd; struct hostent *hostinfo; @@ -249,7 +250,7 @@ char buffer[1024]; int bytes_read; - if ( (hostinfo = gethostbyname(WEATHER_UNDERGROUND_BASEURL)) == NULL ) + if ( (hostinfo = gethostbyname(baseurl)) == NULL ) { perror("Host not known by DNS server or DNS server not working"); return(-1); diff -Nur open2300-1.10/Makefile open2300-1.10/Makefile --- open2300-1.10/Makefile 2005-03-15 20:14:48.000000000 +1300 +++ open2300-1.10/Makefile 2006-07-24 16:10:03.000000000 +1200 @@ -23,6 +23,7 @@ LOGOBJ = log2300.o rw2300.o linux2300.o win2300.o FETCHOBJ = fetch2300.o rw2300.o linux2300.o win2300.o WUOBJ = wu2300.o rw2300.o linux2300.o win2300.o +HAMOBJ = ham2300.c rw2300.o linux2300.o win2300.o CWOBJ = cw2300.o rw2300.o linux2300.o win2300.o DUMPOBJ = dump2300.o rw2300.o linux2300.o win2300.o HISTOBJ = history2300.o rw2300.o linux2300.o win2300.o @@ -46,7 +47,7 @@ ####### Build rules -all: open2300 dump2300 log2300 fetch2300 wu2300 cw2300 history2300 histlog2300 bin2300 xml2300 light2300 interval2300 minmax2300 +all: open2300 dump2300 log2300 fetch2300 wu2300 cw2300 history2300 histlog2300 bin2300 xml2300 light2300 interval2300 minmax2300 ham2300 open2300 : $(OBJ) $(CC) $(CFLAGS) -o $@ $(OBJ) $(CC_LDFLAGS) @@ -63,6 +64,9 @@ wu2300 : $(WUOBJ) $(CC) $(CFLAGS) -o $@ $(WUOBJ) $(CC_LDFLAGS) $(CC_WINFLAG) +ham2300 : $(HAMOBJ) + $(CC) $(CFLAGS) -o $@ $(HAMOBJ) $(CC_LDFLAGS) $(CC_WINFLAG) + cw2300 : $(CWOBJ) $(CC) $(CFLAGS) -o $@ $(CWOBJ) $(CC_LDFLAGS) $(CC_WINFLAG) @@ -106,12 +110,13 @@ $(INSTALL) light2300 $(bindir) $(INSTALL) interval2300 $(bindir) $(INSTALL) minmax2300 $(bindir) + $(INSTALL) ham2300 $(bindir) uninstall: - rm -f $(bindir)/open2300 $(bindir)/dump2300 $(bindir)/log2300 $(bindir)/fetch2300 $(bindir)/wu2300 $(bindir)/cw2300 $(bindir)/xml2300 $(bindir)/light2300 $(bindir)/interval2300 $(bindir)/minmax2300 + rm -f $(bindir)/open2300 $(bindir)/dump2300 $(bindir)/log2300 $(bindir)/fetch2300 $(bindir)/wu2300 $(bindir)/cw2300 $(bindir)/xml2300 $(bindir)/light2300 $(bindir)/interval2300 $(bindir)/minmax2300 $(bindir)/ham2300 clean: - rm -f *~ *.o open2300 dump2300 log2300 fetch2300 wu2300 cw2300 history2300 histlog2300 bin2300 xml2300 mysql2300 pgsql2300 light2300 interval2300 minmax2300 + rm -f *~ *.o open2300 dump2300 log2300 fetch2300 wu2300 cw2300 history2300 histlog2300 bin2300 xml2300 mysql2300 pgsql2300 light2300 interval2300 minmax2300 ham2300 cleanexe: - rm -f *~ *.o open2300.exe dump2300.exe log2300.exe fetch2300.exe wu2300.exe cw2300.exe history2300.exe histlog2300.exe bin2300.exe xml2300.exe mysql2300.exe pgsql2300.exe light2300.exe interval2300.exe minmax2300.exe \ No newline at end of file + rm -f *~ *.o open2300.exe dump2300.exe log2300.exe fetch2300.exe wu2300.exe cw2300.exe history2300.exe histlog2300.exe bin2300.exe xml2300.exe mysql2300.exe pgsql2300.exe light2300.exe interval2300.exe minmax2300.exe ham2300.exe diff -Nur open2300-1.10/open2300-dist.conf open2300-1.10/open2300-dist.conf --- open2300-1.10/open2300-dist.conf 2005-02-28 04:44:56.000000000 +1300 +++ open2300-1.10/open2300-dist.conf 2006-07-31 09:20:43.000000000 +1200 @@ -52,6 +52,12 @@ WEATHER_UNDERGROUND_PASSWORD WUPASSWORD # Password for Weather Underground +#### HAMWEATHER variables (used only by ham2300) + +HAMWEATHER_ID HAMID # ID received from Hamweather +HAMWEATHER_PASSWORD HAMPASSWORD # Password for Hamweather + + ### MYSQL Settings (only used by mysql2300) MYSQL_HOST localhost # Localhost or IP address/host name diff -Nur open2300-1.10/rw2300.c open2300-1.10/rw2300.c --- open2300-1.10/rw2300.c 2005-03-05 21:19:30.000000000 +1300 +++ open2300-1.10/rw2300.c 2006-07-31 09:11:38.000000000 +1200 @@ -2403,6 +2403,8 @@ config->num_hosts = 2; // default number of defined hosts strcpy(config->weather_underground_id, "WUID"); // Weather Underground ID strcpy(config->weather_underground_password, "WUPassword"); // Weather Underground Password + strcpy(config->weather_underground_id, "HAMID"); // Hamweather ID + strcpy(config->weather_underground_password, "HAMPassword"); // Hamweather Password strcpy(config->timezone, "1"); // Timezone, default CET config->wind_speed_conv_factor = 1.0; // Speed dimention, m/s is default config->temperature_conv = 0; // Temperature in Celcius @@ -2490,6 +2492,18 @@ continue; } + if ((strcmp(token,"HAMWEATHER_ID")==0) && (strlen(val)!=0)) + { + strcpy(config->hamweather_id, val); + continue; + } + + if ((strcmp(token,"HAMWEATHER_PASSWORD")==0)&&(strlen(val)!=0)) + { + strcpy(config->hamweather_password, val); + continue; + } + if ((strcmp(token,"TIMEZONE")==0) && (strlen(val) != 0)) { strcpy(config->timezone, val); diff -Nur open2300-1.10/rw2300.h open2300-1.10/rw2300.h --- open2300-1.10/rw2300.h 2005-03-05 21:29:13.000000000 +1300 +++ open2300-1.10/rw2300.h 2006-07-31 09:06:42.000000000 +1200 @@ -47,6 +47,11 @@ #define MILLIBARS 1.0 #define INCHES_HG 33.8638864 +/* ONLY EDIT THESE IF HAMWEATHER CHANGES URL */ +#define HAMWEATHER_BASEURL "www.hamweather.net" +#define HAMWEATHER_PATH "/weatherstations/pwsupdate.php" + +#define HAMWEATHER_SOFTWARETYPE "open2300%20v" /* ONLY EDIT THESE IF WEATHER UNDERGROUND CHANGES URL */ #define WEATHER_UNDERGROUND_BASEURL "weatherstation.wunderground.com" @@ -71,6 +76,8 @@ int num_hosts; // total defined hosts char weather_underground_id[30]; char weather_underground_password[50]; + char hamweather_id[30]; + char hamweather_password[50]; char timezone[6]; //not integer because of half hour time zones double wind_speed_conv_factor; //from m/s to km/h or miles/hour int temperature_conv; //0=Celcius, 1=Fahrenheit @@ -305,7 +312,7 @@ int write_device(WEATHERSTATION serdevice, unsigned char *buffer, int size); void sleep_short(int milliseconds); void sleep_long(int seconds); -int http_request_url(char *urlline); +int http_request_url(char *urlline, char *baseurl); int citizen_weather_send(struct config_type *config, char *datastring); #endif /* _INCLUDE_RW2300_H_ */ diff -Nur open2300-1.10/win2300.c open2300-1.10/win2300.c --- open2300-1.10/win2300.c 2005-03-05 21:28:22.000000000 +1300 +++ open2300-1.10/win2300.c 2006-07-31 09:10:22.000000000 +1200 @@ -229,15 +229,16 @@ /******************************************************************** * http_request_url - Windows version * - * Inputs: urlline - URL to Weather Underground with path and data + * Inputs: urlline - URL to Weather site with path and data * as a pointer to char array (string) + * baseurl - hostname of site to send data to * * Returns: 0 on success and -1 if fail. * - * Action: Send a http request to Weather Underground + * Action: Send a http request to a weather site * ********************************************************************/ -int http_request_url(char *urlline) +int http_request_url(char *urlline, char *baseurl) { WORD wVersionRequested; WSADATA wsaData; @@ -267,7 +268,7 @@ return(-1); } - if ( (hostinfo = gethostbyname(WEATHER_UNDERGROUND_BASEURL)) == NULL ) + if ( (hostinfo = gethostbyname(baseurl)) == NULL ) { perror("Host not known by DNS server or DNS server not working"); return(-1); diff -Nur open2300-1.10/wu2300.c open2300-1.10/wu2300.c --- open2300-1.10/wu2300.c 2005-03-05 21:28:35.000000000 +1300 +++ open2300-1.10/wu2300.c 2006-07-31 09:12:03.000000000 +1200 @@ -106,7 +106,7 @@ } else { - http_request_url(urlline); + http_request_url(urlline, WEATHER_UNDERGROUND_BASEURL); } return(0);