Postlad/Guides/ESP8266 DHT22 cloud dashboard with plain HTTP
ESP8266 DHT22 cloud dashboard with plain HTTP
An ESP8266 can put DHT22 temperature and humidity readings on a live cloud dashboard with one HTTP GET request. The sketch below uses the board's built-in WiFi, prints the complete server reply and needs no MQTT broker or TLS certificate bundle.
That last point matters on the ESP8266. It is still a capable sensor board, but its memory and certificate handling are less forgiving than a current ESP32.
Reviewed, not yet bench-tested on this exact NodeMCU and sensor combination.
Parts
- NodeMCU ESP8266 development board
- DHT22/AM2302 sensor
- 10 kΩ resistor if the sensor is not on a breakout board
- Breadboard and three jumper wires
- Micro-USB cable
- Arduino IDE 2.x
- Adafruit
DHT sensor libraryandAdafruit Unified Sensor - Free Postlad account and write key
Wiring
| DHT22 pin | NodeMCU |
|---|---|
| VCC | 3V3 |
| DATA | D1, which is GPIO5 |
| GND | GND |
For a bare four-pin DHT22, add a 10 kΩ resistor between DATA and 3V3. Most three-pin breakout boards already include it.
Use the GPIO number in code, not the printed D1 label. On NodeMCU, D1 maps to GPIO5.
Complete NodeMCU sketch
Install the ESP8266 board package, select NodeMCU 1.0 (ESP-12E Module), fill in the three constants, and upload.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <DHT.h>
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* WRITE_KEY = "YOUR_KEY";
const char* POSTLAD_URL = "http://api.postlad.com/u";
const unsigned long SEND_INTERVAL_MS = 30000;
#define DHT_PIN 5
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);
void connectWiFi() {
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.print("\nConnected. IP: ");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
delay(200);
dht.begin();
delay(2000);
connectWiFi();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("DHT read failed: check power, data pin and pull-up resistor");
delay(2000);
return;
}
if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
connectWiFi();
}
WiFiClient client;
HTTPClient http;
String url = String(POSTLAD_URL)
+ "?k=" + WRITE_KEY
+ "&f1=" + String(temperature, 2)
+ "&f2=" + String(humidity, 1);
if (!http.begin(client, url)) {
Serial.println("Could not start HTTP request");
delay(SEND_INTERVAL_MS);
return;
}
int status = http.GET();
String body = http.getString();
Serial.printf(
"%.2f C %.1f %%RH -> HTTP %d %s\n",
temperature,
humidity,
status,
body.c_str()
);
http.end();
delay(SEND_INTERVAL_MS);
}Open Serial Monitor at 115200 baud. A successful line looks like:
23.41 C 51.8 %RH -> HTTP 200 ok 148Configure the chart
On the stream page, set:
| Field | Name | Unit | Decimals |
|---|---|---|---|
f1 | Temperature | °C | 1 or 2 |
f2 | Humidity | %RH | 1 |
The names affect the chart, CSV export and share page. They do not change the device request.
Why plain HTTP is useful here
TLS works on the ESP8266, but doing it properly means fitting a trust anchor, setting a valid clock and planning for certificate changes. Calling setInsecure() encrypts the connection without proving who is on the other end.
Postlad's device endpoint supports plain HTTP as a first-class route. The request is small and the response is readable. The trade-off is equally plain: somebody able to observe that network can see the reading and write key.
Use a trusted network, isolate the sensor VLAN, or use HTTPS with certificate validation when the data or key is sensitive. A houseplant and a laboratory freezer do not have the same threat model.
Keep the write key out of public code
The write key lets its holder add readings. It is not the URL you share with viewers.
- Commit
YOUR_KEY, never a live key. - Rotate a key that reaches a public Git repository.
- Give viewers a public or secret read link.
- Do not put personal information in
statusor field names.
Improve reliability without hiding failures
The sketch retries WiFi on the next loop. It does not claim that a missed sample was stored.
For an unattended logger:
- Record the HTTP status and body.
- Add a watchdog for a genuinely wedged network stack.
- Store timestamped samples locally if every sample matters.
- Replay those samples through the batch endpoint after reconnection.
Never convert a failed DHT read to zero. Zero degrees and zero humidity are valid-looking measurements. A gap is more honest and easier to diagnose.
DHT11 changes
Change one line:
#define DHT_TYPE DHT11The wiring and request remain the same. The DHT11 has a narrower range, lower accuracy and whole-number output. Use it when you already own one, not because its lower price will survive the time spent explaining its readings.
Troubleshooting
The ESP8266 resets during a request
Use a stable USB supply and cable. WiFi transmission creates short current peaks that expose weak power supplies. If the serial log mentions watchdog resets, also look for long blocking loops or a library mismatch.
The DHT reading is nan
Check the GPIO mapping, 3.3 V supply and pull-up resistor. Do not read a DHT22 more often than about once every two seconds. The example waits 30 seconds between successful cycles.
The board never joins WiFi
ESP8266 supports 2.4 GHz, not 5 GHz. Captive portals and many enterprise networks also require an interactive login the sketch cannot perform.
HTTP returns a negative value
That is a client-side failure, not a server status. Print http.errorToString(status).c_str() during diagnosis if you need the ESP8266 library's explanation.
The server returns 429
The request is arriving faster than the stream's rate limit. Slow the loop and honour the Retry-After header. Repeatedly hammering a rejected request only delays recovery.
FAQ
Can ESP8266 send DHT22 data to the cloud without MQTT?
Yes. A periodic HTTP request is enough for a temperature and humidity logger. MQTT is optional, not a prerequisite for a remote chart.
Which NodeMCU pin should I use for DHT22?
GPIO5, printed as D1 on most NodeMCU boards, is a straightforward choice. Avoid confusing the board label with the GPIO number used by the Arduino core.
Is ESP8266 still suitable for IoT projects?
Yes, for small WiFi sensor nodes. Its constraints become noticeable with large TLS stacks, complex web interfaces or many libraries, but one short request every 30 seconds is well within its role.
How long does Postlad keep the readings?
On Free, every reading is kept at full detail for 30 days. After that it becomes an hourly minimum, maximum and average, kept for 12 months. Older than that is deleted.
Can I share the dashboard without exposing the key?
Yes. Share the stream's public or secret read link. The write key stays on the device and never belongs in the viewer URL.
Create the stream
Create a free account, paste the stream's write key into the sketch, then send the viewer link rather than a screenshot.
Related guides
- Send ESP32 data to the cloud: the newer board version, including a no-sensor test.
- Arduino data logger online: UNO R4 WiFi and analogue input.
- Try an ESP32 cloud dashboard in Wokwi: test the request from a browser simulator.
- Build a room monitor: turn temperature and humidity into a complete installation.
- Free IoT dashboard for students: sharing and retention for course projects.
Sources and verification
- ESP8266 Arduino Core documentation: https://arduino-esp8266.readthedocs.io/en/latest/
- Library releases can change behaviour; record the board package and DHT library versions used in your build notes.