1

So here is my code, Its the simple_server example from ESPAsyncWebServer.h and encryption example from PracticalCrypto.h combined. the webserver works fine and I can see the / page, but the moment I open the /get page, where the code for encryption exmple is, esp8266 crashes. I tried removing while (1) yield(); but the problrm is persistent. Is PracticalCrypto too much for esp8266? So why is this happening?

#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <Arduino.h>
#include <PracticalCrypto.h>

PracticalCrypto crypto;
AsyncWebServer server(80);

const char* ssid = "123456789";
const char* password = "123456789";

const char* PARAM_MESSAGE = "message";

void notFound(AsyncWebServerRequest *request) {
    request->send(404, "text/plain", "Not found");
}

void setup() {

    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("WiFi Failed!\n");
        return;
    }
    
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Hello, world");
    });

    // Send a GET request to <IP>/get?message=<message>
    server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        } else {
            message = "No message sent";
        }
String key = crypto.generateKey();
           crypto.setKey(key);
    
    // let's make sure the key was set.
    // if the key is empty, it's likely your key doesn't have the right length
    key = crypto.getKey();
    Serial.printf("\nEncryption key: %s\n", key.c_str());


    String plaintext = "hello world!";
    Serial.printf("Plaintext: '%s'\n", plaintext.c_str());

    String ciphertext = crypto.encrypt(plaintext);

    if (ciphertext.length() == 0) {
        Serial.printf("Encryption failed (status %d)\n", crypto.lastStatus());
        while (1) yield();
    }

    Serial.printf("Ciphertext: '%s'\n", ciphertext.c_str());
        request->send(200, "text/plain", "Hello, GET: " + message);
    });

    // Send a POST request to <IP>/post with a form field message set to <message>
    server.on("/post", HTTP_POST, [](AsyncWebServerRequest *request){
        String message;
        if (request->hasParam(PARAM_MESSAGE, true)) {
            message = request->getParam(PARAM_MESSAGE, true)->value();
        } else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, POST: " + message);
    });

    server.onNotFound(notFound);

    server.begin();
}

void loop() {
}

Here last prints before crash

23:02:10.050 -> Encryption key: E*o24<7c%J3Ss1Qk=7*_.c/Y3wIi']Er sjaSE8KyxX)*XqROj)X#$7+\tvhv Q/
23:02:10.050 -> Plaintext: 'hello world!'
23:02:10.050 -> 
23:02:10.050 -> User exception (panic/abort/assert)
23:02:10.050 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
23:02:10.050 -> 
23:02:10.050 -> Panic core_esp8266_main.cpp:191 __yield
0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.