Advertisement
ZaynerTech

webinterface.cgi for Arduino communication through a webpage

Mar 31st, 2014
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.76 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # Takes post from webpage and sends it to a temp file for Arduino to eventually see.
  4. #
  5.  
  6. local ($buffer, @pairs, $pair, $name, $value, %FORM);
  7.     # Read in text
  8.     $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
  9.     if ($ENV{'REQUEST_METHOD'} eq "POST")
  10.     {
  11.         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  12.     }else {
  13.         $buffer = $ENV{'QUERY_STRING'};
  14.     }
  15.     # Split information into name/value pairs
  16.     @pairs = split(/&/, $buffer);
  17.     foreach $pair (@pairs)
  18.     {
  19.         ($name, $value) = split(/=/, $pair);
  20.         $value =~ tr/+/ /;
  21.         $value =~ s/%(..)/pack("C", hex($1))/eg;
  22.         $FORM{$name} = $value;
  23.     }
  24.    
  25.     if($temper = $FORM{temper})
  26.     {
  27.       `echo "$temper:Temp\n" > /tmp/Thermo`;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement