Go Down

Topic: Need help: SerialPort and PHP under Linux (Read 4786 times) previous topic - next topic

zeox

Jul 27, 2014, 01:54 pm Last Edit: Jul 27, 2014, 05:29 pm by zeox Reason: 1
Hello,
I like to print some temperature values on a website(only lan).

Following I have done:

1. Setup ttyUSB0:
Code: [Select]
stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

2. Load sketch on my Arduino:
Code: [Select]

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#define REZ 12

OneWire oneWire(ONE_WIRE_BUS); /* Ini oneWire instance */
DallasTemperature sensors(&oneWire);/* Dallas Temperature Library */

DeviceAddress sensor1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //replaced
DeviceAddress sensor2 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

int incomingByte = 0;

void setup() {
  Serial.begin(9600);
  sensors.begin();
}

void loop() {
 if (Serial.available() > 0) {
               // read the incoming byte:
               incomingByte = Serial.read();
               if (incomingByte == 'A') {
                 Serial.print(getTemp(sensor1));
               }
               if (incomingByte == 'I') {
                 Serial.print(getTemp(sensor2));
               }
 }
}

float getTemp(byte* address) {
 sensors.setResolution(address, REZ);
 sensors.requestTemperaturesByAddress(address);
 float back = sensors.getTempC(address);
 return back;
}


3. Test my connection and function:
Code: [Select]
echo "A" > /dev/ttyUSB0 && cat /dev/ttyUSB0
-> I get the right temperature value!

4. Download https://php-serial.googlecode.com/svn/trunk/php_serial.class.php

5. My index.php:
Code: [Select]
<?php

include "php_serial.class.php";
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);

$serial->deviceOpen();
$serial->sendMessage("A");
$read $serial->readPort();
$serial->deviceClose();
echo 
$read;

?>




But I get no output on my website and no error?

erni-berni

Hi,
are you sure that php (apache) is permitted to read the seriell interface ?
In Linux the user and group for apache ist www-data. You have to add this user to the group dialout.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy