2

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");
}
dda
1,5951 gold badge12 silver badges17 bronze badges
asked May 28, 2017 at 1:25

1 Answer 1

2

The Adafruit DHT library causes a shortcut on the signal line. That can be a problem for Arduino boards, but it is a big problem for the ESP8266.
Issue: DHT init sequence wrong #48
I don't know what is a bigger problem, the shortcut in the code or Adafruit not fixing it.

Why do you mention the Arduino Uno with a label ?
For the "GET" you should find a good working example.

The DHT22 is not very good. There are better sensors with a normal I2C interface, for example the HTU21D-F or the BME-280. This is about a great test: Hackaday: Humidity Sensor Shootout. The BME-280 is the undisputed winner.

answered May 28, 2017 at 5:58
1
  • I'll look for a BMW, for the GET request it was working when I was using sparkfun's data hosting. I am switching to posting to my Google sheet and that's when something isn't working quite right. Commented May 28, 2017 at 12:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.