Hi. I trying send dht22 data to mysql base in specific time with ds3231. But it always send 'nan' data. When i send data only with dht22, it works fine, but not with ds3231. What's the problem?
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS1307RTC.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Newer Ethernet shields have a MAC address printed on a sticker on the shield
IPAddress server(192, 168, 7, 1); //IPv4 address
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);
EthernetClient client;
void setup() {
Serial.begin(9600);
// wait for Arduino Serial Monitor
while (!Serial) ;
// get and set the time from the RTC
setSyncProvider(RTC.get);
if (timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
Alarm.alarmRepeat(10, 30, 0, Morningalarm);
Ethernet.begin(mac);
dht.begin();
}
void loop() {
digitalClockDisplay();
// wait one second between each clock display in serial monitor
Alarm.delay(1000);
}
int idSensor = 1;
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float fah = dht.readTemperature(true); //reading the temperature in Fahrenheit
float heat_index = dht.computeHeatIndex(fah, hum); //Reading the heat index in Fahrenheit
float heat_indexC = dht.convertFtoC(heat_index); //Converting the heat index in Celsius
void Morningalarm() {
if (client.connect(server, 80)) {
Serial.println("connected");
client.print("GET /data.php?");
client.print("temperature=");
client.print(temp);
client.print("&humidity=");
client.print(hum);
client.print("&heat_index=");
client.print(heat_indexC);
client.print("&idSensor=");
client.print(idSensor);
client.println(" HTTP/1.1");
client.println("Host: 192.168.7.1");
client.println("Connection: close");
client.println();
client.stop(); //Closing the connection
} else {
//if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}

