Ich bin jetzt so weit…
Arduino Sketch
#include <DHT.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac = { 0x90, 0xA2, 0xDA, 0x0E, 0xB, 0x76 }; // RESERVED MAC ADDRESS
EthernetClient client;
#define DHTPIN 8 // SENSOR PIN
#define DHTTYPE DHT11 // SENSOR TYPE - THE ADAFRUIT LIBRARY OFFERS SUPPORT FOR MORE MODELS
DHT dht(DHTPIN, DHTTYPE);
long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 2500; // READING INTERVAL
int t = 0; // TEMPERATURE VAR
int h = 0; // HUMIDITY VAR
String data;
void setup() {
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
}
dht.begin();
delay(10000); // GIVE THE SENSOR SOME TIME TO START
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
data = “”;
}
void loop(){
currentMillis = millis();
if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
previousMillis = currentMillis;
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
}
data = “temp1=” + String(t) + “&hum1=” + String(h);
if (client.connect(“localhost”,80)) { // REPLACE WITH YOUR SERVER ADDRESS ++++ ODER LOCALHOST
client.println(“POST /add.php HTTP/1.1”);
client.println(“Host: localhost”); // SERVER ADDRESS HERE TOO
client.println(“Content-Type: application/x-www-form-urlencoded”);
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
}
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
delay(300000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}
Und das hier die dazugehörigen php skripte…
<?php
include("connect.php");
$link=Connection();
$result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
?>
Arduino INFO 1
Temperatur und Feuchtigkeit im Badezimmer
<?php
if($result!==FALSE){
while($row = mysql_fetch_array($result)) {
printf("",
$row["timeStamp"], $row["temperature"], $row["humidity"]);
}
mysql_free_result($result);
mysql_close();
}
?>
Timestamp |
Temperatur in *C |
Feuchtigkeit in % |
%s |
%s |
%s |
<?php
function Connection(){
$server="localhost";
$user= "root" ;
$pass="raspberry";
$db="raspberrypidb";
$connection = mysql_connect($server, $user, $pass);
if (!$connection) {
die('MySQL ERROR: ' . mysql_error());
}
mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
return $connection;
}
?>
<?php
include("connect.php");
$link=Connection();
$temp1=$_POST["temp1"];
$hum1=$_POST["hum1="];
$query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
VALUES ('".$t."','".$h."')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>
Leider kommen keine Daten in der Datenbank an… jemand eine Idee?
Vielen vielen Dank