Hello there, i want to send temperature datas to database. My add.php have this code:
<?php
include("connect.php");
$temp=$_POST["temp"];
$ins = mysqli_query($con,"INSERT INTO `tempLog` (`temperature`) VALUES ('".$temp."')") or die (mysqli_error($con));
header("Location: index.php");
?>
Please i dont know how to send datas from Arduino. I got big problems with that. Please send me code, which will working. I want Arduino in Client mode.
My .ino file:
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.arduino.php5.sk";
IPAddress ip(192, 168, 1, 254);
EthernetClient client;
int t = 0; // TEMPERATURE VAR
String data;
void setup() {
Serial.begin(9600);
sensors.begin();
data = "1";
t = (int) sensors.getTempCByIndex(0);
while (!Serial) {
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Zlyhanie DHCP protokolu!");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("Priprájam...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("Pripojené");
// Make a HTTP request:
client.println("POST /add.php HTTP/1.1");
client.println("Host: www.arduino.php5.sk");
client.print(data);
client.println();
client.println("Pripojenie uzavreté");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("Pripojenie neúspešné");
}
}
void loop() {
sensors.requestTemperatures();
t = (int) sensors.getTempCByIndex(0); // Send the command to get temperatures
data = t + "temp";
delay(10000);
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
delay(10000);
Serial.println("Odpojené");
client.stop();
// do nothing forevermore:
while (true);
}
}
I want 2 temperatures, can you help me with that? I got Uno R3 (CH340) and Ethernet shield W5100. My temperature equipments are Dallas DS18B20