rkrasowski has asked for the wisdom of the Perl Monks concerning the following question:

Hi all and Happy New Year. I am working on data recorder. I created telemetryBox (on parallax propeller). It collects 13 parameters from different sensors. It sends it via xBee. I wrote Perl script to collect data from USB. Also I wrote using Tk nice display which schows data in label form. But connecting these two seems to be a problem for me. The way I have done it is not nice - data from telemetryBox via my Perl program is written into data.txt file. From that file my Tk display program gets the data and shows it. Is there any other, cleaner way to do it?? Also want to change background color in label showing values. Let say voltage above 5V - green background, 4-5V yellow, <4 red. So dynamic change of the color of label would be nice. Thanks like always Robert

Replies are listed 'Best First'.
Re: Data display in Tk
by GrandFather (Saint) on Jan 02, 2012 at 02:10 UTC

    I'd set up a update callback using $mw->repeat($interval, \&update); to poll the receiver at some appropriate interval. If you set $interval to be slightly less than the expected update interval from the telemetry system the updates will synchronise to the sent rate data.

    If you read the Tk documentation you will work out how to change the background colour of widgets.

    True laziness is hard work
Re: Data display in Tk
by zentara (Cardinal) on Jan 02, 2012 at 11:22 UTC
Re: Data display in Tk
by cavac (Prior) on Jan 02, 2012 at 13:22 UTC

    I see multiple ways to do this. If you don't care that you miss an update or two and just want to display the current state, you could use something like Cache::Memcached to always hold to current value in memcached. Then, your Tk could just poll whenever it feels like it wants to update.

    Or, use a simple database (a minimal postgresql setup with a table or two will do nicely). This way, you don't have to solve the syncronisation problem but you also can keep as much historical records as you like. This also gives you a simple way to implement a sensors "replay" for debugging or to search through big datasets with minimum extra coding.

    BREW /very/strong/coffee HTTP/1.1
    Host: goodmorning.example.com
    
    418 I'm a teapot