daily pastebin goal
48%
SHARE
TWEET

cheerlights.pl

a guest Dec 18th, 2012 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w
  2. use Device::SerialPort;
  3. use LWP::Simple;
  4.  
  5. my $portvalue = '/dev/tty.usbmodem12341';
  6. my $port = Device::SerialPort->new("$portvalue");
  7. my $url = 'http://api.thingspeak.com/channels/1417/field/1/last.txt';
  8. my $content;
  9. my $oldcontent = '';
  10.  
  11. $port->databits(8);
  12. $port->baudrate(9600);
  13. $port->parity("none");
  14. $port->stopbits(1);
  15. $|++;
  16.  
  17. sleep(3);
  18. print "Serial port ready...\n";
  19.  
  20. while (1) {
  21.     $content = '';
  22.     $content = get($url);
  23.     if (!defined($content) || $content eq '') {
  24.         sleep(60);
  25.         next;
  26.     }
  27.  
  28.     $content =~ s/\s//gsi;
  29.     if( $content ne $oldcontent )
  30.     {
  31.         print "Cheerlights are now: $content\n";
  32.         $port->write($content);
  33.         $oldcontent = $content;
  34.     }
  35.     sleep(30);
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top