Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl # # master_timer # # Perl control script for X10 Firecracker module # Useful for simple crontab timer applications. Options are overly wor +dy # to make for easy crontab reading later on. # # Requires the ControlX10::CM17 module and Device::SerialPort module f +rom # CPAN. Not portable to Windows platforms; other portability unknown. # # 18-Mar-2001 by James Mancini - released into public domain use vars qw( $module $secure $action); use Device::SerialPort; use ControlX10::CM17 qw( send_cm17 0.05 ); use Getopt::Long; use strict; my %opt; $opt{fullcmd} = "$0 ".(join " ", map {$_ =~ /[ \[\]\*\{\}\;\>\<\&]/ ? +"'$_'" : $_ } @ARGV); options(\%opt); my $port = $opt{port} || "/dev/ttyS0"; my $serial_port = Device::SerialPort->new ($port,1); die "Darn! I Can't open serial port $port: $^E\n" unless ($serial_port +); # These are for the pass-through port on the Firecracker $serial_port->databits(8); $serial_port->baudrate(4800); $serial_port->parity("none"); $serial_port->stopbits(1); $serial_port->dtr_active(1); $serial_port->handshake("none"); $serial_port->write_settings || die "Failed to set serial params.\n"; if ($opt{secure}) { my $sleeptime = int(rand (31) * 60); print "\nSleeping $sleeptime seconds..\n" if $opt{verbose}; sleep $sleeptime; } my $action = ""; if ($opt{action} =~ /^off$/) { $action = "K" } elsif ($opt{action} =~ /^dim([+-][\d]+)$/) #dim can be + or - { $action = "${1}" } elsif ($opt{action} =~ /^bright([+-][\d]+)$/) #really the same as d +im { $action = "${1}" } elsif ($opt{action} =~ /^dim$/) { $action = "-14" } elsif ($opt{action} =~ /^bright$/) { $action = "+14" } elsif ($opt{action} =~ /^allon$/) # All lights on { $action = "O"; $opt{module}=""; } elsif ($opt{action} =~ /^alloff$/) # All lights off { $action = "N"; $opt{module}=""; } elsif ($opt{action} =~ /^masteroff$/) # All modules off { $action = "P"; $opt{module}=""; } else # Default action = turn module on { $action = "J" } $opt{module} =~ s/^[^0-9a-g]$//i; $opt{hcode} =~ s/^[^a-zA-Z]$|^[\w].+//; $opt{hcode} = "A" unless $opt{hcode}; $opt{hcode} =~ tr/a-z/A-Z/; my $cmd = "$opt{hcode}$opt{module}${action}"; print "\nSending $cmd...\n" if $opt{verbose}; send_cm17($serial_port, $cmd); $serial_port->close || die "\nclose problem with $port\n"; undef $serial_port; sub options () { my $opt = shift; GetOptions( $opt, 'action=s', 'hcode=s', 'module=s', 'secure', 'verbose', 'port=s', ); unless ($opt{module}) #print usage { print <<ECHO; Usage: master_timer [options] --module=[1-9a-g] *REQUIRED* Specify which module to send the command to. 16 modules are allowed per house code, numbered 1-9 then a-g (i.e, 10 = a, 16 = g). --action=opt {optional} 'opt' must be one of the following: [on|off|dim{-1-100}|bright{+1-100}|alloff|allon|masteroff] 'allon' and 'alloff' refer to all LIGHT MODULES, 'masteroff' turns off ALL MODULES. Default action is ON. --hcode=[a-z] set housecode for command. Defaults to housecode "A". --secure {optional} Add a random delay between 0 and 30 minutes before executing command. Useful for timer applications. Set the command to run at the EARLIEST time you want it to happen. --port=device 'device' should be the full path to the port, e.g. "/dev/ttyS1". Optional. If not specified, defaults to /dev/ttyS0 (COM1). --verbose {optional} Print status messages. ECHO exit (1); } }

In reply to X10 Timer script... by Clownburner

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: i have a different opinion: automation is always worth: first i can use Perl (and this is good), then later you can reuse parts to automate others tasks. My $boss everytime say:'how much time you spend doing this?' So generally i present a perl solution
    [Corion]: Discipulus: Yes, but the chart gives some limits on whether it's really worth spending time for saving your time. If you gain enjoyment, automating is still great, but it doesn't save time ;)
    [Discipulus]: Corion are you would able to realize such thing? O_O
    [Corion]: In the same vein I have a script that automates Firefox to enter some data into another system. It's not faster than the people using the script if they were to do it manually, but they prefer not having to check the data and not having typos when ...
    [Corion]: ... entering the data
    [Corion]: Discipulus: I don't know whether I could really do that, but the init process itself mostly launches other processes, and the whole startup is just following a path of dependencies and making sure they are all running. Which basically is what ...
    [Discipulus]: when at work my time is (temporarly) owned by the firm, so i do not care (coworkers whatch movies.. I code Perl)
    [Corion]: ... make already does, except for files instead of programs. But maybe with some /proc hackery, that could be eliminated and one could use plain make :-D
    [choroba]: systemd just makes is asynchronous
    [choroba]: so, make -j

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2017-07-27 09:28 GMT
    Find Nodes?
      Voting Booth?
      I came, I saw, I ...

      Results (408 votes). Check out past polls.