Hello,
I like to print some temperature values on a website(only lan).
Following I have done:
- Setup ttyUSB0:
stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
- Load sketch on my Arduino:
#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;
}
- Test my connection and function:
echo "A" > /dev/ttyUSB0 && cat /dev/ttyUSB0
→ I get the right temperature value!
-
Download https://php-serial.googlecode.com/svn/trunk/php_serial.class.php
-
My index.php:
<?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?