-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteatimer.pl
48 lines (40 loc) · 1.05 KB
/
teatimer.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
use Win32::SerialPort;
use IO::Handle;
#use Data::Dumper;
#where to send data
my $url = "http://example.com/wth.php?v=";
my $serial_port = new Win32::SerialPort('COM4');
$serial_port->handshake('none');
$serial_port->baudrate(9600);
$serial_port->parity('odd');
$serial_port->databits(7);
$serial_port->stopbits(1);
$serial_port->buffers(256, 256);
$serial_port->read_interval(0); #RI
$serial_port->read_const_time(20); #RC
open my($fd), ">>" , 'wth3.txt' || die('cant append to file');
my $data = "";
my $response = $serial_port->input;
while (1) {
my ($rb, $byte) = $serial_port->read(1);
if ($rb > 0) {
#print $byte;
$data = "$data$byte";
if($byte eq "\n") {
$data =~ s/^[^,]+//;
$data = time().$data;
chomp($data);
$url = $url.$data;
print "$data\n";
print $fd "$data\n";
$fd->flush;
$data = "";
my $contents = get($url);
}
}
}
#print Dumper($response);