Page 2 of 3
Re: Plugin for Newbies
Posted: Sat May 21, 2011 7:25 pm
by pinto
Not:($2 - $5) * 100.0)
But:
(($2 - $5) * 100.0)
tested, and working

A little typo I guess when you changed your script to use wget
Jozef
Re: Plugin for Newbies
Posted: Sat May 21, 2011 7:53 pm
by wfpost
yes, I had removed lround, because I guessed it is not needed, but added it again, otherwise I´ll get weird values like 1.79 instead of 1.8. Strange.
Code: Select all
#! /bin/sh
#
while :
do
# pull data filter the needed string
wget -O /dev/stdout "http://127.0.0.1/meteograph.cgi?text=all" | grep -E "actual_thb0_press_hpa|seqhour1_thb0_press_hpa" | gawk 'BEGIN {FS="_"} {print $4,$6}' | tr -s '\n' ' ' | gawk 'BEGIN {FS=" "} {printf "data9 %d\n", lround (($2 - $5) * 100.0) }'
# make sure output gets flushed
sync
# wait 900 seconds for next read
sleep 900
done
Re: Plugin for Newbies
Posted: Sat May 21, 2011 10:55 pm
by Hathor27
wfpost wrote:boris sample is working with my meteohub.
the sleep value can´t be the culprit, I guess
30s is not a reasonable polling value anyway, because the website updates the temps every 20-30 minutes
What error do you get?
I've got no idea what's wrong in my configuration...
I set up three samples: yours (I hope you don't mind), Boris' and one of me like
Code: Select all
#! /bin/sh
#
while :
do
# pull data from website and filter the needed string
wget -O /dev/stdout "http://www.meteoschweiz.admin.ch/web/de/wetter/aktuelles_wetter.par0005.sub0025.html" 2>/dev/null | grep "___BEZ" | gawk 'BEGIN {FS=">"} {print $3}' | gawk 'BEGIN {FS="&"} {printf "thb9 0 0 0 0 0 %d\n", lround ($1 * 10.0)}'
# make sure output gets flushed
sync
sleep 120
done
I set them all for execution as
Code: Select all
meteohub:/home/meteohub# dir -l plugin*.sh
-rwxr-xr-x 1 root root 412 May 21 22:14 plugin_data19_press_delta3h.sh
-rwxr-xr-x 1 root root 392 May 8 22:25 plugin_t9_sylt_ost.sh
-rwxr-xr-x 1 root root 674 May 21 22:10 plugin_thb9_BEZ.sh
meteohub:/home/meteohub#
On Meteohub GUI I only see
and meteohub-log says
Code: Select all
logger (21.05.2011 22:50:31): unexpected 0 bytes delivered from weather station 2 (Plug-in)
logger (21.05.2011 22:50:31): disconnect station 2 (Plug-in).
logger (21.05.2011 22:50:31): unexpected 0 bytes delivered from weather station 3 (Plug-in)
logger (21.05.2011 22:50:31): disconnect station 3 (Plug-in).
logger (21.05.2011 22:50:31): unexpected 0 bytes delivered from weather station 4 (Plug-in)
logger (21.05.2011 22:50:31): disconnect station 4 (Plug-in).
Any idea?...
Re: Plugin for Newbies
Posted: Sat May 21, 2011 11:06 pm
by Hathor27
DUMMY ME
I should have inserted the whole path to my plugin name into definition of weatherstation. For the plugin I only wrote
instead of
Code: Select all
/home/meteohub/plugin_t9_sylt_ost.sh
Thanks for conversation - now it seems to work

Re: Plugin for Newbies
Posted: Sat May 21, 2011 11:28 pm
by Hathor27
Again, one more problem occurs with my own plugin:
Code: Select all
#! /bin/sh
#
while :
do
# pull data from website and filter the needed string
wget -O /dev/stdout "http://www.meteoschweiz.admin.ch/web/de/wetter/aktuelles_wetter.par0005.sub0025.html" 2>/dev/null | grep "___BEZ" | gawk 'BEGIN {FS=">"} {print $3}' | gawk 'BEGIN {FS="&"} {printf "thb9 0 0 0 %d 0 %d\n", lround ($1*10.0), lround ($1*10.0)}'
# make sure output gets flushed
sync
sleep 120
done
and meteohub-log says
Code: Select all
logger (21.05.2011 23:21:38): Bad thb9 sensor data, "pressure x10" (0) out of range [5000:12000]
If I run the wget-statement at ssh, it says
Code: Select all
meteohub:/home/meteohub# wget -O /dev/stdout "http://www.meteoschweiz.admin.ch/web/de/wetter/aktuelles_wetter.par0005.sub0025.html" 2>/dev/null | grep "___BEZ" | gawk 'BEGIN {FS=">"} {print $3}' | gawk 'BEGIN {FS="&"} {printf "thb9 0 0 0 %d 0 %d\n", lround ($1*10.0), lround ($1*10.0)}'
thb9 0 0 0 10187 0 10187
Any idea?...
Re: Plugin for Newbies
Posted: Sun May 22, 2011 12:02 am
by Hathor27
funny... it seems like a self-study course to me
I got the wrong syntax for this sensor: I used 5 parameters and should have used only 3.
This here works now:
Code: Select all
#! /bin/sh
#
while :
do
# pull data from website and filter the needed string
wget -O /dev/stdout "http://www.meteoschweiz.admin.ch/web/de/wetter/aktuelles_wetter.par0005.sub0025.html" 2>/dev/null | grep "___BEZ" | gawk 'BEGIN {FS=">"} {print $3}' | gawk 'BEGIN {FS="&"} {printf "thb9 0 0 %d\n", lround ($1*10.0)}'
# make sure output gets flushed
sync
# wait 15 minutes for next read
sleep 900
done
I still have one question: Boris, you mentioned
admin wrote:yes, this is not formally documented, but when the line you transmit does start with a ":" then meteohub takes the number after that as a linux "time_t" typed date information (seconds since 1.1.1970).
Example ":1305913348 t9 123" gets interpreted as
Temp sensor #9 is reporting 12.3 °C at 2011-05-20 19:42:28 CEST.
How would you arrange the wget command, if I have to collect the timestamp and the barodata with 2 different grep/gawk commands?
Hopefully

Re: Plugin for Newbies
Posted: Sun May 22, 2011 8:24 pm
by Hathor27
It's me again - sorry to be new and noisy...
In accordance to the questions before, I'd like to write a more complicated plugin
- which reads a website once into a variable, e.g. $website
- then I want to analyze with grep and gawk and write its results to more variables
- before I merge them together into a new meteohub value, e.g. ":$time thb9 $val1 $val2 $val3"
Can anybody help with that?
If I use
Code: Select all
website=$(wget -O - http://www.mydomain.com/mysite.html)
and
everything seems to come in one line.
So the
grep command (or just me) can not locate the line of the searched string...
...what is the best way to read the website just once and analyze it then within the script?
Re: Plugin for Newbies
Posted: Sun May 22, 2011 11:20 pm
by wfpost
That does not seem to be possible with pipes.
But if you want to extract more than one value from a website that can be done in writing the data first to a file and then extract things you need step by step.
I do that with the twitter script mentioned here >>>
viewtopic.php?f=16&t=7978&p=8571&hilit=twitter#p8571
viewtopic.php?f=16&t=8428&hilit=twitter
Re: Plugin for Newbies
Posted: Sun May 22, 2011 11:35 pm
by Hathor27
ooops, that two steps in one
Could you please guide me in a simpler way?
Re: Plugin for Newbies
Posted: Sun May 22, 2011 11:59 pm
by wfpost
the example below extracts the current weather condition and range of vision from wunderground.
first I let wget save the website and then save it again with lynx as pure text.
then sed is used to extract the data needed.
At the end I have two variables
$ZUSTAND
$SICHTWEITE
which get printed into my website every 15 Minutes.
http://honsolgen.de
If you want to extract different parts from a file, you should read a guide about sed, simply google it, the web is full of very good introductions about it.
Code: Select all
wget --user-agent="" 'http://deutsch.wunderground.com/global/stations/10866.html' --output-document=wua.html
lynx -dump wua.html >wua.txt
sed -n '/ Aktueller Zustand/,$p' <wua.txt >wua1.txt
sed -n '/°C/,$p' <wua1.txt >wua.txt
sed -n '/Sichtweite/,$p' <wua1.txt >wuasicht.tmp
sed 20q wuasicht.tmp >wuasicht.txt
sed 11q wua.txt >wua.tmp
mv wua.tmp wua.txt
cp wua.txt wom.txt
rm *.tmp
ZUSTAND=$(awk 'NR==3 { print $1,$2 }' wua.txt)
SICHTWEITE=$(awk 'NR==2 { print $1 }' wuasicht.txt)
SICHTWEITE=$SICHTWEITE' km'
Re: Plugin for Newbies
Posted: Mon May 23, 2011 12:02 pm
by skyewright
admin wrote:wfpost wrote:Can I feed stdout with two variables at once in a pipe?
no, sorry.
Not a pipe based solution, but my workaround in such a situation is to create a meteohub html template that reports the data I want, then call that (e.g. wget) from the plugin or virtual sensor script.
Re: Plugin for Newbies
Posted: Mon May 23, 2011 12:47 pm
by wfpost
I see, thanks for the hint.
clientraw.txt is uploaded every minute anyway and could be used, but it hasn´t the seq* variables.
Could you give an example with the virtual sensor script?
Can I create a virtual thbx sensor reading data from a file instead of doing it via a new plug-in station?
Re: Plugin for Newbies
Posted: Mon May 23, 2011 2:33 pm
by skyewright
wfpost wrote:Can I create a virtual thbx sensor reading data from a file instead of doing it via a new plug-in station?
Certainly.
The main difference between a virtual sensor script and a plugin script is that the plugin script runs continually using a loop with a 'sleep' or some such to control how often it reports but the virtual sensor script runs afresh each time the trigger happens. There is nothing to stop you having a virtual sensor script that totally ignores the data that meteohub provides on stdout.
e.g. if I have the parameter list correct
Code: Select all
#!/usr/bin/perl -w
use strict;
print "100 50 50 9990 9990 1\n"
could provide a valid thb type sensor, with one (very boring!) reading delivered each time the trigger was activated.
For what I think you want to do, you'd put your wget and data extraction in the script and deliver a parameter list based on that.
Does that make sense?
Re: Plugin for Newbies
Posted: Sat Jun 04, 2011 12:04 am
by Hathor27
Hi skyewright,
I haven't quite finished my plugin-task, but got a question on
skyewright wrote:The main difference between a virtual sensor script and a plugin script is that the plugin script runs continually using a loop with a 'sleep' or some such to control how often it reports but the virtual sensor script runs afresh each time the trigger happens. There is nothing to stop you having a virtual sensor script that totally ignores the data that meteohub provides on stdout.
What is the trigger for a virtual sensor script, please? When does such a script start and/or stop?
Re: Plugin for Newbies
Posted: Sat Jun 04, 2011 7:12 pm
by skyewright
Hathor27 wrote:
What is the trigger for a virtual sensor script, please? When does such a script start and/or stop?
The trigger is that another (real) sensor has just delivered a reading to Meteohub.
Once started, the virtual sensor script should do its processing, provide a correctly formated reading for the virtual sensor to Meteohub, then finish.