Hello! I'm new to arduino and nodemcu and I'm encountering an exeption(28) and an error. Please help me rectify it, as I need to submit it as a part of my university project. Thank you for the help!
So I'm trying to use nodemcu and 3 push buttons to display the data from an api.
Here I've connected the push buttons to pins D5, D6 and D7 of the nodemcu.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <ACROBOTIC_SSD1306.h>
#define button1 D6
#define button2 D5
#define button3 D7
int buttonValue = 0;
const char *ssid = "my_ssid";
const char *password_wifi = "my_password";
String payload;
void setup()
{
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
Serial.begin(115200);
Wire.begin();
oled.init(); // Initialze SSD1306 OLED display
oled.clearDisplay(); // Clear screen
//oled.setTextXY(0,0);
WiFi.begin(ssid, password_wifi);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("Connecting...");
}
delay(1000);
}
void loop()
{
oled.clearDisplay();
int val;
int httpCode;
if (WiFi.status() == WL_CONNECTED)
{ //oled.setTextXY(0,0);
Serial.println("Connected to WiFi");
String postdata = "sinchanagupta@gmail.com";
HTTPClient http; //Object of class HTTPClient
http.begin("http://jsonplaceholder.typicode.com/users/");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST(postdata); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
int val = buttonselection();
String value = String(val);
display_info(value);
}
}
int buttonselection()
{
while((digitalRead(button1) == LOW) && (digitalRead(button2) == LOW) && (digitalRead(button3) == LOW))
{
if (digitalRead(D6) == 1)
{
buttonValue = 1;
break;
}
else if (digitalRead(D5) == 1)
{
buttonValue = 2;
break;
}
else if (digitalRead(D7) == 1)
{
buttonValue = 3;
break;
}
}
return buttonValue;
}
void display_info(String value)
{
HTTPClient http; //Object of class HTTPClient
http.begin("http://jsonplaceholder.typicode.com/users/" + value);
int httpCode = http.GET();
payload = http.getString();
if (httpCode > 0)
{
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject &root = jsonBuffer.parseObject(payload);
oled.clearDisplay();
int id = root["id"];
const char *name = root["name"];
const char *username = root["username"];
const char *email = root["email"];
oled.clearDisplay();
Serial.print("Name:");
Serial.println(name);
Serial.print("Username:");
Serial.println(username);
Serial.print("Email:");
Serial.println(email);
oled.setTextXY(0,0); // Set cursor position, start of line 0
oled.putString(name);
oled.setTextXY(1,0); // Set cursor position, start of line 1
oled.putString(username);
oled.setTextXY(2,0); // Set cursor position, start of line 2
oled.putString(email);
}
else
{
Serial.println("Error");
}
http.end();
}
Here is the output:-
11:50:22.462 -> Connected to WiFi
11:50:23.162 -> 201
11:50:23.162 -> {
11:50:23.162 -> "sinchanagupta@gmail.com": "",
11:50:23.162 -> "id": 11
11:50:23.162 -> }
11:50:24.191 -> Name:
11:50:24.191 -> Username:
11:50:24.237 -> Email:
11:50:24.237 ->
11:50:24.237 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
11:50:24.237 ->
11:50:24.237 -> Exception (28):
11:50:24.237 -> epc1=0x40204865 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
11:50:24.237 ->
11:50:24.237 -> >>>stack>>>
11:50:24.237 ->
11:50:24.237 -> ctx: cont
11:50:24.237 -> sp: 3ffffc50 end: 3fffffc0 offset: 0190
11:50:24.237 -> 3ffffde0: 00000000 00000000 3ffee58c 4020462a
11:50:24.237 -> 3ffffdf0: 00000000 3ffee5b4 3ffee58c 4020186d
11:50:24.237 -> 3ffffe00: 3ffefac4 3ffefb2c 3ffefb2c 3fff0004
11:50:24.237 -> 3ffffe10: 001c001f 00000281 00010050 3f001388
11:50:24.237 -> 3ffffe20: 3fff002c 0011001f 00fffe6d 70747468
11:50:24.237 -> 3ffffe30: 40204800 84fee5b4 3fff00ec 0000001f
11:50:24.283 -> 3ffffe40: 000013c0 3ffefcd4 0011001f 0010090f
11:50:24.283 -> 3ffffe50: 00000000 000001d2 80fffe80 00000000
11:50:24.283 -> 3ffffe60: 00000000 00000194 00000002 40205201
11:50:24.283 -> 3ffffe70: 00000000 3ffe000a 3fffff00 402054f9
11:50:24.283 -> 3ffffe80: 8000000a 00000000 3fff0054 3ffffe9c
11:50:24.283 -> 3ffffe90: 3ffee43a 3ffffe9c 3fffff0a 40208818
11:50:24.283 -> 3ffffea0: 0034003f 3fff01cc 00000564 4020547c
11:50:24.283 -> 3ffffeb0: 00000000 000000c9 3fffff6c 402054ac
11:50:24.283 -> 3ffffec0: 3fffff78 000000c9 3ffffee0 3ffee630
11:50:24.283 -> 3ffffed0: 3fffdad0 000000c9 3ffee5b4 402019d5
11:50:24.329 -> 3ffffee0: 3ffef8cc 3ffefa34 3ffefa34 3ffefacc
11:50:24.329 -> 3ffffef0: 001c001f 000c17ee 3f010050 40001388
11:50:24.329 -> 3fffff00: 6573752f 002f7372 87006d61 70747468
11:50:24.329 -> 3fffff10: 3ffee400 8400003c 3ffefa6c 0000004f
11:50:24.329 -> 3fffff20: 00fe8717 3ffefa0c 0011001f 00207539
11:50:24.329 -> 3fffff30: 3ffe8700 00000000 8022002e 00000000
11:50:24.329 -> 3fffff40: 00000000 00000000 ffffffff 3ffee601
11:50:24.329 -> 3fffff50: 00000000 0023000a 3fff0194 0000002f
11:50:24.329 -> 3fffff60: 00fede40 00000000 00000000 33373031
11:50:24.329 -> 3fffff70: 35393636 8a003635 33373031 35393636
11:50:24.376 -> 3fffff80: 8a003635 3ffefc9c 002f002f 00206b0a
11:50:24.376 -> 3fffff90: 3ffef7b4 0017001f 00fee458 40201130
11:50:24.376 -> 3fffffa0: feefeffe 00000000 3ffee5f0 4020601c
11:50:24.376 -> 3fffffb0: feefeffe feefeffe 3ffe84f4 40100e4d
11:50:24.376 -> <<<stack<<<
11:50:24.376 ->
11:50:24.376 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
11:50:24.376 ->
11:50:24.376 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
11:50:24.376 ->
11:50:24.376 -> load 0x4010f000, len 3584, room 16
11:50:24.424 -> tail 0
11:50:24.424 -> chksum 0xb0
11:50:24.424 -> csum 0xb0
11:50:24.424 -> v2843a5ac
11:50:24.424 -> ~ld
11:50:25.786 -> Connecting...
11:50:26.810 -> Connecting...