Page 1 of 1

Virtual Sensors from bash-file

Posted: Wed Aug 31, 2011 10:12 pm
by Hathor27
Hi there,

can anybody help me designing a more complex virtual sensor with a bash-file?
The fare-away goal should be to get a 3h-trend from a sensor like thb0 into thb9, from temperature, humidity and barometric pressure.

I tried the following to get a 3h-trend value (first just) from the barometric pressure:

Code: Select all

#! /bin/sh
#
# runs at /home/meteohub/vsensor_delta3h.sh
wget -q -O /dev/stdout "http://meteo.horn.dom/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 "%.1f\n", lround ($2 - $5) }'
#
Then I set a new virtual sensor as:
NeueID Name Trigg Umrechnung
Data11 Trend thb0 /home/meteohub/vsensor_delta3h.sh

After saving this virtual sensor the data collecting process restarts. Then meteohub.log says:

Code: Select all

processing "/home/meteohub/vsensor_thb0_delta3h.sh" does not return a value string, reason is: 
error while doing write on socket 5558: Broken pipe
What do I have to change for it returns only the desired value?

Thx in advance

Re: Virtual Sensors from bash-file

Posted: Sat Sep 17, 2011 11:12 pm
by Hathor27
...is anybody out there beeing able to give me an advice?... :?

Re: Virtual Sensors from bash-file

Posted: Sun Sep 18, 2011 1:06 am
by wfpost
Starting your command manually from the shell it stays empty, but works with my meteohub with my internal IP-adress and comes up with a valid value

Therefore >>
replace dnydns name with your internal IP
wget -q -O /dev/stdout "http://meteohub-IP/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 "%.1f\n", lround ($2 - $5) }'

Re: Virtual Sensors from bash-file

Posted: Sun Sep 18, 2011 1:07 pm
by Hathor27
wfpost wrote:Therefore >>
replace dnydns name with your internal IP
Thanks for your intention, wfpost. I run my own name-server internally, and meteo is the name of meteohub in my horn.dom name-space.
If I type the wget-command manually at the console, it works fine with name as far as with ip: It returns a single value like 2.3
Even if I run the command within the bash file it works fine at command line.

Only If I setup the virtual-sensor within meteohub, it won't work - any idea what I'm doing wrong?... :?
I suppose there is something with the return value meteohub expects... what is the difference if meteohub runs a single command (like wget) or a bash file for a virtual sensor?

Re: Virtual Sensors from bash-file

Posted: Tue Oct 18, 2011 7:19 pm
by skyewright
Hathor27 wrote:If I type the wget-command manually at the console, it works fine with name as far as with ip: It returns a single value like 2.3
Even if I run the command within the bash file it works fine at command line.
I'm not up on bash or gawk.
What exactly is the sort of value that your bash file outputs to stdout?
Hathor27 wrote:I suppose there is something with the return value meteohub expects... what is the difference if meteohub runs a single command (like wget) or a bash file for a virtual sensor?
With a virtual sensor Meteohub is looking for output on stdout, and expects that output to be in the correct format for the relevant virtual sensor.

For example in perl, my output line for a DATA sensor might look like:

print "$virtualData\n";

Whatever is output, I'd not expect it to include a decimal point. The values are typically scaled up, e.g. a DATA value that is 1.25 would be presented as 100 times that, i.e. 125, and a T value that was 10.3°C would be presented as 10 times that, i.e. 103.

Does that help?

Re: Virtual Sensors from bash-file

Posted: Sun Oct 23, 2011 9:06 pm
by Hathor27
Thank you skyewright - you're absolutely right: It needs to be a numeric value without a decimal point.

But there is another thing: I defined a well working virtual sensor directly in the meteohub GUI as

Code: Select all

awk '{printf "%d %d %d %d %d %d %d %d", $3, $4, $5, $6, $7, $8 , $9, $10}'
That writes me the values of thb0 into thb2 (stupid!)

If I set up a bash file like

Code: Select all

