ESP8266 Exception 28 - esp8266

I has a sketch that startings a web server to show files in LittleFS. But when it is starting, it's crashing with Exception code 28.
My full code:
#include <FS.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <LittleFS.h>
FS* fileSystem = &LittleFS;
File uploadFile;
ESP8266WebServer server(80);
void handleRoot() {
String lstemp = "<html>\
<head>\
<title>ESP8266 FS Browser</title>\
</head>\
<body>\
<nav>\
Disk Info\
</nav>\n";
if ((server.hasArg("path") ? server.arg("path") : "/").endsWith("/")) {
Dir dir = fileSystem->openDir(server.hasArg("path") ? server.arg("path") : "/");
Serial.println("listing dir");
while (dir.next()) {
Serial.println(dir.fileName());
if (dir.isFile()) {
lstemp += "<a href='/?path=" + (server.hasArg("path") ? server.arg("path") : "/") + dir.fileName() + "'>" + dir.fileName() + "</a><br>\n";
} else {
lstemp += "<a href='/?path=" + (server.hasArg("path") ? server.arg("path") : "/") + dir.fileName() + "/'>" + dir.fileName() + "/</a><br>\n";
}
}
} else {
lstemp = "<html><head><title>ESP8266 FS Browser</title></head><body>You are viewing file now. Click <a href='/download?action=download?path=" + server.arg("path") + "'>here</a> to download\n<iframe src='/download?action=view?path=" + server.arg("path") + "'></iframe>";
}
lstemp += "</body></html>";
server.send(200, "text/html", lstemp);
}
void handleFsInfo() {
String fsinfotemp = "FS: LittleFS\nTotal size: ";
FSInfo fs_info;
LittleFS.info(fs_info);
fsinfotemp += fs_info.totalBytes / 1000;
fsinfotemp += " KB\nUsed: ";
fsinfotemp += fs_info.usedBytes / 1000;
fsinfotemp += "\nFree: ";
fsinfotemp += (fs_info.totalBytes - fs_info.usedBytes) / 1000;
server.send(200, "text/plain", fsinfotemp);
}
void handleUploadFile() {}
void handleDownloadFile() {
if (server.arg("action") == "download") {
server.chunkedResponseModeStart(200, "application/octet-stream");
}
if (server.arg("action") == "view") {
server.chunkedResponseModeStart(200, "text/plain");
}
File downloadable = fileSystem->open(server.arg("path"), (char*)'r');
while (downloadable.available()) {
server.sendContent((char*)downloadable.read());
Serial.write(downloadable.read());
}
server.chunkedResponseFinalize();
downloadable.close();
}
void handleMkdir() {}
void handleRemove() {}
void handleRename() {}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin("MySSID", "MyPASSWORD");
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
ESP.restart();
}
if (!fileSystem->begin()) {
Serial.println("File system begin failed! Formatting LittleFS...");
fileSystem->format();
Serial.println("Done. Reboot ESP8266");
while (1) {;}
}
server.on("/", handleRoot);
server.on("/fsinfo", handleFsInfo);
server.on("/upload", handleUploadFile);
server.on("/download", handleDownloadFile);
server.on("/mkdir", handleMkdir);
server.on("/rm", handleRemove);
server.on("/rename", handleRename);
if (MDNS.begin("esp8266-filehost")) {
MDNS.addService("http", "tcp", 80);
}
server.begin();
}
void loop() {
server.handleClient();
MDNS.update();
}
Full exception code:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (28):
epc1=0x40214c00 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000072 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffca0 end: 3fffffc0 offset: 0190
3ffffe30: 3ffee9c0 ffffffff 00000006 402123c6
3ffffe40: 000052b4 00000430 3fff0924 40208bba
3ffffe50: 3ffffea0 3ffeff78 00000000 40211400
3ffffe60: 0000000a 3ffee9e4 4021439c 00000000
3ffffe70: 3ffffecc 00000000 3ffee9c0 402059d4
3ffffe80: 00000000 3ffeeb64 3ffffea0 4020f901
3ffffe90: 00000000 3ffeeb64 3ffee9c0 40207732
3ffffea0: 00000000 69006e6f 00000000 ffffffff
3ffffeb0: 40211df2 00000001 00000000 00000000
3ffffec0: 0023002f 00000000 00000000 68746170
3ffffed0: 3ffeea00 04000000 00000000 40211400
3ffffee0: 00000000 00000000 4bc6a7f0 3ffeed28
3ffffef0: 3fffdad0 00000001 3fff0204 4021435e
3fffff00: 00000000 00000000 3fff0b3c 401000e9
3fffff10: 00000000 616f6c6e 00000000 402058fd
3fffff20: 3fff04b4 3ffeea08 3ffee9c0 40207876
3fffff30: 00000000 3ffeeb08 00000001 4020accf
3fffff40: 000052ac 00000000 00000000 00000001
3fffff50: 00000001 3ffee9e4 3fff04e8 3ffeed28
3fffff60: 3fffdad0 3ffee9e4 3ffee9c0 402080a2
3fffff70: 00000000 3ffeeb08 3ffeed14 4020adc4
3fffff80: 00000000 00000000 00000001 401003ec
3fffff90: 3fffdad0 00000000 3ffeed14 40208168
3fffffa0: 3fffdad0 00000000 3ffeed14 40211de0
3fffffb0: feefeffe feefeffe 3ffe85dc 40100ea5
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
This crash happens when I added file download function, but I hasn't found an error. Global variables remaining 36% of RAM, but all temp String variables are freed after finishing function automatically. So chunk server sending is collecting a much of junk?

I think that this can happen when converting char to char*. The read function returns a char and at the end of c-strings it should always be null and when converting it is not. Perhaps there is an error in this

Related

ESP8266 BearSSL MQTT Exception when connecting

I am trying to connect to HiveMQ MQTT Broker from my ESP8266, 2 months ago, this code works fine, but now, when I implement more features, the code run with a lot of Exceptions. Sometimes, Exception (28), I'm newbie in this fields and don't know the way to handle it, thanks for your helps.
RAM and Flash:
Exception:
Sometimes:
My Code:
void setup()
{
BearSSL::WiFiClientSecure *bear = setSSLCertificate();
PSclient = new PubSubClient(*bear);
MQTT_ADDRESS = cEEPROM.getMqttAddress();
MQTT_PORT = cEEPROM.getMqttPort();
PSclient->setServer(MQTT_ADDRESS.c_str(), MQTT_PORT);
PSclient->setBufferSize(512);
PSclient->setCallback(myCallback);
}
void loop()
{
wifiConfig.configWifiAP(ENV_SSID_AP, ENV_PASS_AP);
if (!PSclient->connected())
{
reconnect();
}
else
{
PSclient->loop();
}
}
}
void reconnect()
{
while ((!PSclient->connected()) && tryConnectPS <= 5)
{
setDateTime();
String MQTT_ACCOUNT = cEEPROM.getMqttAccount();
String MQTT_USERNAME = cEEPROM.getMqttUsername();
String MQTT_PASSWORD = cEEPROM.getMqttPassword();
Serial.print("Try to connect to MQTT... ");
if (PSclient->connect(MQTT_ACCOUNT.c_str(), MQTT_USERNAME.c_str(), MQTT_PASSWORD.c_str()))
{
Serial.print("Connected state:");
Serial.println(PSclient->state());
String MQTT_TOPIC = cEEPROM.getMqttTopic();
boolean result = PSclient->subscribe(MQTT_TOPIC.c_str());
Serial.print("Tinh trang subscribe topic: ");
Serial.println(result);
tryConnectPS = 0;
DeviceService::turnReadyLedOn();
return;
}
else
{
Serial.print("Failed,rc = ");
Serial.println(PSclient->state());
Serial.println("Try again in 2 seconds ... ");
delay(1000);
tryConnectPS++;
}
}
}
BearSSL::WiFiClientSecure *setSSLCertificate()
{
LittleFS.begin();
int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
Serial.printf("So chung chi CA : %d\n", numCerts);
if (numCerts == 0)
{
Serial.printf("KHONG TIM THAY CHUNG CHI NAO");
}
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
bear->setCertStore(&certStore);
return bear;
}
Full exception:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (28):
epc1=0x40205f0d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
stack>>>
ctx: bearssl
sp: 3fff3690 end: 3fff3a80 offset: 0190
3fff3820: 3ffe8cc1 3fffbd6c 3fffb7f4 40205ef4
3fff3830: 4021bb04 00000000 000003e8 4021ad84
3fff3840: 00000000 00000000 00000000 40213640
3fff3850: 00000000 00000000 3fff116c 4021bb04
3fff3860: 00000000 000003e8 3ad6faec 00000000
3fff3870: 00000000 00000000 40213640 00000000
3fff3880: 00000000 3fff116c bd2fdbf6 925dd89d
3fff3890: c6b3dd59 2f7b7dde 0c3e3fec bc6117ef
3fff38a0: 572033bf f8302d1e 0001d90a 0000056f
3fff38b0: 928b6852 b5d6e5dc d07ddae3 3fffa404
3fff38c0: 3fffa428 3fffae04 000003dd 4023efe6
3fff38d0: 4026ed46 eb148196 203ddbd5 d3597ea7
3fff38e0: f958f8e2 cd48b85b 164f5cfe 551efe29
3fff38f0: 11c8af23 7cea8db0 2f179093 09a2acfd
3fff3900: f03f4647 ffb7b0e9 32684d28 1e5e67d6
3fff3910: 4026f0a7 00000000 00000b80 00000000
3fff3920: 3fffa41c 3fffac04 3fffa4d4 0000001a
3fff3930: 3fffa434 3fffa430 c818691e 0a857cc3
3fff3940: 56789534 54be83d2 466dbc59 1ce0b490
3fff3950: 3416a5e4 0b8510a4 5d8f434c 59ff5645
3fff3960: 3fff6072 0000002a 3fff6072 00000683
3fff3970: 3fff5ad4 3fff52d4 3fff5ab8 4023f682
3fff3980: 3fff5adc 3fff52d4 3fff5ab8 40239cb0
3fff3990: 402083e4 3fff52d4 3ffffdf0 00000004
3fff39a0: 4026d679 00000005 00000000 fffffffe
3fff39b0: 00000000 3fffc6fc 00000000 3fff4b3c
3fff39c0: 0000f811 00000000 3fff11d8 00000030
3fff39d0: deadbeef deadbeef 4026da73 deadbeef
3fff39e0: 3fff5ad8 3fff5b5c 3fff5ad4 deadbeef
3fff39f0: deadbeef 3fff52b8 0000001a 3fff5db8
3fff3a00: 0000001a deadbeef deadbeef deadbeef
3fff3a10: deadbeef deadbeef deadbeef 3fff5dd4
3fff3a20: 000005c2 3fff5cd4 3fff52d4 40237e44
3fff3a30: 3fff5ab8 deadbeef deadbeef deadbeef
3fff3a40: 00000250 00000005 deadbeef 3fff11d8
3fff3a50: 00000000 00000000 3fff52d4 40238439
3fff3a60: 00000100 deadbeef deadbeef deadbeef
3fff3a70: deadbeef 00000000 3fff4b3c 402093b8
ctx: cont
sp: 3ffffde0 end: 3fffffc0 offset: 0000
3ffffde0: 00000000 00000000 00003a98 40208400
3ffffdf0: 000005c2 6e00c440 c4c69916 284c5820
3ffffe00: 00000008 00000001 000024a9 00000000
3ffffe10: 40238f4c 40238f9c 3fff52d4 4023858a
3ffffe20: 3fff57d4 3fff4d44 3fff52d4 3fff4d44
3ffffe30: 00000000 00000001 3fff4b3c 40208453
3ffffe40: 00000000 00000001 3fff4b3c 40208643
3ffffe50: 40105b5d 3fff135c 3fff135c 000000c9
3ffffe60: 00000000 00000000 000022b3 4021733a
3ffffe70: 00000000 3fff4b3c 3fff4cd4 4020746e
3ffffe80: 3fff5194 00000010 3fffff5c 3fff45f4
3ffffe90: 000022b3 3fff4d44 3fff4b3c 3fff45f4
3ffffea0: 000022b3 3fff4d44 3fff4b3c 402086e5
3ffffeb0: 4021bbac 9e5c4936 4021bbac 9e5c4936
3ffffec0: 00000000 3fff4c94 3fff4cbc 4021a08a
3ffffed0: 00000000 3fff4c94 3fff4cbc 4020b3e8
3ffffee0: 3ffe88ec 3fff135c 00000005 000000a4
3ffffef0: 00000000 3fffff74 00000000 00000000
3fffff00: 00000001 3ffe88d2 3fff11a0 40214c34
3fffff10: 40214c28 3ffe88d2 3fff11a0 3fff0f30
3fffff20: 3fff0c48 3fff0d44 3fff11a0 4020b5d0
3fffff30: 00000000 00000000 00000001 402150d0
3fffff40: 3fff0c48 3fff0d44 3fff11a0 4020575a
3fffff50: 3fff0f30 00000001 3fff0c54 3fff4cbc
3fffff60: 000f000f 8a003837 3fff4c94 0012001f
3fffff70: 8a003439 36384d53 4a4b3252 0a003439
3fffff80: 3fffdad0 3fff0d44 3fff0c3c 3fff12f4
3fffff90: 3fffdad0 00000000 3fff0d44 40205b09
3fffffa0: 3fffdad0 00000000 3fff12e0 40216d40
3fffffb0: feefeffe feefeffe 3ffe8650 40100dd9
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
I expect to a successful and stable connection to MQTT Broker

MQTT-SN Gateway - Not able to publish or changed my clientID, but able to connect and subscribe?

I have a project using MQTT-SN protocol, I use this https://github.com/S3ler/arduino-mqtt-sn-client as my MQTT-SN Client (I'm Using nodeMCU same as Arduino ESP8266) , my MQTT-SN Gateway use paho.mqtt-sn.embedded-c on my laptop and for my broker I use Mosquitto on my laptop too
this is the code for the MQTT-SN client
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiUdpSocket.h>
#include <MqttSnClient.h>
const char* ssid = "xxx";
const char* password = "xxx";
#define buffer_length 10
char buffer[buffer_length + 1];
uint16_t buffer_pos = 0;
IPAddress gatewayIPAddress(192, 168, 1, 151);
uint16_t localUdpPort = 1884;
// #define gatewayHostAddress "arsmb.de"
WiFiUDP udp;
WiFiUdpSocket wiFiUdpSocket(udp, localUdpPort);
MqttSnClient<WiFiUdpSocket> mqttSnClient(wiFiUdpSocket);
const char* clientId = "Kevin";
char* subscribeTopicName = "test";
char* publishTopicName = "test";
int8_t qos = 0;
void mqttsn_callback(char *topic, uint8_t *payload, uint16_t length, bool retain) {
Serial.print("Received - Topic: ");
Serial.print(topic);
Serial.print(" Payload: ");
for (uint16_t i = 0; i < length; i++) {
char c = (char) * (payload + i);
Serial.print(c);
}
Serial.print(" Lenght: ");
Serial.println(length);
}
void setup() {
Serial.begin(115200);
delay(1000);
pinMode (sensor,INPUT);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Starting MqttSnClient - ");
mqttSnClient.setCallback(mqttsn_callback);
if (!mqttSnClient.begin()) {
Serial.print("Could not initialize MQTT-SN Client ");
while (true) {
Serial.println(".");
delay(1000);
}
}
Serial.println(" ready!");
}
void convertIPAddressAndPortToDeviceAddress(IPAddress& source, uint16_t port, device_address& target) {
// IPAdress 0 - 3 bytes
target.bytes[0] = source[0];
target.bytes[1] = source[1];
target.bytes[2] = source[2];
target.bytes[3] = source[3];
// Port 4 - 5 bytes
target.bytes[4] = port >> 8;
target.bytes[5] = (uint8_t) port ;
}
void loop() {
if (!mqttSnClient.is_mqttsn_connected()) {
#if defined(gatewayHostAddress)
IPAddress gatewayIPAddress;
if (!WiFi.hostByName(gatewayHostAddress, gatewayIPAddress, 20000)) {
Serial.println("Could not lookup MQTT-SN Gateway.");
return;
}
#endif
device_address gateway_device_address;
convertIPAddressAndPortToDeviceAddress(gatewayIPAddress, localUdpPort, gateway_device_address);
Serial.print("MQTT-SN Gateway device_address: ");
printDeviceAddress(&gateway_device_address);
if (!mqttSnClient.connect(&gateway_device_address, clientId, 180) ) {
Serial.println("Could not connect MQTT-SN Client.");
delay(1000);
return;
}
Serial.println("MQTT-SN Client connected.");
mqttSnClient.subscribe(subscribeTopicName , qos);
}
if (Serial.available()> 0) {
buffer[buffer_pos++] = Serial.read();
if (buffer[buffer_pos - 1] == '\n') {
// only qos -1, 0, 1 are supported
if (!mqttSnClient.publish(buffer, publishTopicName , qos)) {
Serial.println("Could not publish");
}
Serial.println("Published");
memset(buffer, 0x0, buffer_length);
buffer_pos = 0;
}
}
mqttSnClient.loop();
}
and this my MQTT-SN Gateway look, I can only connect and subscribe, I can't Publish or change my clientID
I already try to fix with https://github.com/S3ler/arduino-mqtt-sn-client/issues/3 but still I can't publish and I can only subscribe even my clientid won't change like I declared on my code
I don't know what's wrong with it,Can someone tell me what's wrong with my code?
Edit:
This is what it look like in my Arduino IDE Terminal, Someone know what is the error? or what is the problem that keep me can't publish?
00:57:06.516 -> Connecting to WiFi
00:57:07.061 -> .....
00:57:09.071 -> WiFi connected
00:57:09.071 -> IP address:
00:57:09.071 -> 192.168.1.192
00:57:09.071 -> Starting MqttSnClient - ready!
00:57:09.071 -> MQTT-SN Gateway device_address: 192, 168, 1, 151, 7, 92
00:57:09.173 -> MQTT-SN Client connected.
00:57:09.173 ->
00:57:09.173 -> Exception (28):
00:57:09.173 -> epc1=0x4000bf80 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
00:57:09.173 ->
00:57:09.173 -> >>>stack>>>
00:57:09.173 ->
00:57:09.173 -> ctx: cont
00:57:09.173 -> sp: 3ffffc80 end: 3fffffc0 offset: 0190
00:57:09.173 -> 3ffffe10: 00000011 3ffeeb84 00000000 fffffffe
00:57:09.206 -> 3ffffe20: 00000011 00000001 00000001 3ffef57c
00:57:09.206 -> 3ffffe30: 3ffef500 3ffef57c 3ffef4fc 40215182
00:57:09.206 -> 3ffffe40: 3ffeec00 00000000 00000000 40215cef
00:57:09.206 -> 3ffffe50: 00000016 3ffee478 3ffe8750 40210538
00:57:09.206 -> 3ffffe60: 3ffeec00 0000005a 00000020 40100990
00:57:09.206 -> 3ffffe70: 3ffeec00 3ffeec04 0000075c 3ffef5e0
00:57:09.206 -> 3ffffe80: 00000810 00000102 00000000 3ffef500
00:57:09.241 -> 3ffffe90: 0000075c 3ffef57c 3ffef4fc 4021058f
00:57:09.241 -> 3ffffea0: 007a1200 59b425ea 00000000 40210628
00:57:09.241 -> 3ffffeb0: 00000000 00000000 00000001 00000000
00:57:09.241 -> 3ffffec0: 00000000 3ffef57c 00000000 40202b90
00:57:09.241 -> 3ffffed0: 3ffee478 3ffee5c8 00000000 40203cae
00:57:09.241 -> 3ffffee0: 00000013 3ffee4ba 3ffef4ac 00000008
00:57:09.241 -> 3ffffef0: 00000000 3ffee4c0 3ffee4a8 40205a04
00:57:09.275 -> 3fffff00: 00000008 3ffee4c0 3ffee4a8 40201771
00:57:09.275 -> 3fffff10: 40205d30 9701a8c0 3ffe876f 40203405
00:57:09.275 -> 3fffff20: 00000000 00000019 3ffee630 402034cc
00:57:09.275 -> 3fffff30: 3ffee478 00002710 3ffee630 3ffe8750
00:57:09.275 -> 3fffff40: 3ffee478 00000016 3ffee45c 40201c94
00:57:09.275 -> 3fffff50: 0104040c 654b00b4 006e6976 00000000
00:57:09.275 -> 3fffff60: 00000000 00000000 00000000 a8c00000
00:57:09.275 -> 3fffff70: 5c079701 00000000 00000000 00000000
00:57:09.309 -> 3fffff80: 3ffe8755 00000005 0000000c 00000001
00:57:09.309 -> 3fffff90: 40201068 c001a8c0 feefeffe 3ffee75c
00:57:09.309 -> 3fffffa0: 3fffdad0 00000000 3ffee71c 40203d90
00:57:09.309 -> 3fffffb0: feefeffe feefeffe 3ffe8500 40100c1d
00:57:09.309 -> <<<stack<<<
00:57:09.309 ->
00:57:09.309 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
00:57:09.343 ->
00:57:09.343 -> load 0x4010f000, len 3456, room 16
00:57:09.343 -> tail 0
00:57:09.343 -> chksum 0x84
00:57:09.343 -> csum 0x84
00:57:09.343 -> va5432625
00:57:09.343 -> ~ld
00:57:10.395 ->
if anyone from this issue can help me , I want to know what is the problem and how can I fix it?
Socket error on client <>, disconnecting with Paho MQTT-SN Gateway and ESP8266 CLient
I already decode the error and it say like this
Exception 28: LoadProhibited: A load referenced a page mapped with an
attribute that does not permit loads
PC: 0x4000bf80
EXCVADDR: 0x00000000
Decoding stack results
0x4021547a: ip4_output_if_src at core/ipv4/ip4.c line 1590
0x40215fe3: ip_chksum_pseudo at core/inet_chksum.c line 395
0x40210830: udp_sendto_if_src at core/udp.c line 893
0x40100990: malloc(size_t) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 511
0x40210887: udp_sendto_if at core/udp.c line 692
0x40210920: udp_sendto at core/udp.c line 599
0x40202c28: WiFiUDP::endPacket() at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src\WiFiUdp.cpp line 176
0x40204df5: uart_write(uart_t*, char const*, size_t) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\uart.cpp line 509
0x40204df5: uart_write(uart_t*, char const*, size_t) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\uart.cpp line 509
0x402033e4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h line 164
0x402033e4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h line 164
0x402033f0: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h line 165
0x402036c1: Print::write(char const*) at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h line 62
0x40201d34: loop() at C:\Users\ASUS\OneDrive\Documents\Arduino\Test/Test.ino line 133
0x40201074: mqttsn_callback(char*, unsigned char*, unsigned short, bool) at C:\Users\ASUS\OneDrive\Documents\Arduino\Test/Test.ino line 35
0x40204058: loop_wrapper() at C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_main.cpp line 197
Is anyone know what the error mean? Please tell me and Thank You
Thank you for all, but i already fix my problem it seem there is a wrong code in the library and you must change it, right now i'm doing fine doing some publish

Nanopb + Azure MQTT not working on NodeMCU

I have been trying to encode a string using Nanopb library on NodeMCU and publish it using AzureMQTT.
On testing individually, both Nanopb and Azure work just fine. However, Integration of both in one sketch gives me errors.
void loop(){
uint8_t sMsg[512];
gestures data;
char *msg = "aaaaaaaaaaaaaaaaaaaaaaaaa";
strcpy(data.values,msg);
Serial.println("done with strcpy");
pb_ostream_t buffer = pb_ostream_from_buffer(sMsg, sizeof(sMsg));
if (!(pb_encode(&buffer, gestures_fields, &data))) {
Serial.println(F("Encoding failed"));
Serial.println(PB_GET_ERROR(&buffer));
return;
}
else
{
Serial.println("enterd else");
Serial.println((char*)sMsg);
client.run();
if (client.connected()) {
Serial.println("connected");
String payload = "{\"DeviceId\":\"" + String(DEVICE_ID) + "\", \"data\":" + (char*)sMsg + "}";
Serial.println(payload);
client.sendEvent(payload);
Serial.println("Published message!");
}
}
Serial.println("Done with loop");
}
The Serial output is as below:
entered if
done with strcpy
enterd else
aaaaaaaaaaaaaaaaaaaaaaaaa?z[#t/⸮?⸮⸮⸮?⸮⸮⸮?⸮⸮⸮?⸮+⸮?⸮⸮⸮?$⸮?
Done with loop
If observed, the client.connected() is returning false, hence, the message is not being published.
Also, sometimes, at client.run() there's a stack error:
Fatal exception 28(LoadProhibitedCause):
epc1=0x401016dc, epc2=0x00000000, epc3=0x00000000, excvaddr=0x02786a4c,
depc=0x00000000
Exception (28):
epc1=0x401016dc epc2=0x00000000 epc3=0x00000000 excvaddr=0x02786a4c
depc=0x00000000
ctx: sys
sp: 3ffffcf0 end: 3fffffb0 offset: 01a0
>>>stack>>>
3ffffe90: 3fff0010 3fff242c 00000000 40216af4
3ffffea0: 00000000 005e5dbc 40216b4b 3fff242c
3ffffeb0: 3fff2414 ffffffbc 00000000 ffffffff
3ffffec0: 02786a30 00000000 4020c087 00000026
3ffffed0: ffffffff 00000000 3ffeaf61 00000130
3ffffee0: 4020c0da 3fff2d2c 3ffef1cc 3ffef4cc
3ffffef0: 00000000 00000000 4010195b 3fff2d2c
3fffff00: 000000c0 00000000 00000064 3fff2d94
3fffff10: 4020b4e0 3fff2d2c 3fff2d6c 401070bc
3fffff20: 00000009 4021007c 3ffef848 40234b25
3fffff30: 3fff1f34 3fff1f30 005e5dcb 4010610e
3fffff40: 402164be 3ffee878 3ffee878 40234d6d
3fffff50: 401060f4 00000000 00000000 0000001c
3fffff60: 4021fdb4 3ffeffe8 0000001b 4021fdc1
3fffff70: 3ffef858 3fff0010 027982a2 60000600
3fffff80: 4021fe06 3fffdab0 00000000 3fffdcb0
3fffff90: 3fff0020 3fffdab0 00000000 40208993
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<
Decoding the stacktrace gives:
Exception 28: LoadProhibited: A load referenced a page mapped with an
attribute that does not permit loads
Decoding 22 results
0x401016dc: ppEnqueueRxq at ?? line ?
0x401016dc: ppEnqueueRxq at ?? line ?
0x40216af4: ieee80211_parse_wmeparams at ?? line ?
0x40216b4b: ieee80211_parse_wmeparams at ?? line ?
0x4020c087: pp_attach at ?? line ?
0x4020c0da: pp_attach at ?? line ?
0x4010195b: ppCalFrameTimes at ?? line ?
0x4020b4e0: ppCheckTxIdle at ?? line ?
0x401070bc: pvPortMalloc at
C:\Users\Violet\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/heap.c line 13
0x4021007c: ieee80211_getmgtframe at ?? line ?
0x40234b25: udp_input at
/Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/udp.c line 106
(discriminator 1)
0x4010610e: igmp_timer at
/Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/timers.c line
222
0x402164be: sta_input at ?? line ?
0x40234d6d: udp_bind at
/Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/udp.c line 787
0x401060f4: igmp_timer at
/Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/timers.c line 217
0x4021fdb4: system_get_os_print at ?? line ?
0x4021fdc1: system_pp_recycle_rx_pkt at ?? line ?
0x4021fe06: system_restart_hook at ?? line ?
0x40208993: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data&,
std::_Any_data const&, std::_Manager_operation) at
c:\users\violet\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-
elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2/functional
line 1934
It seems you may be overflowing your stack, i.e. running out of space allocated for local variables. When either of the libraries run alone, there is enough space, but when combined it runs out.
A simple way to fix this would be to change this large variable to static allocation:
uint8_t sMsg[512]; // Allocated on stack area
static uint8_t sMsg[512]; // Allocated separately
What static does is that it reserves a section for the variable for the whole duration of the program, instead of trying to fit it in the small dynamic area of the stack.
It is also possible to increase the stack size. On Arduino ESP8266 SDK, this seems to be done by modifying CONT_STACKSIZE in cores/esp8266/cont.h.

pubsubclient can not connect to broker when using JWT authentication

I'm using pubsubclient library.
I used this function to connect to mosquitto broker which using mosquitto-auth-plug with JWT authentication.
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
String red_token = "eyJhbGciOiJIUzUxMiJ9.*****";
String deviceTopic = "outTopic";
//My token length is 205 characters
//client.connect(strDeviceId.c_str(), red_token.c_str(),"pass", deviceTopic.c_str(), 0, false, CMD_OFF_LINE)
bool result = client.connect("newClientIdMCU",token,"pass", deviceTopic.c_str(), 0, 0, "offline");
delay(2000);
if (result) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish(deviceTopic.c_str(), "hello world");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
This exception occurs when client.connect called:
Attempting MQTT connection...
Exception (9):
epc1=0x40202c6d epc2=0x00000000 epc3=0x00000000 excvaddr=0x445a5a51 depc=0x00000000
ctx: cont
sp: 3ffef490 end: 3ffef720 offset: 01a0
>>>stack>>>
3ffef630: 3ffe848e 0000075b 3ffee5b8 402023e1
3ffef640: 3ffe01dc 0afed47d 3ffe8788 0afed47d
3ffef650: 3ffe85ae 3ffef6c0 3ffef6c0 3ffeffec
3ffef660: 3ffe848e 3ffee4fc 3ffee500 40202db0
3ffef670: 514d0400 3f045454 3ffef6c0 402036cd
3ffef680: 3ffe854e 3ffe853f 00000000 4020371e
3ffef690: 3ffe8536 3ffee5d0 3ffee6c0 3ffe848e
3ffef6a0: 00000000 3ffee4fc 3ffee6c0 40201e02
3ffef6b0: 00000000 3ffe8553 00000000 00000000
3ffef6c0: 3ffeffec 0000000f 00000008 3fff056c
3ffef6d0: 000000af 000000a7 3ffee4fc 40203114
3ffef6e0: 3fffdad0 00000000 3ffee4fc 3ffee6ec
3ffef6f0: 3fffdad0 3ffee4fc 3ffee6e4 40201eaa
3ffef700: 3fffdad0 00000000 3ffee6e4 40203834
3ffef710: feefeffe feefeffe 3ffee700 40100718
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,7)
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset
On broker log "New connection...." but Sending CONNACK to clientId (0, 0) can't send.
What could be problem?
I change pubsubclient.h file lib from:
// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
to
// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 256
it works.

