Go Down

Topic: ESP8266 WiFiClientSecure crash (Read 104 times) previous topic - next topic

sirko

I'm trying to get json data but nodeMcu crash on boot, I think is related to SSL, on port 80 without SSL(local host) is working fine.
How can I get this to work? Thanks
Sketch:
Code: [Select]
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
const char* ssid = "XXX";
const char* password = "XXX";
const char *fingerprint = "B3:C4:FB:5F:CC:18:AD:6F:AC:50:70:DE:CA:33:92:65:69:4E:99:3D";
void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // Connect to HTTP server
  WiFiClientSecure client;
  //client.setInsecure();
  client.setFingerprint(fingerprint);
  client.setTimeout(3000);

  if (!client.connect("hydroxsystems.co.uk", 443)) {
    Serial.println(F("Connection failed"));
    return;
  }
  Serial.println(F("Connected!"));

  // Send HTTP request
  client.println(F("GET /HomeAutomation/index.php?data=2 HTTP/1.0"));
  client.println(F("hydroxsystems.co.uk"));

  client.println(F("Connection: close"));
  if (client.println() == 0) {
    Serial.println(F("Failed to send request"));
    return;
  }

  // Check HTTP status
  char status[32] = {0};
  client.readBytesUntil('\r', status, sizeof(status));
  // It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK"
  if (strcmp(status + 9, "200 OK") != 0) {
    Serial.print(F("Unexpected response: "));
    Serial.println(status);
    return;
  }

  // Skip HTTP headers
  char endOfHeaders[] = "\r\n\r\n";
  if (!client.find(endOfHeaders)) {
    Serial.println(F("Invalid response"));
    return;
  }

  // Allocate the JSON document
  // Use arduinojson.org/v6/assistant to compute the capacity.
  const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
  DynamicJsonDocument doc(capacity);

  // Parse JSON object
  DeserializationError error = deserializeJson(doc, client);
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.c_str());
    return;
  }

  // Extract values
  Serial.println(F("Response:"));
  Serial.println(doc["key"].as<char*>());
  Serial.println(doc["timestamp"].as<long>());
  Serial.println(doc["threshold"].as<int>());

  // Disconnect
  client.stop();
}
void loop() {}


Error:
Code: [Select]
.....scandone
state: 0 -> 2 (b0)
.state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt

connected with XXXXX, channel 6
dhcp client start...
....ip:192.168.100.18,mask:255.255.255.0,gw:192.168.100.1
BSSL:_connectSSL: start connection
Fatal exception 9(LoadStoreAlignmentCause):
epc1=0x402094cc, epc2=0x00000000, epc3=0x00000000, excvaddr=0xfeefeffe, depc=0x00000000

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x402094cc epc2=0x00000000 epc3=0x00000000 excvaddr=0xfeefeffe depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffb40 end: 3fffffc0 offset: 0190
3ffffcd0:  3ffffdf0 3ffee698 3ffffe70 40204f09
3ffffce0:  3ffe0000 0000005a 000000a0 401008fd
3ffffcf0:  00000000 00000000 3ffeec68 4021b010
3ffffd00:  00000968 3ffee79c 00000008 401008fd
3ffffd10:  00000014 3ffef5ec 000000ff 00000000
3ffffd20:  00000006 3ffeebf0 00000020 40100c20
3ffffd30:  401007e8 3ffee79c 0000001e 3ffef5ec
3ffffd40:  3ffef804 3ffeec68 00000000 4021b058
3ffffd50:  3ffeec68 00000000 00000000 40100260
3ffffd60:  00000000 4bc6a7f0 0000193c 4021b07e
3ffffd70:  3ffeec68 00000000 00000000 4021bc13
3ffffd80:  3ffee8e8 00000008 401001f6 40217162
3ffffd90:  3ffeec68 3ffee79c 3ffee800 40212f61
3ffffda0:  401051b1 001eee5e 3ffef670 00000000
3ffffdb0:  00f42400 3dcbf479 001eee00 00000000
3ffffdc0:  40105435 001eee5e 3ffee77c 00000000
3ffffdd0:  401051b1 001eeef1 00000001 3ffee678
3ffffde0:  401052dd 3ffee77c 3ffee77c 00000034
3ffffdf0:  00000000 00000001 3ffee678 40207862
3ffffe00:  00000000 3ffffe70 3ffef6b4 4020348c
3ffffe10:  3ffee678 00000000 00000d50 000001bb
3ffffe20:  3ffffe70 3ffe8683 3ffee660 000001bb
3ffffe30:  3ffffe70 3ffe8683 00000001 4020513f
3ffffe40:  40209b00 0a3aff95 40209b00 0a3aff95
3ffffe50:  3ffeef1c 00000000 3ffffe70 3ffee720
3ffffe60:  3ffe8681 3ffee698 3ffee660 40201d7e
3ffffe70:  402099a0 00000000 00003a98 feefeffe
3ffffe80:  00000000 3ffef6b4 3fff1354 3ffef8ec
3ffffe90:  00000000 00000000 3fff1354 00000000
3ffffea0:  00000000 3fff6474 3ffef964 00000000
3ffffeb0:  00000000 3fff20b4 3ffef914 3fff620c
3ffffec0:  3ffef93c 00000000 00000000 00000000
3ffffed0:  00004145 00000255 00000000 00000000
3ffffee0:  00000000 00000000 00000000 00000000
3ffffef0:  00000000 00000000 c4b30100 18cc5ffb
3fffff00:  50ac6fad 33cade70 4e696592 fe003d99
3fffff10:  00000000 feefeffe 00000000 00000000
3fffff20:  feefef00 00000000 00000000 feefeffe
3fffff30:  feefeffe feefeffe feefeffe feefeffe
3fffff40:  feefeffe feefeffe feefeffe feefeffe
3fffff50:  feefeffe feefeffe feefeffe feefeffe
3fffff60:  feefeffe feefeffe feefeffe feefeffe
3fffff70:  feefeffe feefeffe feefeffe feefeffe
3fffff80:  feefeffe feefeffe feefeffe feefeffe
3fffff90:  feefeffe feefeffe feefeffe feefeffe
3fffffa0:  3fffdad0 00000000 3ffee6e0 40207378
3fffffb0:  feefeffe feefeffe 3ffe8530 40100f11
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

smah

Well,
your stacktrace says..

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
PC: 0x402094cc
EXCVADDR: 0xfeefeffe


so check  you connection with DHC or Postman. Also try to add https in you client.connect line.


sirko

Fixed it last night... I had bad GET request now is working fine

Go Up