#!/bin/sh
#
# runs as /home/meteohub/vsensor_thb2.sh
#
awk '{printf "%d %d %d %d %d %d %d %d", $3, $4, $5, $6, $7, $8 , $9, $10}'
and configure that within the meteohub GUI instead of the above, meteohub.log says:

Code: Select all

"/home/meteohub/vsensor_thb2.sh" does not return a value string, reason is: sh: /home/meteohub/vsensor_thb2.sh: /bin/sh^M: bad interpreter: No such file or directory
What am I doing wrong?! Why bad interpreter?

Re: Virtual Sensors from bash-file

Posted: Sun Oct 23, 2011 9:16 pm
by Hathor27
Hathor27 wrote:

Code: Select all

/bin/sh^M: bad interpreter
OK - found :oops:

a DOS/Windows-Error: CRLF instead of LF

Re: Virtual Sensors from bash-file

Posted: Sun Oct 23, 2011 9:44 pm
by Hathor27
Now back to my previous issue: I want to build a more complex virtual sensor, calculating a 3h trend of thb0.

First I only want to set up the 3h trend of the barometric pressure (temperature and humidity follows later):

Code: Select all

#! /bin/sh
#
# runs as /home/meteohub/vsensor_thb0_delta3h.sh
#
wget -q -O /dev/stdout "http://meteohub-ip/meteograph.cgi?text=all" | grep -E "seqmin15_thb0_press_hpa" | gawk 'BEGIN {FS="_"} {print $4,$15}' | gawk 'BEGIN {FS=" "} {printf "0 0 0 %d 0 0\n", lround (($2 - $3) *100.0) }'
Running that script at the command line, it returns a proper string like

Code: Select all

0 0 0 -10 0 0
Setting up the same script as virtual sensor, meteohub.log says:

Code: Select all

logger (23.10.2011 21:30:18): processing "/home/meteohub/vsensor_thb0_delta3h.sh" does not return a value string, reason is: 
logger (23.10.2011 21:30:18): error while doing write on socket 5558: Broken pipe
Has anybody any idea on that?

May a barometric pressure value of thb be negative? Even if not, I did the same into data34 (with only one value), and the same message accours in meteohub.log - what does it mean and how can I get thru?

Re: Virtual Sensors from bash-file

Posted: Tue Nov 01, 2011 10:19 pm
by Hathor27
...not any crack willing to help? :wink:

I think there's something wrong handling the trigger value, but I'm to little into this mechanism - can anybody assist, please?

Re: Virtual Sensors from bash-file

Posted: Wed Nov 02, 2011 1:32 am
by admin
try listening directly at port 5558 by "netcat localhost 5558" instead of the wget thing.

Re: Virtual Sensors from bash-file

Posted: Sun Nov 06, 2011 9:47 pm
by Hathor27
admin wrote:try listening directly at port 5558 by "netcat localhost 5558" instead of the wget thing.
Thank you so far. I tried it - it's much faster - but the error message is still the same...
...any more suggestions?

Re: Virtual Sensors from bash-file

Posted: Sun Nov 06, 2011 11:13 pm
by admin
it allows only one rquesting process at a time. When mutliple script invocations do read, it will fail.

Re: Virtual Sensors from bash-file

Posted: Sun Nov 06, 2011 11:21 pm
by Hathor27
admin wrote:it allows only one rquesting process at a time. When mutliple script invocations do read, it will fail.
How could I (would you) setup a virtual sensor with a script file then, please?
Is there another way to get this functionality?

Re: Virtual Sensors from bash-file

Posted: Sun Nov 06, 2011 11:32 pm
by admin
use two kinds of script. one that grabs data from the port and temporary saves this in a file, the other virtual sensor definitions use a variant that reads data from that file.

Re: Virtual Sensors from bash-file

Posted: Sun Nov 06, 2011 11:40 pm
by Hathor27
admin wrote:use two kinds of script. one that grabs data from the port and temporary saves this in a file, the other virtual sensor definitions use a variant that reads data from that file.
The second script I understand to start as virtual sensor - that's ok.
But where/how would you suggest to start the first script (comfortable way)?