Exception (28) and fatal exception 28 (LoadProhibitedCause)

I have made the code for a humidity and temperature controller that are supposed to send data to ThingSpeak as well.

Here is how the code looks like:

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 0     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Uncomment to get temperatures in fahrenheit
//#define USE_FAHRENHEIT

#define WARMRELAYPIN 2
#define COOLRELAYPIN 3
#define HUMIDRELAYPIN 4
#define DRYRELAYPIN 5
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
#include "ThingSpeak.h"

// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Ethernet shield, WiFi101 shield, esp8266, ESP32, and MKR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************


#include <ESP8266WiFi.h>

const char ssid[] = "TAH";
const char pass[] = "28.Januar1951";

unsigned long ChannelNumber = 557790;
char WriteAPIkey[] = "A71VMEADZDSF5ISQ";
char ReadAPIKey[] = "JQ05PV694PGR4L3A";

void setup() {
  
  Serial.begin(9600);
         delay(10);
               
       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"); 
  
  Serial.println("DHTxx test!");
  pinMode(WARMRELAYPIN, OUTPUT);
  pinMode(COOLRELAYPIN, OUTPUT);
  pinMode(HUMIDRELAYPIN, OUTPUT);
  pinMode(DRYRELAYPIN, OUTPUT);
  digitalWrite(WARMRELAYPIN, HIGH);
  digitalWrite(COOLRELAYPIN, HIGH);
  digitalWrite(HUMIDRELAYPIN, HIGH);
  digitalWrite(DRYRELAYPIN, HIGH);
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(1000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  //Now send the data to ThingSpeak
  ThingSpeak.setField(1,t);
  ThingSpeak.setField(2,h);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  delay(500);
  if (t <= 12.00){
    digitalWrite(WARMRELAYPIN, LOW);
  } else {
    digitalWrite(WARMRELAYPIN, HIGH);
  }
  
  if (t >= 13.00){
    digitalWrite(COOLRELAYPIN, LOW);
  
  } else {
    digitalWrite(COOLRELAYPIN, HIGH);  
  }
  if (h < 72){
    digitalWrite(HUMIDRELAYPIN, LOW);
  } else {
    digitalWrite(HUMIDRELAYPIN, HIGH);
  }
  if (h > 73){
    digitalWrite(DRYRELAYPIN, LOW);
  } else {
    digitalWrite(DRYRELAYPIN, HIGH);
  }
  delay(1000);
  ThingSpeak.writeFields(ChannelNumber, WriteAPIkey);
  
}

When running the code, however, I get this:

SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
Connecting to 
TAH
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
.
connected with TAH, channel 13
dhcp client start...
ip:192.168.1.137,mask:255.255.255.0,gw:192.168.1.1
.
WiFi connected
DHTxx test!
Humidity: 50.20 %	Temperature: 24.10 *C 75.38 *F	Heat index: 23.88 *C 74.98 *F
Fatal exception 28(LoadProhibitedCause):
epc1=0x40202a99, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (28):
epc1=0x40202a99 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3ffffcc0 end: 3fffffd0 offset: 01a0

>>>stack>>>
3ffffe60:  0000005c 00000028 0000005d 00000077  
3ffffe70:  33323130 37363534 62613938 3ffeeafc  
3ffffe80:  0000002c 3fffff2c 3ffeedd8 3ffeedd8  
3ffffe90:  00000020 00000000 0000002c 401009c1  
3ffffea0:  3ffffee0 00000001 3fffff2c 40204e11  
3ffffeb0:  00000002 3fffff38 3fffff2c 3ffeeb50  
3ffffec0:  00000020 3fffff20 3fffff20 40204d93  
3ffffed0:  3fff0244 0000001f 3fffff20 3ffeeb50  
3ffffee0:  3ffe84dc 3fffff20 3ffeeadc 40202c8c  
3ffffef0:  00000009 00000000 3fffff20 40204ec4  
3fffff00:  3ffe8b44 3fffff38 3ffeeadc 40204eec  
3fffff10:  00000009 00000000 3ffeeadc 402032a1  
3fffff20:  3fff01d4 0000001f 0000001f 00000000  
3fffff30:  00000000 00000000 00000000 00000000  
3fffff40:  00000000 00000000 00000000 00000000  
3fffff50:  3fff0244 0000001f 0000001f 3ffeecf0  
3fffff60:  000882de 3ffe84dc 402051f8 3fffefb0  
3fffff70:  40201792 000003e8 000003e8 4296c28f  
3fffff80:  41c0cccd 4248cccd 3ffeeadc 402034fd  
3fffff90:  41bf023c 4295f46d 00000000 401069e9  
3fffffa0:  3ffe8b6c 00000003 3ffeebdc 3ffeec9c  
3fffffb0:  3fffdad0 00000000 3ffeec94 40205284  
3fffffc0:  feefeffe feefeffe 3ffe85f4 40100a49  
<<<stack<<<
⸮⸮⸮K⸮

When I comment on line "ThingSpeak.writeFields(ChannelNumber, WriteAPIkey);", the issue will disappear, but will not upload to ThingSpeak. How do I work around this?

Hi,
It looks like the DHT sensor is not connecting.

Have you written this in stages?
Do you have code that just reads the sensor and outputs to the serial, no wifi or ThnkSpeak code?

Also check that pin 0 on the ESP is available and not one of the programming pins for the ESP.

Tom... :slight_smile:

TomGeorge:
Hi,
It looks like the DHT sensor is not connecting.

Have you written this in stages?
Do you have code that just reads the sensor and outputs to the serial, no wifi or ThnkSpeak code?

Also check that pin 0 on the ESP is available and not one of the programming pins for the ESP.

Tom... :slight_smile:

The DHT sensor does connect as it puts out read temp and humidity into serial monitor.

What do you mean by "written in stages"?

Yes. I have that type of code which causes no problems.

pin 0 is NOT an esp programming pin

btw, here is the decoded stacktrace

Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
Decoding 15 results
0x40202a99: ThingSpeakClass::connectThingSpeak() at C:\Users\eirik_000\OneDrive\Dokumenter\Arduino\libraries\ThingSpeak\src/ThingSpeak.h line 1744
0x40202a99: ThingSpeakClass::connectThingSpeak() at C:\Users\eirik_000\OneDrive\Dokumenter\Arduino\libraries\ThingSpeak\src/ThingSpeak.h line 1744
0x401009c1: ppEnqueueTxDone at ?? line ?
0x40204e11: String::init() at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/WString.cpp line 782
:  (inlined by) String::String(String const&) at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/WString.cpp line 39
0x40204d93: String::copy(char const*, unsigned int) at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/WString.cpp line 782
0x40202c8c: ThingSpeakClass::writeRaw(unsigned long, String, char const*) at C:\Users\eirik_000\OneDrive\Dokumenter\Arduino\libraries\ThingSpeak\src/ThingSpeak.h line 1195
0x40204ec4: String::String(float, unsigned char) at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/WString.cpp line 782
0x40204eec: String::concat(char const*, unsigned int) at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/WString.cpp line 782
0x402032a1: ThingSpeakClass::writeFields(unsigned long, char const*) at C:\Users\eirik_000\OneDrive\Dokumenter\Arduino\libraries\ThingSpeak\src/ThingSpeak.h line 1144
0x402051f8: run_scheduled_functions() at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/Schedule.cpp line 73
0x40201792: delay at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/core_esp8266_wiring.c line 54
0x402034fd: loop at C:\Users\eirik_000\OneDrive\Dokumenter\Arduino\sketch_aug09a/sketch_aug09a.ino line 147
0x401069e9: pvPortCalloc at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/heap.c line 160
0x40205284: ~_List_node at C:\Users\eirik_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/ScheduledFunctions.cpp line 18
:  (inlined by) destroy   > at c:\users\eirik_000\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\ext/new_allocator.h line 124
:  (inlined by) std::_List_base   >::_M_clear() at c:\users\eirik_000\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/list.tcc line 75
0x40100a49: ppEnqueueRxq at ?? line ?

btw, I have managed to solve the issue myself now, so no more need for any assistance. Looked over the code and found I was missing these lines:

WiFiClient client;

ThingSpeak.begin(client);

please close this thread now

Hi,
Good to hear.
You will find you can edit the subject line of this thread, just add to it [SOLVED}.

That will indicate to anyone that the thread had a solution, the thread remains accessible for other to look at if the have a similar problem.

Thanks for advising on how you solved your problem... Tom.. :slight_smile: