CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

Post #1 of 3 (2349 views)
simple program to write MQTT data rrd loosing 75% of sent Can't Post

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

Post #2 of 3 (2346 views)
Re: [sash99] simple program to write MQTT data rrd loosing 75% of sent [In reply to] Can't Post

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

Post #3 of 3 (2341 views)
Re: [Laurent_R] simple program to write MQTT data rrd loosing 75% of sent [In reply to] Can't Post

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");


}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives