esp32 wifi websocket fastled -- crash

raysconcept
Posts: 2
Joined: Wed May 12, 2021 4:30 pm

esp32 wifi websocket fastled -- crash

Postby raysconcept » Wed May 12, 2021 5:33 pm

///////////////////////////////////////////////////////////////////////////////////////////////

ISSUE: (code main.cpp is below)

I am working with ESP32, Wifi + WebSockets + ArduinoJson + Fastled and experiences crashes also.
It seems to run fine until I implement FastLed. I am sending instructions from nodejs (what leds to turn on etc) via websocket in json-format. It crashes when fastled.show(); is invoked;

just before the error occurs and crashes, the jsonparser stops working (results in null on all values)
then this error pops, and the esp is nonresonsive, the error message is even not completed

Guru Meditation Error: Core 1 panic'ed (StoreProhi
///////////////////////////////////////////////////////////////////////////////////////////////
hardware:

board: huzzah32 feather
leds: ws2815
///////////////////////////////////////////////////////////////////////////////////////////////
platformio.ini:

[env:huzzah]
platform = espressif32
board = featheresp32
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^6.17.3
ottowinter/ArduinoJson-esphomelib@^6.15.2
fastled/FastLED@^3.4.0

///////////////////////////////////////////////////////////////////////////////////////////////
This is the warning message I get when uploading to the board (not sure if it is related to the crash):

In file included from src\main.cpp:38:0:
.pio\libdeps\huzzah\FastLED\src/FastLED.h:14:21: note: #pragma message: FastLED version 3.004.000
# pragma message "FastLED version 3.004.000"
^
In file included from .pio\libdeps\huzzah\FastLED\src/FastLED.h:65:0,
from src\main.cpp:38:
.pio\libdeps\huzzah\FastLED\src/fastspi.h:135:23: note: #pragma message: No hardware SPI pins defined. All SPI access will default to bitbanged output
# pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"
///////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////
THE CODE (MAIN.CPP)
///////////////////////////////////////////////////////////////////////////////////////////////

// WIFI & WEBSOCKET
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebSocketClient.h>
#include <Preferences.h>

// json parser
#include <ArduinoJson.h>
#include <string>
#include <string.h>
#include <cstring>
#include <iostream>
/*
#include <sstream>
using namespace std;
#define ARDUINOJSON_ENABLE_STD_STREAM 1
*/

// LEDS
//#include <Adafruit_NeoPixel.h>
#define FASTLED_ALLOW_INTERRUPTS 0
#define FAST_LED_REFRESH_CORE 0
#include <FastLED.h>
#include <math.h>

unsigned long msMax = 4000; //L; // duration of effect === speed
unsigned long msStart = millis(); // = 0; // reset to millis()

/*
// lengte van serie van gekoppelde strips (max 1333 leds):
#define NUM_LEDS 60 // LEDS totaal aan 1 ring (360 = 6tubes(x1m) x 60leds/m)
#define NUM_RINGS 3 // STRIP is 1 ring. 360 x 3ringen = 1080byte. Dan nog 253 bytes over voor programma.
#define DATA_PIN1 16
#define DATA_PIN2 17
#define DATA_PIN3 19
CRGB rings[NUM_RINGS][NUM_LEDS]; // de ledstrips per ring (1 ring gedraagt zich als 1 lange strip van 6m)
*/

//eeprom = electrically erasable programmable read-only memory
Preferences pref;

byte mac[6];
char macaddress[30];
//std::string macaddress;
WebSocketClient webSocketClient;

// Use WiFiClient class to create TCP connections
WiFiClient wifiClient;
StaticJsonDocument<200> jsondoc;

#define NUM_LEDS 60

CRGB leds[NUM_LEDS];
int nr;
int L;

void led_00()
{

for (L = 0; L < NUM_LEDS; L++)
{
leds[L].setRGB(50, 0, 0);
FastLED.show();
}
return;
}

void led_01()
{
nr = round(NUM_LEDS * (millis() - msStart) / msMax);
for (L = 0; L < nr; L++)
{
leds[L].setRGB(0, 0, 0);
}
leds[nr].setRGB(100, 0, 0);
FastLED.show();
return;
}
void led_02()
{
nr = round(NUM_LEDS * (millis() - msStart) / msMax);
for (L = 0; L < nr; L++)
{
leds[L].setRGB(0, 0, 0);
}
leds[nr].setRGB(0, 100, 0);
FastLED.show();
return;
}

///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
int ix = 0;
int esptime = 0;
void setup()
{
// FastLED.addLeds<NEOPIXEL, DATA_PIN2>(rings[2], NUM_LEDS);

FastLED.addLeds<NEOPIXEL, 22>(leds, NUM_LEDS);
/*
FastLED.addLeds<NEOPIXEL, 23>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, 17>(leds, NUM_LEDS);
*/
// FastLED.addLeds<WS2812, 22>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, 23>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, 17>(leds, NUM_LEDS);

msStart = millis();

Serial.begin(9600);
//delay(10);
// pref.begin("xxx", false);
//delay(10);
//String pwd = pref.getString("pw", "rays1234");

WiFi.mode(WIFI_AP);
Serial.print("Connecting to WENSLICHTROUTER");
WiFi.begin("WENSLICHTROUTER", "rays1234");
int wifi_try = 0;
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
wifi_try += 1;
if (wifi_try > 10)
{
Serial.println("restarting");
delay(1000);
esp_restart();
}
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

delay(1000);

//get the mac address of the Magafter
WiFi.macAddress(mac);
if (wifiClient.connect("192.168.0.100", 3003))
{
Serial.println("ESP32 CONNECTED TO S3_COM");
}
else
{
Serial.println("ESP32 FAILED TO CONNECT TO S3_COM");
while (1)
{
esptime += 1;
if (esptime > 100)
{
esp_restart();
}
Serial.println("while esp32 failed to connect to S3_COM (restart at 100), time:");
Serial.println(esptime);
}
}
//turn the mac array into a char array with separators
memset(macaddress, 0, sizeof(macaddress));
char result[5];
for (int i = 0; i < 6; i++)
{
memset(result, 0, sizeof(result));
sprintf(result, "%x", (char)mac);
//macaddress = (char)mac;
strcat(macaddress, result);
strcat(macaddress, "-");
}
// Handshake with the server
webSocketClient.path = (char *)"/"; // path;
webSocketClient.host = (char *)"192.168.0.100"; //eehost;
if (webSocketClient.handshake(wifiClient))
{
Serial.println("ESP32 HANDSHAKE TO S3_COM SUCCES");
Serial.println(macaddress);

String MSGNOW = "HANDSHAKE";
String msg = "{\"from\":\"ESP\",\"msg\":\"" + MSGNOW + "\",\"mac\":\" " + macaddress + "\",\"time\":\"" + String(millis()) + "\"}";
webSocketClient.sendData(msg);
MSGNOW = ""; //reset
//led_handshake_oke();
}
else
{
Serial.println("ESP32 HANDSHAKE TO S3_COM FAILED");
// while (1)
// {
// }
}
ix = 0;
}

//std::__cxx11::string fromIn;
String toIn("");

//
/*
String msgIn;
String MSGNOW;
String msgReturn;
String dataIn;
*/

String MSGNOW;
time_t timenow = time(0);
int currentShow = 0;

void loop()
{
//Serial.println(ESP.getFreeHeap()); //=> 26900 - 269400
String data;
if (ix > 10000)
{
ix = 0;
}
++ix;

//Serial.println(WiFi.status());
//led_loop();
// int nr = round(NUM_LEDS * (millis() - msStart) / msMax);
//Serial.println("n="+nr);

if (millis() - msStart > msMax)
{
// effect duration, bijvoorbeeld snelheid van de snow
msStart = millis();
}

if (wifiClient.connected())
{
webSocketClient.getData(data);

if (data.length() > 0)
{
Serial.println("data");
Serial.println(data);
DeserializationError err = deserializeJson(jsondoc, data);
if (err)
{
Serial.println("error deserialization");
Serial.println(err.c_str());
return;
}
//vTaskDelay(100); //delay(100); // delay stopt hele processor, vTaskDelay pauseert alleen proces
Serial.println("websocketClient deserialize end");

String fromIn = jsondoc["from"];
Serial.print(fromIn);
Serial.print(" / ");

String toIn = jsondoc["to"];
Serial.print(toIn);
Serial.print(" / ");
// std::string toInSub = str.substr(1, str.size()); // incomming mac bevat een spatie aan het begin, die wordt er hiermee vanaf gehaald
String actionIn = jsondoc["action"];
Serial.print(actionIn);
Serial.print(" / ");

String msgIn = jsondoc["msg"];
Serial.print(msgIn);
Serial.print(" / ");

if (msgIn == "PROBEBROADCAST" || msgIn == "PROBEDIRECT")
{
MSGNOW = "PROBEOKE";
}
else
{
MSGNOW = msgIn;
}

if (msgIn == "LED_01")
{
currentShow = 1;
}
if (msgIn == "LED_02")
{
currentShow = 2;
}
String echo = "{\"from\":\"ESP\",\"msg\":\"" + MSGNOW + "\",\"mac\":\"" + macaddress + "\",\"time\":\"" + String(millis()) + "\"}";
webSocketClient.sendData(echo);
MSGNOW = "";
}

if (currentShow == 0)
{
led_00();
Serial.print("S0 ");
}
else if (currentShow == 1)
{
led_01();
Serial.print("S1 ");
}
else if (currentShow == 2)
{
led_02();
Serial.print("S2 ");
}
}
else
{
Serial.println("disconnected?");
esp_restart();
}
}

Who is online

Users browsing this forum: No registered users and 106 guests