Hi,
Can somebody help me out as I can't see the answer to my problem.
I'm running an Ethernet Shield with a thermistor and wish to add the values to a mysql database. I know the php script works as I can insert a number instead of (celsius)"); and then run the script and the number appears in the database. My problem is with the sketch which works accept it wont pass the data to the php file which lives at /var/www/ard_log/update.phpThermometer0()
Here is the sketch:
#include <SPI.h>
#include <WString.h>
#include <Ethernet.h>
#define READING_PIN 0
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
*LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x11, 0xAC }; //physical mac address
byte ip[] = { 192, 168, 1, 19 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 4; // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
//#################################################
double R1 = 10000.0; //resistance put in parallel
double V_IN = 5.0;
double A = 1.129148e-3;
double B = 2.34125e-4;
double C = 8.76741e-8;
double K = 9.5; // mW/dec C - dissipation factor
double SteinhartHart(double R)
{
// calculate temperature
double logR = log(R);
double logR3 = logR * logR * logR;
return 1.0 / (A + B * logR + C * logR3 );
}
//#################################################
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
//#############################################
double adc_raw = analogRead(READING_PIN);
//Serial.println(adc_raw);
double V = adc_raw / 1024 * V_IN;
//calculate resistance
double R_th = (R1 * V ) / (V_IN - V);
double kelvin = SteinhartHart(R_th) - V*V/(K * R_th);
int celsius = kelvin - 273.15;//was double but changed to int to remove decimal places
Serial.print(celsius);
Serial.println();
client.print("Temp.");
client.print(" is ");
client.print(celsius);
client.println(".C");
client.println("GET /http://192.168.1.20/ard_log/update_db.php?celsius=");
client.println(celsius);
client.println(" HTTP/1.1\r\n");
client.println("Host: http://192.168.1.20");
client.println();
delay(1000);
//##############################################
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
and here is the php:
<?php
//Connect to database
$con = mysql_connect("xxxx", "xxxx", "xxxx");
if(!$con)
{
die('Could not connect: ' .mysql_error());
}
mysql_select_db("1stClassElec", $con);
mysql_query("INSERT INTO device_1(temp) VALUES (celsius)");
mysql_close($con);
?>
Any help would be appreciated as I've spent hours on this problem