Monday, February 15, 2010

Inexpensive Professional Camcorder

LM35+LCD+web+MySQL - 5) Logger,mysql e cron

The first script is the fetcher, in charge of opening the serial port , agreed to send a character ('s' in our case) read the temperature and sends the Arduino and print. ------------------------------------------------ -------------------------------------------------- --------- First of all, we must add the user under which runs the HTTP daemon default (Apache), the group dialout, otherwise the website will not have access to Arduino. Indeed solo gli utenti di questo gruppo hanno il diritto di accedere alle periferiche.
Nel caso di Ubuntu l'utente di Apache è www-data , quindi da shell si lancierà:
$ sudo usermod -a -G dialout www-data
Una volta modificato, riavviare Apache: $ sudo /etc/init.d/apache2 restart Le modifiche così apportate saranno applicate definitivamente. ----------------------------------------------------------------------------------------------------------- Agli inizi avevo provato con phpSerial (una libreria in PHP per la gestione della seriale), ma ho avuto molti malfunzionamenti spesso subdoli che mi hanno portato a sostituirla in favore di Device::Serial Port (
http://search.cpan.org/dist/Device-SerialPort/
) una libreria Perl per la gestione della seriale davvero efficiente e facile da impiegare. La cosa senz'altro più interessante di questa libreria è che consente di disabilitare la linea DTR e quindi di prevenire l'autoreset di Arduino 10000 ogni qualvolta si invia un dato sulla seriale. Per installare Device::Serial Port da Ubuntu/Debian:
$ sudo apt-get install libdevice-serialport-perl Essendo gli altri script in PHP si è usata una funzione wrapper PHP ( fetchTemp() ) che fa semplicemente il lavoro di richiamare da sistema lo script fetcher.pl e riporlo in a variable available to other PHP scripts. Here are two scripts:
FETCHER.PL # / usr / bin / perl-w ########### ################################################## ############################################ #

# Reason: simply download and print to video the temperature acquired by Arduino.










# # Requires: Device:: SerialPort \u0026lt; ; http://search.cpan.org/ ~ cook/Device-SerialPort-1.04/SerialPort.pm>
        # # On Ubuntu: $ sudo apt-get install perl-SerialPort-libdevice      #  

####################################### ################################################## ################ use strict ; use
Device :: SerialPort ; my $portName = "/dev/ttyUSB0" ; # identificativo seriale/USB usata my
$bps = "9600" ; # velocità in bps my
$car = 's' ; # character agreed to the request data
# Constructor (opens the door and commit the resources hw)

my $ port =



Device: SerialPort ->

new
  ($ portName   
)
-> databits
( 8
)
die "failed setting parity"
;
$ port -> stopbits
(
1) di Arduino)

sleep ( 1 );
# attendi 1s # Invia carattere convenuto per la richiesta della temperatura
$port
-> lookclear ;
# svuota buffer $port -> write ( $car ); # invia carattere convenuto
# Legge dato da seriale (in pooling) my $ gotit = "" ;

# data read
until ( " it $ gotit ) { $ gotit
$ port = -> lookfor ; # poll until data ready die "Aborted without match \\ n "Unless
(
defined
$ gotit );}
Destroyer # (closes the door and releases the resources hw)

$ port -> close
wrapper script in PHP, FETCHER.PHP : \u0026lt;?

/******************************************** ************************************************** ***
* * Reason: function "wrapper" for the Perl script to fetch the temperature from Arduino *
* Author: Francesco Parisi (fparisi at tiscali dot it), (fparisi at gmail dot com) * * ************* ************************************************** **********************************/


function
fetchTemp () { $ perlCmd
= '/ usr / bin / perl' ; / / Perl full control of its path $ path = '/ home / frank / public_html /' ; / / path to the Perl script (complete with '/' end)


$ script =
'fetcher.pl'

;

/ / Perl script name


$ temperature =
    exec 
( $ perlCmd . ''
. $ path.
$ script); return
$ temperature;} ?>


highlighted code generated by Generator:
GNU source- highlight 3.1 by Lorenzo Bettini


http://www.lorenzobettini.it

http://www.gnu.org/software/src-highlite

 

0 comments:

Post a Comment