Home: Perl Programming Help: Beginner:
simple program to write MQTT data rrd loosing 75% of sent



sash99
New User

Sep 12, 2016, 8:32 PM


Views: 3090
simple program to write MQTT data rrd loosing 75% of sent

hi there.
I am very green a perl. but i can not figure out why or how to correct my issue: i looked for perl script on the internet but there none that would help so i hacked away at one until I got it to "work"

#!/usr/bin/perl -w


open(SUB, "/usr/bin/mosquitto_sub -t /wind |");


while ($wind = <SUB>) {
if ($wine =~ 0) {

print "$wind ";

system("rrdtool update wind.rrd N:$wind");

}
}


it works some what but it not capturing over 1/2 of the packets sent. the packets come every 2 - 7 seconds. some time it capturers every packet for 5 packets sent then it might miss 9 out of 10 packets of the next ones sent . the packets are small . basically numbers less then 6gigits in length . probably something simple i just do not know what it might be.

thank you for your time
sash :)


Laurent_R
Veteran / Moderator

Sep 13, 2016, 1:20 AM


Views: 3087
Re: [sash99] simple program to write MQTT data rrd loosing 75% of sent

Two errors on this line:

Code
if ($wine =~ 0) {

First, your variable containing the input line is $wind, not $wine. But I guess that's just a typo.

Then, the "=~ 0" is most probably wrong, because the "=~" should really be used with a regular expression, not with a single digit. Perhaps you simply need "=~ /0/) {", or perhaps you need something else, I don't know because you don't explain what you want to achieve with this code line.

So please tell us what is the purpose of this conditional.


sash99
New User

Sep 13, 2016, 5:43 AM


Views: 3082
Re: [Laurent_R] simple program to write MQTT data rrd loosing 75% of sent

thank you Laurent_R

that was just enough i removed that line and it seams to work it prints all the Mqtt packets - now and sends to rrdtools :)


#!/usr/bin/perl -w


open(SUB, "/usr/bin/mosquitto_sub -t /wind |");


while ($wind = <SUB>) {


print "$wind ";

system("rrdtool update wind.rrd N:$wind");


}