For some reason using my DHT22 sensor I keep getting "NaN". I have tried using older versions of the DHT22 sensor library as suggested by a few of my searches, but it still doesn't fix the issue.
Also I can't get it to work with the GET request portion. Any help would be greatly appreciated.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Phant.h>
#include <ESP.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "Myyyyyyh";
const char* password = "Ixxxxx1";
const char* host = "script.google.com";
//*****example address
//https://script.google.com/macros/s/AKfycbyNsFc87GQmRP3GnWoTzK6/exec?tag=test&value=8
const String gardenchart = "/macros/s/AKfycbyNnWoTzK6/exec?";
const byte sleeptime = 1;
const byte NUM_FIELDS = 5;
const String fieldNames[NUM_FIELDS] = {"ghumidity", "gtemp", "light", "otemp", "wtemp"};
String fieldData[NUM_FIELDS];
void setup() {
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
fieldData[0] = 1;
postdata();
ESP.deepSleep(sleeptime * 60 * 1000000, WAKE_RF_DEFAULT);
}
void loop() {
delay(50);
}
void postdata() {
fieldData[0] = dht.readHumidity();
fieldData[1] = dht.readTemperature(true);
WiFiClient client;
const int httpPort = 80;
if (!client.connect (host, httpPort)) {
return;
}
for (int i=0; i<NUM_FIELDS; i++) {
client.print("GET ");
client.print(fieldNames[i]); client.print("&value=");
client.print(fieldData[i]); client.print(" HTTP/1.1");
client.println("Host:"); client.print(host);
Serial.print(fieldNames[i] + fieldData[i]); delay(500);
}
client.println("Connection: close");
}