Commit 522a96d0 authored by Gebhardt, Albrecht's avatar Gebhardt, Albrecht

fix pressure code for higher sealevels

skip neagtive rain differences
cut off uv outliers
parent b5510430
all: frewe-client
frewe-client: frewe-client.c http_fetcher.c http_error_codes.c
gcc frewe-client.c http_fetcher.c http_error_codes.c -o frewe-client -lusb -lm -lcrypto
......@@ -165,7 +165,7 @@ usb_dev_handle *dev=NULL;
//char filebuf[256];
char *filebuf=NULL; // Will be allocated by html_fetcher
char *frewe_server_url_submit_template = "%s?serverkey=%s&action=addrecord&datetime=%%n&tempin=%%I&tempout=%%O&tempdew=%%E&tempchill=%%C&humin=%%h&humout=%%H&windgust=%%G&windspeed=%%W&winddir=%%D&pressabs=%%P&pressrel=%%L&rain=%%R&illu=%%M&uv=%%U&rainrate=%%S";
char *frewe_server_url_submit_template = "%s?serverkey=%s&action=addrecord&datetime=%%n&tempin=%%I&tempout=%%O&tempdew=%%E&tempchill=%%C&humin=%%h&humout=%%H&windgust=%%G&windspeed=%%W&winddir=%%D&winddeg=%%d&pressabs=%%P&pressrel=%%L&rain=%%R&illu=%%M&uv=%%U&rainrate=%%S";
char *frewe_server_url_lasttime_template = "%s?serverkey=%s&action=getlasttime";
char *frewe_server_url_error_template = "%s?serverkey=%s&action=submiterror&email=%s";
char *frewe_server_url_alarm_template = "%s?serverkey=%s&action=alarm";
......@@ -1521,14 +1521,14 @@ int ws_parse(uint8_t *buffer, uint8_t *buffer60, uint8_t *buffer0h, time_t curti
w.pressabs = (float)(buffer[0x07]+(buffer[0x08]<<8))/10*c.pressabs_factor+c.pressabs_offset;
if (w.pressabs < 900 || w.pressabs>1100)
if (w.pressabs < 650 || w.pressabs>1100)
{ logger(LOG_ERROR,"ws_parse","Pressure out of range: %f hPa",w.pressabs);
errcount++;
}
// Relative pressure (hPa)
if (w.pressabs > 900 && w.pressabs<1100 && w.tempout<100 && w.tempout>-100)
if (w.pressabs > 650 && w.pressabs<1100 && w.tempout<100 && w.tempout>-100)
{ float m=altitude / (18429.1 + 67.53 * w.tempout + 0.003 * altitude); // Power exponent to correction function
w.pressrel=w.pressabs * pow(10,m);
}
......@@ -1544,7 +1544,11 @@ int ws_parse(uint8_t *buffer, uint8_t *buffer60, uint8_t *buffer0h, time_t curti
lastrain = (float)(buffer60[0x0D]+(buffer60[0x0E]<<8))*0.3*c.rain_factor+c.rain_offset;
w.rainhour = w.rain - lastrain;
if (w.rainhour<0 || w.rainhour>50)
if (w.rainhour<0)
{ logger(LOG_ERROR,"ws_parse","Rainhour is negative, will set it to 0, rain=%f, lastrain=%f",w.rain,lastrain);
w.rainhour = 0;
}
if (w.rainhour>150)
{ logger(LOG_ERROR,"ws_parse","Rainhour is out of range, rain=%f, lastrain=%f",w.rain,lastrain);
w.rainhour=-1;
errcount++;
......@@ -1560,7 +1564,11 @@ int ws_parse(uint8_t *buffer, uint8_t *buffer60, uint8_t *buffer0h, time_t curti
lastrain = (float)(buffer0h[0x0D]+(buffer0h[0x0E]<<8))*0.3*c.rain_factor+c.rain_offset;
w.rainday = w.rain - lastrain;
if (w.rainday<0 || w.rainday>100)
if (w.rainday<0)
{ logger(LOG_ERROR,"ws_parse","Rainday is negative, will set it to 0, =%f, lastrain=%f",w.rain,lastrain);
w.rainday = 0;
}
if (w.rainday>200)
{ logger(LOG_ERROR,"ws_parse","Rainday is out of range rain=%f, lastrain=%f",w.rain,lastrain);
w.rainday=-1;
errcount++;
......@@ -1584,18 +1592,23 @@ int ws_parse(uint8_t *buffer, uint8_t *buffer60, uint8_t *buffer0h, time_t curti
if(strcasecmp(ws_type,"WH3080")==0 || strcasecmp(ws_type,"WH3081")==0)
{
if (!sensorlost)
{ w.uv = floor((float)buffer[19]*c.uv_factor+c.uv_offset);
{ //logger(LOG_ERROR,"main","uv read: %f",(float)buffer[19]);
w.uv = floor((float)buffer[19]*c.uv_factor+c.uv_offset);
//logger(LOG_ERROR,"main","illu read: %f",(float)(buffer[16]+(buffer[17]<<8)+(buffer[18]<<16)));
w.illu = (float)(buffer[16]+(buffer[17]<<8)+(buffer[18]<<16))*0.1*c.illu_factor+c.illu_offset;
}
else
{ w.uv=-1.0;
w.illu=-1.0;
}
// cut outliers:
if(w.uv>30) w.uv=-1;
}
else
{ w.uv=-1.0;
w.illu=-1.0;
}
// Check if values are reasonable...
......@@ -1865,28 +1878,28 @@ int ws_format(char *format, char *out, unsigned char urlencode, char *user, char
break;
case 'P': // abs. pressure hPa
if (w.pressabs<900 || w.pressabs>1100)
if (w.pressabs<650 || w.pressabs>1100)
strcatenc(out,error,urlencode);
else
sprintf(out,"%s%0.1f",out,w.pressabs);
break;
case 'p': // abs. pressure in
if (w.pressabs<900 || w.pressabs>1100)
if (w.pressabs<650 || w.pressabs>1100)
strcatenc(out,error,urlencode);
else
sprintf(out,"%s%0.2f",out,hpa2in(w.pressabs));
break;
case 'L': // rel. pressure hPa
if (w.pressrel<900 || w.pressrel>1100)
if (w.pressrel<650 || w.pressrel>1100)
strcatenc(out,error,urlencode);
else
sprintf(out,"%s%0.1f",out,w.pressrel);
break;
case 'l': // rel. pressure in
if (w.pressrel<900 || w.pressrel>1100)
if (w.pressrel<650 || w.pressrel>1100)
strcatenc(out,error,urlencode);
else
sprintf(out,"%s%0.2f",out,hpa2in(w.pressrel));
......
#######################################################################
# Freetz Weather Client (frewe-client) for FRITZ!Box Configuration File
# Alexey Ozerov (c) 2015 - ver. 1.19
# Alexey Ozerov (c) 2012 - ver. 1.17
# All settings are optional, all lines beginning with # are comments
#######################################################################
......@@ -13,7 +13,7 @@
StationType WH1080
# Weather station altitude in meters for relative pressure calculation
Altitude 50
Altitude 450
# Set RunInterval in seconds in order to run frewe-client continuously
# Less then 48 seconds is not reasonable as the last reading updated every 48 secs
......@@ -25,19 +25,19 @@ RunInterval 300
#######################################################################
# Full URL of frewe-server.php
#FreweServer_URL http://www.domain.com/path/to/frewe-server.php
FreweServer_URL http://192.168.1.11/users/alge/frewe-7390-1/frewe-server.php
# Server key as defined in frewe-server.php
#FreweServer_Key your_server_key
FreweServer_Key qwe234c1ercqertgrtfwdqexy
# Send weather data to frewe-server, set On to enable
#FreweServer_SendData Off
FreweServer_SendData On
# Resend missing weather data, set On to enable
#FreweServer_Resend Off
FreweServer_Resend On
# Send all kind of errors to specified email address (requires frewe-server to be configured)
#Error_Email name@domain.com
Error_Email root@algepop.net
#######################################################################
# Configuration of known weather services
......@@ -123,15 +123,6 @@ UVOffset 0.0
OutputFormat
ErrorString N/A
#######################################################################
# Output format and file for FHEM integration (ADVANCED)
# Use this command to add your weather station to FHEM
# define myWH1080 WS3600 "cat /var/media/ftp/frewe/fhem.txt" 300
#######################################################################
#FHEM_File /var/media/ftp/frewe/fhem.txt
#FHEM_OutputFormat DTime %N\nTi %I\nTo %O\nRHi %h\nRHo %H\nDIR %d\nDIRtext %D\nWS %W\nWG %G\nRtot %R\nRP %L\n
#FHEM_ErrorString
#######################################################################
# Alarms (ADVANCED)
......
#!/bin/sh
# Install/uninstall, start/stop/restart, testrun frewe-client
if [ -x /usr/bin/dirname ] && [ -x /usr/bin/readlink ]
then
if [ -L $0 ]
then
DIR=$(dirname $(readlink -f $0)) ;
else
DIR=$(dirname $0) ;
fi
else
DIR="/var/media/ftp/frewe"
fi
if [ "$DIR" == "." ]
then
DIR="`pwd`"
fi
PRONAME="frewe-client"
BINFILE="$DIR/$PRONAME"
CFGFILE="$DIR/$PRONAME.cfg"
LOGFILE="/dev/null"
# Uncomment to enable local data logging
#LOGFILE="$DIR/$PRONAME.csv"
if [ ! -f "$BINFILE" ]
then
echo "File $BINFILE not found. "
echo "Please upload this file. Aborted"
exit 1
fi
if [ ! -f "$CFGFILE" ]
then
echo "File $CFGFILE not found."
echo "Please upload this file. Aborted"
exit 1
fi
chmod 755 $BINFILE
# Print version info of currently installed frewe-client
$BINFILE -H
case "$1" in
install)
if [ -e /var/flash/debug.cfg ] && [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ]
then
echo "$PRONAME is already installed. Here is the content of debug.cfg:"
cat /var/flash/debug.cfg
echo "Nothing to install"
exit 1
fi
echo "(max=12; i=0; while [ \$i -lt \$max ]; do if [ -x "$BINFILE" ]; then $BINFILE -c $CFGFILE >> $LOGFILE & break; fi; let i=\$i+1; echo Waiting for $PRONAME... \$i; sleep 5; done) &" > /var/tmp/debug.cfg
if [ -e /var/flash/debug.cfg ]
then
cat /var/flash/debug.cfg >> /var/tmp/debug.cfg
fi
cat /var/tmp/debug.cfg > /var/flash/debug.cfg
echo "$PRONAME installed. Here is the content of the new debug.cfg:"
cat /var/flash/debug.cfg
;;
uninstall)
if [ -e /var/flash/debug.cfg ]
then
cat /var/flash/debug.cfg | grep -v $PRONAME > /var/tmp/debug.cfg
cat /var/tmp/debug.cfg > /var/flash/debug.cfg
echo "$PRONAME uninstalled. Here is the content of the new debug.cfg:"
cat /var/flash/debug.cfg
else
echo "debug.cfg not found, nothing was installed..."
fi
;;
start)
if [ "`pidof $PRONAME`" != "" ]
then
echo "$PRONAME is already running with PID `pidof $PRONAME`"
exit 1
fi
$BINFILE -c $CFGFILE >> $LOGFILE &
echo "$PRONAME started with PID `pidof $PRONAME`"
;;
stop)
if [ "`pidof $PRONAME`" == "" ]
then
echo "$PRONAME is not running. Nothing to stop"
exit 1
fi
kill `pidof $PRONAME`
echo "$PRONAME stopped"
;;
restart)
if [ "`pidof $PRONAME`" == "" ]
then
echo "$PRONAME is not running. Nothing to stop"
else
kill `pidof $PRONAME`
echo "$PRONAME stopped"
fi
if [ "`pidof $PRONAME`" != "" ]
then
echo "$PRONAME is already running with PID `pidof $PRONAME`"
exit 1
fi
$BINFILE -c $CFGFILE >> $LOGFILE &
echo "$PRONAME started with PID `pidof $PRONAME`"
;;
stat)
if [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ]
then
echo "$PRONAME is installed. Here is content of debug.cfg:"
cat /var/flash/debug.cfg
else
echo "$PRONAME is not installed"
fi
echo
if [ "`pidof $PRONAME`" != "" ]
then
echo "$PRONAME is running with PID `pidof $PRONAME`"
ps | grep "`pidof $PRONAME`"
else
echo "$PRONAME is not running"
fi
;;
testrun)
$BINFILE -v
;;
testruncfg)
$BINFILE -v -c $CFGFILE -r 0
;;
*)
echo "Usage: $0 {install|uninstall|start|stop|restart|stat|testrun|testruncfg}"
exit 1
;;
esac
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment