Open savagerex opened 1 year ago
This forum is for issues with the code included here. Issues with 3rd party libraries should be addressed on their site. General questions should be asked at https://esp32.com
before we discuss this issue. (https://github.com/espressif/arduino-esp32/issues/8423#issuecomment-1642231644)
you mention that ESP32 WROVER only have 4MB PSRAM.
but i only declare 891000.
why memory not enough????
I also mentioned that there is no reason to have the buffer size larger than your maximum mqtt message size.
@savagerex - I have analyzed the issue with the MQTT Library from https://github.com/256dpi/arduino-mqtt
I concluded that this issue is due to the fact that the MQTT Library uses malloc()
in its class constructor MQTTClient::MQTTClient(int bufSize)
and it happens when the PSRAM has not been already initialized (before Arduino app_main()
has even been executed).
Therefore the malloc()
always fails if the size of the buffer doesn't fit in the ESP32 RAM (not PSRAM).
This is an issue of the Library and it must be fixed within the Library code.
It is not related to ESP32 Arduino code.
Check the related code:
https://github.com/256dpi/arduino-mqtt/blob/master/src/MQTTClient.h#L99-L100
explicit MQTTClient(int bufSize = 128) : MQTTClient(bufSize, bufSize) {}
MQTTClient(int readSize, int writeBufSize);
https://github.com/256dpi/arduino-mqtt/blob/master/src/MQTTClient.cpp#L161-L167
MQTTClient::MQTTClient(int readBufSize, int writeBufSize) {
// allocate buffers
this->readBufSize = (size_t)readBufSize;
this->writeBufSize = (size_t)writeBufSize;
this->readBuf = (uint8_t *)malloc((size_t)readBufSize + 1);
this->writeBuf = (uint8_t *)malloc((size_t)writeBufSize);
}
My suggestion would be for you to fix it manually and create your own MQTT Library version based on the original code.
@SuGlider
but this lib is work in esp32 s3.
if i declare
WiFiClient net; MQTTClient client(1782000);
@SuGlider
but this lib is work in esp32 s3.
if i declare
WiFiClient net; MQTTClient client(1782000);
Please demonstrate that it works with the ESP32-S3. Do you have any evidence of it?
I have one evidence that it also doesn't work with the ESP32-S3:
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4
[ 151][I][MQTTClient.cpp:164] MQTTClient(): MQTT buffer size is: [891100]
[ 151][E][MQTTClient.cpp:167] MQTTClient(): ====> MQTT READ BUF is NULL !!!
[ 153][E][MQTTClient.cpp:170] MQTTClient(): ====> MQTT WRITE BUF is NULL !!!
[ 397][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
[ 439][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 0 - WIFI_READY
[ 473][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 2 - STA_START
checking wifi....[ 567][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[ 588][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 589][D][WiFiGeneric.cpp:1098] _eventCallback(): STA IP: 192.168.1.104, MASK: 255.255.255.0, GW: 192.168.1.1
connecting...Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x42074e5f PS : 0x00060d30 A0 : 0x8200690c A1 : 0x3fcebe60
A2 : 0xffffffff A3 : 0x000d98dc A4 : 0x00000010 A5 : 0x00000004
A6 : 0x00000001 A7 : 0x00000fff A8 : 0x3fcebea0 A9 : 0x00000000
A10 : 0x00000691 A11 : 0x00000000 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x00000008 A15 : 0x3fc9ae44 SAR : 0x0000001c EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x40056f5c LEND : 0x40056f72 LCOUNT : 0x00000000
Backtrace: 0x42074e5c:0x3fcebe60 0x42006909:0x3fcebe80 0x420066f4:0x3fcebed0 0x42006411:0x3fcebf20 0x42002c4d:0x3fcebf90 0x42002cc1:0x3fcebfb0 0x42007d32:0x3fcebfe0
@SuGlider
As below is ESP32 S3 .
If it provides any help, you might checkout H4AsyncMQTT.
@savagerex - I've confirmed your point with the S3. I used a OPI PSRAM ESP32-S3 and it has worked as you described. But when using a QSPI PSRAM ESP32-S3 it crashes, exactly like the ESP32-WROVER.
It seems that there is a difference in the bootloader when PSRAM is Octal SPI. It may have been configured to initialize the PSRAM in boot time.
Other than that, the explanation from https://github.com/espressif/arduino-esp32/issues/8529#issuecomment-1681423588 continues valid.
Hello, come up to this during issue clean up. Can you please @savagerex retest this against 3.1.0-RC1? If the issue is still valid? Thanks a lot!
Board
ESP32-WROVER-E
Device Description
Sensor - iis3dwb external flash
Hardware Configuration
NONE
Version
v2.0.9
IDE Name
Arduino
Operating System
Windows 11
Flash frequency
80M
PSRAM enabled
yes
Upload speed
921600
Description
I use Mqtt library.( https://github.com/256dpi/arduino-mqtt ).
but this libray have different result between ESP32 WROVER and ESP32 S3.
if i declare in ESP32 WROVER as below.
WiFiClient net; MQTTClient client(891100);
it use "PSRAM" about 891100.
ESP32 WROVER always reset.
if i reduce
WiFiClient net; MQTTClient client(1000);
then ESP32 WROVER is work.
if i declare in ESP32 S3
WiFiClient net; MQTTClient client(1782000);
it use "PSRAM" about 1782000.
it is work.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide