My goal is to attach multiple DHT11 sensors to a single board and then send the data to a remote server for graphing. The sending of data works. The problem I am having is with the data from the two sensors.. They both report the same information.
That leads me to believe that the (float)DHT11.temperature is calling the same sensor both times.
Can anyone assist me?
// Temperature Probe - Dual sensors
// Include for Webserver
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xFE, 0x00 };
byte ip[] = { 172, 31, 11, 191 };
byte gateway[] = { 172, 31, 11, 129 };
byte subnet[] = { 255, 255, 255, 128 };
byte server[] = { 172, 31, 11, 70 };
EthernetClient client;
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 2*1000; // delay between updates, in milliseconds
// Include for DTHT11
#include <dht11.h>
dht11 DHT11;
void setup()
{
// LCD Setup
Serial.begin(9600);
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac, ip, gateway, subnet);
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// Declare variables
int chk0 = DHT11.read(A0);
int chk1 = DHT11.read(A1);
switch (chk0)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Sensor 1: Checksum error"); break;
case -2: Serial.println("Sensor 1: Time out error"); break;
default: Serial.println("Sensor 1: Unknown error"); break;
}
int dblHum = (float)DHT11.humidity;
double dblCTemp = (float)DHT11.temperature;
double dblFTemp = Fahrenheit(DHT11.temperature);
Serial.print("Sensor 1: TMP=");
Serial.print(dblFTemp);
Serial.print(" HUM=");
Serial.println(dblHum);
if (client.connect(server, 80)) {
Serial.println("connecting...");
client.print("GET /arduino.php?loc=sensor1&tmp=");
client.print(dblFTemp);
client.print("&hum=");
client.print(dblHum);
client.println(" HTTP/1.1");
client.println("Host: 172.31.11.70");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
switch (chk1)
{
case 0:
Serial.println("OK"); break;
case -1: Serial.println("Sensor 2: Checksum error"); break;
case -2: Serial.println("Sensor 2: Time out error"); break;
default: Serial.println("Sensor 2: Unknown error"); break;
}
int dblHum2 = (float)DHT11.humidity;
double dblCTemp2 = (float)DHT11.temperature;
double dblFTemp2 = Fahrenheit(DHT11.temperature);
Serial.print("Sensor 2: TMP=");
Serial.print(dblFTemp2);
Serial.print(" HUM=");
Serial.println(dblHum2);
if (client.connect(server, 80)) {
Serial.println("connecting...");
client.print("GET /arduino.php?loc=sensor2&tmp=");
client.print(dblFTemp2);
client.print("&hum=");
client.print(dblHum2);
client.println(" HTTP/1.1");
client.println("Host: 172.31.11.70");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
// Delay
delay (10000);
}
}
}
/* --(end main loop )-- */
/-----( Declare User-written Functions )-----/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}