Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Does Perl ring a bell?

by kwaping (Priest)
on Sep 09, 2005 at 17:37 UTC ( #490668=perlquestion: print w/replies, xml ) Need Help??

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

My boss always comes up with crazy ideas. His latest is that he wants to ring a bell, buzzer, or some sort of alarm inside the office whenever someone clicks on a certain link on our website (a la Amazon's early days).

I know this is a long shot, but does anyone have any experience with this via Perl? Any tips or pointers are appreciated! I'm so lost with this one, I can't even come up with any good search terms to try.

Update: Just a little point of clarification, the server is co-located a few states away so this would have to be done via a network connection.

Replies are listed 'Best First'.
Re: Does Perl ring a bell?
by InfiniteLoop (Hermit) on Sep 09, 2005 at 17:49 UTC
    You could control any such equipments via an X10 module. See the following links: Update:
    fizbin, we had the same thing (red and green lava lamp) to indicate a borken build, in my earlier project. Im planning to implement the same for my current project.

      As a followup, here are the physical pieces you'll need on your end:

      • A machine that can be always on (or nearly so), can host a small webserver, and can accept a connection from the webserver whenever that link is hit, and has a spare serial port.
      • The FireCracker 4-Piece starter kit (Actually, all you really need from that is the computer interface and tranceiver)
      • An X10 chime module, such as this one. (I've found other places selling them for about 5 bucks cheaper, if you really want to hunt around)

      Then, check out ControlX10::CM17 for a perl module that will let you send an "on" signal with a small bit of perl code. Then, write a CGI script on the local machine that sends an on signal to the chime module. As you'll almost certainly have problems if more than one instance is trying to ring the bell at a time, check out merlyn's column on how to have only one instance of a CGI running at a time.

      Once you can ring the bell from inside the office by visiting that CGI locally, make your webserver fire off a connection to that cgi script whenever someone follows that particular link.

      Update: It just occurred to me that there's a nice bonus to blowing $100 on this idea of your boss's: with just a little bit more invested for two lava lamps, you have all the physical resources you need for those snazzy red and green build status lava lamps.

      --
      @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
Re: Does Perl ring a bell?
by samizdat (Vicar) on Sep 09, 2005 at 21:03 UTC
    See Das Blinkenlights

    You can use the serial TX bit to drive an optoisolator, which then triggers a separately powered buzzer or bell:
    serial TX bit 12vDC power supply __________ ^ \ | | \__ | @ | @ buzzer coil or relay | @ | -- | / | | | / opto LED V /\/\light/\/\/\ | opto photodiode --- \ | v / | sio gnd --- | | --- = gnd
    Depending on the rating of your optoisolator, you might want to put a zener voltage-limiter in parallel with it. Most any opto should work. Just send bits out the serial port to trigger it. Your remote webserver can send a signal to your office machine through a socket to a daemon, which then talks to the port. Different char strings will cause the coil to energize by different amounts. :D Alternately, you can trigger one of the SIO control bits (as I did in the original article) for better control. Sys:PortIO should be helpful.

    UPDATE: I should have separated the grounds to be truly safe: Ground from the TX pin should go to the gound of the SIO connector (DB-9 or DB-25), and ground of the power driver side should go to the ground of the DC side of the power supply. Sorry about that!
Re: Does Perl ring a bell?
by InfiniteSilence (Curate) on Sep 09, 2005 at 17:51 UTC
    CPAN has a MIDI module that you can use to make sound on your computer's sound card. As far as figuring out when a user clicks on a link on a website, you can just update/increment some database field for that and run the MIDI.

    Celebrate Intellectual Diversity

Re: Does Perl ring a bell?
by NetWallah (Canon) on Sep 09, 2005 at 20:12 UTC
    As an old-time networker, this sounds like a classic usage for an SNMP Trap.

    Your web page (perl code) will need to generate the trap (A simple UDP packet), and send it to a pre-configured Trap receiver (Possibly in a different state or planet).

    The trap receiver (There are many standard ones, and is is simple to write a UDP receiver for this special case) will take action (such as playing an audio file) when a trap is received.

    Typical usage for SNMP traps is network device related alarm conditions.

    Perl modules beginning with "Net::SNMP" are your friends.

         "Man cannot live by bread alone...
             He'd better have some goat cheese and wine to go with it!"

Re: Does Perl ring a bell?
by jZed (Prior) on Sep 09, 2005 at 17:55 UTC
    How about Alert::ElectroSchock. With that module you can deliver the alerts directly to your boss's nervous system, which is where they belong :-).
      That should be: Acme::ElectroShock... ;)
Re: Does Perl ring a bell?
by dws (Chancellor) on Sep 09, 2005 at 20:14 UTC

    His latest is that he wants to ring a bell, buzzer, or some sort of alarm inside the office whenever someone clicks on a certain link on our website (a la Amazon's early days).

    This is closely related to the "turn on the red lava lamp when the build breaks" problem, which, as people note above, is well-solved using some off-the-shelf X10 components plus some X10 modules from CPAN. Wire the remote site to tickle a local server (via HTTP or whatever), and have the local server do the X10 control. The X10 folks even sell a semi-obnoxious doorbell module.

    One piece of advice: With any sort of "ring the bell" mechanism in operation, a handy pair of tools to have nearby are a ski mask and a pair of wire cutters.

Re: Does Perl ring a bell?
by gri6507 (Deacon) on Sep 09, 2005 at 17:47 UTC
    I guess I am not sure what you mean by "ringing a bell". If you mean printing 0x7 to the console to beep the PC speaker, then that's easy: printf("%c",7). If you mean something more, hum, complex, then I guess you need to specify what type of a "bell" you are talking about. One idea would be to have the perl script control something via the serial port. You could even build your own basic "speaker with a switch" for less than a dollar worth of components. Hope this helps.
      I was intentionally ambiguous because I'm open to a wide range of possible solutions. :) Thank you for your suggestions!
Re: Does Perl ring a bell?
by salva (Canon) on Sep 09, 2005 at 17:52 UTC
    you can use system to invoque an external music player to play the bell (or whatever) sound. For instance on my Linux box, I can run ...
    system "gst-launch-ext PolkaParty.mp3";
Re: Does Perl ring a bell?
by sgifford (Prior) on Sep 09, 2005 at 17:56 UTC

    If you want to beep the PC speaker, you can send an ASCII 0x7 or the string "\cG" to the console. The tricky part is getting the console opened; the Web server won't have permission to do that by default, and giving it permission is a security risk.

    If you want to use a sound card in the machine, use one of the Sound modules on CPAN.

    For either of these, I would recommend writing a small server to control the sound, and have it accept simple requests to make a noise. That way you avoid the security problems of giving the Web server access to anything, and you can change out the backend without changing any code.

    You could also consider sending out a special network packet, and having users run a client on their PC that would make the beeping sound, or running a client on a central server that's closer to people's desks.

Re: Does Perl ring a bell?
by ikegami (Patriarch) on Sep 09, 2005 at 18:05 UTC

    Concerning your update, the script on the web server could use LWP to POST a request to a local web server to ring the bell.

    Or you could have an image on the page loaded by the link. The image would actually be a CGI script on a local server that returns a small transparent image after ringing the bell.

      Or you use SMTP and send an email to an account that will do it on the office. This has the advantage of being assinchronous (avoiding locking the real server), and making sure it is delivered (even with some delay).
      daniel
Re: Does Perl ring a bell?
by bradcathey (Prior) on Sep 09, 2005 at 17:55 UTC

    Check my home node. That's the only way I know how to do it.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Does Perl ring a bell?
by schweini (Friar) on Sep 09, 2005 at 22:36 UTC
    I did something similar once, and it was surprisingly easy, even if i guess it wasn't the most elegant solution around:
    i simply soldered a relais to some pins on my parallel port (tons of guides online for soing stuff like that), since you can control quite a couple of those pins by sending bitmasks to the port. then i stole some C code for doing tha appropiate syscall (ioctl, IIRC) from some website, and made a perl CGI script call that C program when it got hit. On the remote server, i simply used LWP to call the CGI script that was on my home machine when it tried to ring that bell, and it worked great.
    You could of course use SOAP or whatever for the communication between the two locations, but plain HTTP worked just fine for me.
    you could also buy really cheap usb->parallel port adaptors so that you don't fry your 'real' port if you mess up - but i wouldn't know how to address USB ports with C...
Re: Does Perl ring a bell?
by jcoxen (Deacon) on Sep 09, 2005 at 18:14 UTC
    If you're using Windows boxen in your office, you could use Filesys::SmbClientParser to send a WinPopup message.

    Jack

Re: Does Perl ring a bell?
by zentara (Archbishop) on Sep 10, 2005 at 10:19 UTC
    Have you pointed out to your boss what will happen if someone attacks the link with a script?

    I'm not really a human, but I play one on earth. flash japh
      In this case I'd connect to some kind of MP3 jukebox instead of a bare alarm.

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Don't fool yourself.
      Well... you'll certainly know about it.
Re: Does Perl ring a bell?
by Anonymous Monk on Sep 10, 2005 at 04:49 UTC
    try MisterHouse "Written in Perl, it fires events based on time, web, socket, voice, and serial data" http://misterhouse.sourceforge.net/
Re: Does Perl ring a bell?
by spiritway (Vicar) on Sep 10, 2005 at 02:36 UTC

    Sounds like your boss is a ding-a-ling...

Re: Does Perl ring a bell?
by rkosai (Beadle) on Sep 10, 2005 at 18:46 UTC
    I did a project in high school where I used the parallel port to control remote control cars. It worked really well; I could record a pathway down the hall, and replay it almost perfectly. You can't access the parallel port without an external library under NT/XP, but you should be able to under (U|Li)nux.

    You can actually set individual pins to be on (+5) or off(0), and the response is really quite fast. You can also check pins that detect when two of them are briged, so you get sort of a "switch" mechanism.

    Hope this helps.

Re: Does Perl ring a bell?
by mattr (Curate) on Sep 12, 2005 at 08:44 UTC
    After a while your office may start getting on your case, and you will be torn between shutting down the project (making you a failure), turning down the sound (which makes it less useful, unless you have a spare corner nobody usually goes to), and turning up the sound (to show off your great jungle sounds (like Peep) or whatever you are using. Sound clutters up a space. So you might like to have some other tricks up your sleeve, for example Xerox PARC and also the MIT Media Lab has thought of some interesting things. For example here is dangling string. You could have propellors, christmas lights, or other things more suble than a beep for every hit. And also, you will want to consider what happens if you get clobbered by a lot of people. Maybe you have a soft click for each hit, which will not be so annoying even if you get posted to slashdot, but you also produce a full tone at a pitch suitable to express a certain magnitude of accesses per minute. Also consider how much load and blocking this is going to put on the systems and the network.
Re: Does Perl ring a bell? (shame)
by tye (Sage) on Sep 11, 2005 at 03:43 UTC

    I can't believe that no one mentioned the "bell" that Perl has built-in, "\a". Why, a simple POD search gives:

    $ grep -wi bell *.pod perlop.pod: \a alarm (bell) (BEL) perlre.pod: \a alarm (bell) (BEL)

    I'm revoking all of y'all's Perl certifications. This is just embarrassing. :)

    - tye        

      I once was sniffing through this man page:

      http://www.themanualpage.org/man/man4/console_codes.4.php

      and noted that on the Linux console you could control the pitch and duration of the console bell by echoing escape codes:

      ESC [ 10 ; n ] Set bell frequency in Hz. ESC [ 11 ; n ] Set bell duration in msec.

      ...you can test this with:

      FREQ=440 DUR=500 echo -e "\e[10;$FREQ]\e[11;$DUR]" >/dev/console echo -e "\a" >/dev/console</p>

      I then found pages like these:

      which gave the frequencies of the different notes (because I don't know much technical stuff about music) and figured out that I could play music on the console...

      I got the sheet music for our national anthem, and wrote a C program which would set the frequency and the duration, send a ^G and then usleep for the appropriate number of microseconds before playing the next note. (if you don't sleep you just get a mess of quick beeps because it sends the next one immediately - it doesn't wait for the playing beep to finish)

      (I did need to get a musically aware friend to tell me which notes I should play sharp or flat - as some needed tweaking for it to be right)

      I found this was a lot more attention getting and pleasant to listen to than using a normal beep as a signal when something was happening on my box (don't forget to reset it back to the normal pitch and duration after playing the tune though, otherwise your adjusted beeps could annoy you when you're using the console beep as a normal console beep!)

      For a while I even left my old laptop running 24x7 in my bedroom and had a cron job to launch the binary at /dev/console (so it played through the PC speaker) in the morning as my alarm clock! - it worked nicely until the clock on the ancient laptop started to go silly ;o)

Re: Does Perl ring a bell?
by Anonymous Monk on Sep 12, 2005 at 01:13 UTC
Re: Does Perl ring a bell?
by Anonymous Monk on Sep 12, 2005 at 02:56 UTC
    tail -f access.log | grep "whatever" | beep -f 440 -l 10 -s
Re: Does Perl ring a bell?
by TomDLux (Vicar) on Sep 13, 2005 at 13:30 UTC

    Most cell companies have a system for sending SMS via email. Send the boss an SMS consisting of the word: 'CLICK!', and his phone will beep. It'll beep in the morning. It'll beep in the evening. It'll beep all day long.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://490668]
Approved by sgifford
Front-paged by InfiniteLoop
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-05-20 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?