I have one problem on programming harduino. I have two arduino. In the first there are Sensor Tmperature DHT22 and Transmitter 433 mhz. In the second there are reciever and ethernet shield. The first must send temperature and Humidity at the second arduino that it must load into a database located in a one server(altervista).
All works fine, the read of parameters and sending the data on second arduino, but the data not load into database.
This is the code that I done for the receiver arduino(rx):
#include <DataCoder.h>
#include <VirtualWire.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
IPAddress ip(192,168,1,127); //indirizzo IP disponibile sulla rete
IPAddress myDns(8,8,8,8); //tuo DNS
char server[] = "www.ilmeteomolfetta.altervista.org"; //sito web
EthernetClient client;
String strURL = ""; //Stringa per caricare dati sul web
const int rx_pin=4;
const int led_pin=13;
void setup()
{
delay(1000);
Serial.begin(9600);
SetupRFDataRxnLink(rx_pin, 800);
Ethernet.begin(mac, ip, myDns);
//Invio al PC il mio IP
Serial.print("Il mio IP: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
if(client.connect(server,80))
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
union RFData inDataSeq;//To store incoming data
float inArray[2];//To store decoded information
if(RFLinkDataAvailable(buf, &buflen))
{
for(int i =0; i< buflen; i++)
{
inDataSeq.s[i] = buf[i];
}
DecodeRFData(inArray, inDataSeq);
Serial.print("Umidita': ");
Serial.print(inArray[1]);
Serial.print("\t");
Serial.print("Temperatura: ");
Serial.print(inArray[0]);
Serial.println();
}
Serial.println("Connessione...");
//Creo URL
strURL="GET /add.php?temp="; //URL
strURL+=inArray[0];
strURL+="&umi=";
strURL+=inArray[1];
strURL+=" HTTP/1.1";
//Invio richiesta al server
client.println(strURL);
client.println("Host: www.ilmeteomolfetta.altervista.org");
client.println("Connection: Close");
client.println();
client.stop();
Serial.println(strURL);
delay(5000);
}
else
{
Serial.println("Errore di connessione...");
Serial.println("Disconnessione in corso...");
client.stop();
}
}
and this is the code that writes into database from ethernet shild:
<?php
include("connect.php");
$link=Connection();
$temp1=$_POST["temp1"];
$hum1=$_POST["hum1"];
$query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
VALUES ('".$temp1."','".$hum1."')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>
The problem is that when I view the data it show 0 to temperature and Humidity because in $temp1=$_POST["temp1"]; $hum1=$_POST["hum1"];
I think that the problem is the array used for create the string to send request to database from arduino because in temp1 and hum1 the values are 0