hi every one I'm try to do iot project from this link this link and my code is
#include <DHT.h> // Including library for dht
#include <ESP8266WiFi.h>
String apiKey = "80ICOTKOF07YJJX4"; // Enter your Write API key from ThingSpeak
const char *ssid = "Hussam"; // replace with your wifi ssid and wpa2 key
const char *pass = "0GJHEA4D";
const char* server = "api.thingspeak.com";
#define DHTPIN 0 //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(10000);
}
and I'm getting
Executable segment sizes:
IROM : 243992 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27868 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1268 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 1092 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 25048 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 274220 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27408 bytes (33%) of dynamic memory, leaving 54512 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port COM7
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 84:0d:8e:a4:77:12
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 278368 bytes to 202928...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 278368 bytes (202928 compressed) at 0x00000000 in 17.9 seconds (effective 124.4 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
and I get nothing at the cloud fields I look for this on the internet but all the answer says that's not a problem but they never give me a clear solution
the connection is exactly the same in link
I just want to knew what's the issue is about the code or the hardware and how to fix it or how to make my code work
User contributions licensed under CC BY-SA 3.0