Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use Device::SerialPort;
- use LWP::Simple;
- my $portvalue = '/dev/tty.usbmodem12341';
- my $port = Device::SerialPort->new("$portvalue");
- my $url = 'http://api.thingspeak.com/channels/1417/field/1/last.txt';
- my $content;
- my $oldcontent = '';
- $port->databits(8);
- $port->baudrate(9600);
- $port->parity("none");
- $port->stopbits(1);
- $|++;
- sleep(3);
- print "Serial port ready...\n";
- while (1) {
- $content = '';
- $content = get($url);
- if (!defined($content) || $content eq '') {
- sleep(60);
- next;
- }
- $content =~ s/\s//gsi;
- if( $content ne $oldcontent )
- {
- print "Cheerlights are now: $content\n";
- $port->write($content);
- $oldcontent = $content;
- }
- sleep(30);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement