Hello I am making a new code for a nodemcu8266 sensor, what I want to do is the following ...
1 read the DHT11 sensor data from the sensor connected to nodemcu8266 send them to thingspeak and write into the first two fields,
2 those fields are got from an extenral program processend and two new signals should be send to put on or off two leds red and blue according to level of temperature too high ...
3 the thingspeak should send the written data , 0 or 1 to nodemcu82666 and put on or off the leds accordingly.
Now the problem is that I am getting error when I connect and I dunno why...
this is the program I did:
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include <dht.h> // Include DHT Header file for DHT sensor.
#define dht_apin D2 // Analog Pin sensor is connected to pin D2.
dht DHT;// Including library for DHT sensor.
//Replace your wifi credentials here
//const char* ssid = "******************";
//const char* password = "******************";
//change your channel number here
unsigned long channel = ******************;
//Weather Station using NodeMCU ESP8266 & Thingspeak IoT Analytics.
String apiKey = "******************"; // Enter your Write API key from ThingSpeak IoT Analytics Cloud platform.
String ReadapiKey = "******************"; // Enter your read API key from ThingSpeak IoT Analytics Cloud platform.
//int LEDblu = 12 ; // Choose the pin for the LED (Pin D6, GPIO 12)
//int LEDrosso = 15 ; // Choose the pin for the LED (Pin D8, GPIO 15)
unsigned int LEDblu_CH = 4; // dichiarazione channel field 4
unsigned int LEDrosso_CH = 5; //dichiarazione channel field 5
const char *ssid = "******************"; // Replace with your Wi-Fi ssid.
const char *pass = "******************"; // // Replace with your Wi-Fi wpa2 key.
const char *server = "api.thingspeak.com"; //Initializing Server.
WiFiClient client;
void setup()
{
// Program written in setup will run only once for connecting to Wi-Fi network.
Serial.begin(115200); // Selecting the baud rate for Serial Communication.
delay(500);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// initialize digital pin LEDblu,LEDrosso as an output.
pinMode(D6, OUTPUT); // Led Blu
pinMode(D8, OUTPUT); // Led Rosso
digitalWrite(D6, 0);
digitalWrite(D8, 0);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass); // Wi-Fi network searching starts.
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected."); //Prints on serial monitor if Wi-Fi gets connected sucessfully.
}
void loop()
{
DHT.read11(dht_apin); // Reading DHT sensor pin D2's data.
// prende i dati dai campi field di thingspeak creando delle var temporanee
int led_blu = ThingSpeak.readFloatField(channel, LEDblu_CH);
int led_rosso = ThingSpeak.readFloatField(channel, LEDrosso_CH);
float h = DHT.humidity; // Storing the humidity float value in variable h
float t = DHT.temperature; // Storing the temperature float value in variable h
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);
// Printing DHT Sensor's Humidity & Temperature on Serial Monitor.
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" C, Humidity: ");
Serial.print(h);
Serial.println("% ||| Data sent to Thingspeak IoT Analytics Cloud platform.");
if(led_blu == 1){
digitalWrite(D6, 1);
Serial.println("led blu is On..!");
}
else if(led_blu == 0){
digitalWrite(D6, 0);
Serial.println("led blu is Off..!");
}
if(led_rosso == 1){
digitalWrite(D8, 1);
Serial.println("led rosso is On..!");
}
else if(led_rosso == 0){
digitalWrite(D8, 0);
Serial.println("led rosso is Off..!");
}
Serial.println(led_blu);
Serial.println(led_rosso);
}
client.stop();
Serial.println("Waiting..."); // Waiting for new data to be sensed by DHT Sensor.
// thingspeak needs minimum 15 sec delay between on Cloud console updates for free subscription.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
}
this is the error I am getting:
16:42:18.825 -> ............
16:42:24.575 -> WiFi connected.
16:42:24.575 ->
16:42:24.575 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
16:42:24.575 ->
16:42:24.575 -> Exception (28):
16:42:24.575 -> epc1=0x4020123f epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
16:42:24.623 ->
16:42:24.623 -> >>>stack>>>
16:42:24.623 ->
16:42:24.623 -> ctx: cont
16:42:24.623 -> sp: 3ffffd20 end: 3fffffc0 offset: 0190
16:42:24.623 -> 3ffffeb0: 00000000 00000001 3fffff1c 3ffe85dc
16:42:24.623 -> 3ffffec0: 3ffefa84 0000000e 3fffff10 40203917
16:42:24.623 -> 3ffffed0: 001abfd9 0000000e 3fffff10 40203988
16:42:24.623 -> 3ffffee0: 001abfd9 3ffefa84 3fffff10 40203a3c
16:42:24.623 -> 3ffffef0: 3ffe8899 00000004 3ffee7a0 40203a65
16:42:24.623 -> 3fffff00: 00000005 00000004 3ffee7a0 402013a3
16:42:24.623 -> 3fffff10: 3ffefbec 000e000f 80000000 3ffefa84
16:42:24.623 -> 3fffff20: 000e000f 89000034 3ffee788 40202a1a
16:42:24.623 -> 3fffff30: 3ffe8860 00000100 0001c200 3ffee9ac
16:42:24.623 -> 3fffff40: 3fffdad0 3ffee7a0 3ffee788 402015aa
16:42:24.671 -> 3fffff50: 40202b7c 3ffe885e 3ffee920 40202b88
16:42:24.671 -> 3fffff60: 40202b7c 3ffe885e 3ffee920 40202de8
16:42:24.671 -> 3fffff70: 3ffe85d0 0000000f 3ffee920 40202ecc
16:42:24.671 -> 3fffff80: 3ffef384 40201cb8 3ffee9ac 40202ef0
16:42:24.671 -> 3fffff90: 3ffe85d0 3ffee8e4 3ffee920 3ffee9ac
16:42:24.671 -> 3fffffa0: 3fffdad0 00000000 3ffee998 40203fc8
16:42:24.671 -> 3fffffb0: feefeffe feefeffe 3ffe85f0 40100c11
16:42:24.671 -> <<<stack<<<
16:42:24.671 ->
16:42:24.671 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
16:42:24.718 ->
16:42:24.718 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
16:42:24.718 ->
16:42:24.718 -> load 0x4010f000, len 3460, room 16
16:42:24.718 -> tail 4
16:42:24.718 -> chksum 0xcc
16:42:24.718 -> load 0x3fff20b8, len 40, room 4
16:42:24.718 -> tail 4
16:42:24.718 -> chksum 0xc9
16:42:24.718 -> csum 0xc9
16:42:24.718 -> v00045740
16:42:24.718 -> ~ld
16:42:25.287 -> Connecting to
16:42:25.287 -> ***********
16:42:25.762 -> .....
and keeps going repeating this .. .what can be the issue?
thanks for any help!

