Pages: [1]   Go Down
Author Topic: Need help: SerialPort and PHP under Linux  (Read 800 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I like to print some temperature values on a website(only lan).

Following I have done:

1. Setup ttyUSB0:
Code:
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:
#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:
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:
<?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?
« Last Edit: July 27, 2014, 10:29:42 am by zeox » Logged

Pages: [1]   Go Up
Jump to: