Ahoj, kúpil som si Arduino a chcem skúsiť jeden test. Mám 2 teplomery DS18B20 ale je tu problém, že hodnoty namerám a viem si ich normálne vypísať v serial monitore, potrebujem to poslať do mysql databázy. Súbor add.php na hostingu vykoná toto:
<?php
include("connect.php");
$temp1=$_GET["temp1"];
$temp2=$_GET["temp2"];
$ins = mysqli_query($con,"INSERT INTO `TempLivingRoom` (`temperature`) VALUES ('".$temp1."')") or die (mysqli_error($con));
$ins2 = mysqli_query($con,"INSERT INTO `TempOutside` (`temperature`) VALUES ('".$temp2."')") or die (mysqli_error($con));
header("Location: index.php");
?>
Problémom ale je, že neviem ako takúto premennú zapísať v .ino súbore a následne to poslať. Mám takýto script pre jednu hodnotu, ale nefunguje to. Ak by niekto vedel helfnuť s urobením scriptu pre jednu hodnotu a príklad budem rád..
Potrebujem to na webclient.
#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("GET /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 + "temp1";
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);
}
}