OpenCV: free(): invalid next size error when resizing matrix

I need to acquire some points' coordinates (represented by variables xCoord and yCoord) and set to 1 the associated positions in matrix scan_image. It may happen that a point's coordinates are outside matrix's dimensions, so scan_image needs to be resized before setting point's associated position in matrix to 1.
Here's the code:
#include "line_matching/listener.hpp"
#include <opencv2/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/utility.hpp>
using namespace cv;
using namespace std;
int main(int argv, char** argc){
/* start listening */
listener lsr;
lsr.listen(argv, argc);
/* get data that were listened to */
vector<listener::completeInformation> vecCI = lsr.getListeningInfo();
/* create a matrix to host image */
Mat scan_image;
/* fill matrix */
float currentX = 0;
float currentY = 0;
for(int i = 0; i<(int)vecCI.size(); i++)
{
/* get current info */
listener::completeInformation ci = vecCI[i];
float xCoord = ci.position.first;
float yCoord = ci.position.second;
/* matrix is void */
if(scan_image.empty())
{
cout << "case 1" << endl;
/* create a new row */
Mat firstRow = Mat::zeros(yCoord+1, xCoord+1, CV_32FC1);
scan_image.push_back(firstRow);
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
/* update matrix size */
currentX = xCoord;
currentY = yCoord;
}
/* new coordinate is outside current matrix */
else if (xCoord > currentX && yCoord > currentY)
{
cout << "case 2" << endl;
/* add necessary rows */
Mat newRows = Mat::zeros(yCoord-currentY, currentX+1, CV_32FC1);
cout << "Size scan " << scan_image.rows << " " << scan_image.cols << endl;
scan_image.push_back(newRows);
currentY = yCoord;
/* add new cols */
Mat newCols = Mat::zeros(currentY+1, xCoord-currentX, CV_32FC1);
cout << "Size newCols " << newCols.rows << " " << newCols.cols << endl;
hconcat(scan_image, newCols, scan_image);
/* update matrix size */
currentX = xCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
/* coordinate's column is outside matrix */
else if(xCoord > currentX && yCoord < currentY)
{
cout << "case 3" << endl;
/* add necessary cols */
Mat newCols = Mat::zeros(currentY+1, xCoord-currentX, CV_32FC1);
cout << "Size scan " << scan_image.rows << " " << scan_image.cols << endl;
cout << "Size newCols " << newCols.rows << " " << newCols.cols << endl;
Mat newMat;
hconcat(scan_image, newCols, newMat);
cout << "Size newMat " << newMat.rows << " " << newMat.cols << endl;
//scan_image.resize(newMat.rows);
//scan_image.create(newMat.rows, newMat.cols, CV_32FC1);
resize(scan_image, scan_image, newMat.size());
cout << "Size scan dopo" << scan_image.rows << " " << scan_image.cols << endl;
//scan_image = newMat.clone();
cout << "create" << endl;
newMat.copyTo(scan_image);
//newMat.assignTo(scan_image, -1);
cout << "Dopo creazione mat " << scan_image.rows << " " << scan_image.cols << endl;
/* update matrix size */
currentX = xCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
/* coordinate's row is outside matrix */
else if(xCoord < currentX && yCoord > currentY)
{
cout << "case 4" << endl;
/* add necessary rows */
Mat newRows = Mat::zeros(yCoord-currentY, currentX+1, CV_32FC1);
scan_image.push_back(newRows);
/* update matrix size */
currentY = yCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
else
{
cout << "case 5" << endl;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
}
imshow("Scan", scan_image);
waitKey();
}
I tried many options to modify scan_info's dimensions (you'll find them in comments) in case denoted as CASE 3, but everytime I get a bad memory error:
*** glibc detected *** /home/ubisum/fuerte_workspace/line_matching/bin/matching_main: free(): invalid next size (fast): 0x0000000001e81060 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7e846)[0x7feb0e3fe846]
/usr/local/lib/libopencv_core.so.3.0(_ZN2cv8fastFreeEPv+0x9d)[0x7feb0fb24986]
/usr/local/lib/libopencv_core.so.3.0(+0x21cbb0)[0x7feb0fb26bb0]
/usr/local/lib/libopencv_core.so.3.0(_ZNK2cv12MatAllocator5unmapEPNS_8UMatDataE+0x43)[0x7feb0fb25eaf]
/usr/local/lib/libopencv_core.so.3.0(_ZN2cv3Mat10deallocateEv+0x71)[0x7feb0fb27c3b]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main(_ZN2cv3MatD1Ev+0x75)[0x40de15]
/usr/local/lib/libopencv_imgproc.so.3.0(_ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi+0x16da)[0x7feb0efd80dc]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main(main+0x1b19)[0x40d389]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7feb0e3a176d]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main[0x40dce1]
======= Memory map: ========
00400000-0041f000 r-xp 00000000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
0061e000-0061f000 r--p 0001e000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
0061f000-00620000 rw-p 0001f000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
01e43000-030ec000 rw-p 00000000 00:00 0 [heap]
7feae470a000-7feae490a000 rw-p 00000000 00:00 0
7feae490a000-7feae4919000 r-xp 00000000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4919000-7feae4b19000 ---p 0000f000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b19000-7feae4b1a000 r--p 0000f000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b1a000-7feae4b1b000 rw-p 00010000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b1b000-7feae4b2c000 rw-p 00000000 00:00 0
7feae4b2c000-7feae4b6c000 rw-s 00024000 00:05 13777 /dev/ati/card0
7feae4b6c000-7feae526c000 rw-s 00006000 00:05 13777 /dev/ati/card0
7feae526c000-7feae53ec000 rw-p 00000000 00:00 0
7feae53ec000-7feae5486000 r-xp 00000000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae5486000-7feae5586000 ---p 0009a000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae5586000-7feae55ae000 rwxp 0009a000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae55ae000-7feae55cb000 rwxp 00000000 00:00 0
7feae55cb000-7feae7a13000 r-xp 00000000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7a13000-7feae7c13000 ---p 02448000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7c13000-7feae7ee0000 rw-p 02448000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7ee0000-7feae8000000 rw-p 00000000 00:00 0
7feae8000000-7feae8021000 rw-p 00000000 00:00 0
7feae8021000-7feaec000000 ---p 00000000 00:00 0
7feaec000000-7feaec021000 rw-p 00000000 00:00 0
7feaec021000-7feaf0000000 ---p 00000000 00:00 0
7feaf0000000-7feaf0021000 rw-p 00000000 00:00 0
7feaf0021000-7feaf4000000 ---p 00000000 00:00 0
7feaf4000000-7feaf4021000 rw-p 00000000 00:00 0
7feaf4021000-7feaf8000000 ---p 00000000 00:00 0
7feaf8000000-7feaf8021000 rw-p 00000000 00:00 0
7feaf8021000-7feafc000000 ---p 00000000 00:00 0
7feafc011000-7feafc0d1000 rw-p 00000000 00:00 0
7feafc0d1000-7feafc171000 r-xp 00000000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc171000-7feafc271000 ---p 000a0000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc271000-7feafc274000 rw-p 000a0000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc274000-7feafc284000 rw-p 00000000 00:00 0
7feafc284000-7feafc28a000 r-xp 00000000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc28a000-7feafc489000 ---p 00006000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc489000-7feafc48a000 rw-p 00005000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc48a000-7feafc48b000 ---p 00000000 00:00 0
7feafc48b000-7feafcc8b000 rw-p 00000000 00:00 0 [stack:13933]
7feafcc8b000-7feafcc8c000 ---p 00000000 00:00 0
7feafcc8c000-7feafd48c000 rw-p 00000000 00:00 0
7feafd48c000-7feafd48d000 ---p 00000000 00:00 0
7feafd48d000-7feafdc8d000 rw-p 00000000 00:00 0
7feafdc8d000-7feafdc8e000 ---p 00000000 00:00 0
7feafdc8e000-7feafe48e000 rw-p 00000000 00:00 0
7feafe48e000-7feafe48f000 ---p 00000000 00:00 0
7feafe48f000-7feafec8f000 rw-p 00000000 00:00 0
7feafec8f000-7feafec9b000 r-xp 00000000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafec9b000-7feafee9a000 ---p 0000c000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9a000-7feafee9b000 r--p 0000b000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9b000-7feafee9c000 rw-p 0000c000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9c000-7feaff57f000 r--p 00000000 08:06 2759450 /usr/lib/locale/locale-archive
7feaff57f000-7feaff585000 r-xp 00000000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff585000-7feaff784000 ---p 00006000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff784000-7feaff785000 r--p 00005000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff785000-7feaff786000 rw-p 00006000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff786000-7feaff7a7000 r-xp 00000000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff7a7000-7feaff9a6000 ---p 00021000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a6000-7feaff9a8000 r--p 00020000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a8000-7feaff9a9000 rw-p 00022000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a9000-7feaff9fb000 rw-p 00000000 00:00 0
7feaff9fb000-7feaffa0b000 r-xp 00000000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0
7feaffa0b000-7feaffc0b000 ---p 00010000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0
7feaffc0b000-7feaffc0c000 r--p 00010000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0Aborted (core dumped)
Any suggestion?
thanks

Resources