Go Down

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


Jul 27, 2014, 01:54 pm Last Edit: Jul 27, 2014, 05:29 pm by zeox Reason: 1
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() {

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

float getTemp(byte* address) {
 sensors.setResolution(address, REZ);
 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]

include "php_serial.class.php";
$serial = new phpSerial;

$read $serial->readPort();


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


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