Unable to use BLE and MQTT (SSL) without memory error

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
JaiCee
Posts: 2
Joined: Wed Apr 07, 2021 8:25 pm

Unable to use BLE and MQTT (SSL) without memory error

Post by JaiCee » Thu Apr 08, 2021 2:11 pm

I am trying to connect to a bluetooth temperature sensor and send the results over MQTT but keep getting out of memory errors despite there being plenty. I initially had created a more complicated program using uasyncio and the uasyncio MQTT by Peter Hinch and a uasyncio BLE library I wrote myself.

Thinking the problem was to do with uasyncio I rewrote a test example based off the bluetooth examples and umqtt.simple instead but get the same error. Here is the gist of my example code.

When connecting to MQTT the problem occurs when trying to create the ussl socket. Does anyone have any suggestions or has tried this before? I was considering getting an M5Stack Core2 with extra SPIRAM anyway but given that I have 90KB of RAM free before attempting the connection I'm not sure this will help.

Code: Select all

self.sock = ussl.wrap_socket(self.sock, **self.ssl_params)
Here is the error I get if I connect to MQTT then bluetooth.

Code: Select all

GC: total: 111168, used: 19776, free: 91392
 No. of 1-blocks: 276, 2-blocks: 48, max blk sz: 41, max free sz: 4883
Connecting to MQTT
MQTT Connected
stack: 1056 out of 15360
GC: total: 111168, used: 20736, free: 90432
 No. of 1-blocks: 188, 2-blocks: 41, max blk sz: 109, max free sz: 4883
assertion "rc == 0" failed: file "/home/james/Personal/Projects/esp-idf/components/bt/host/nimble/nimble/porting/nimble/src/os_msys_init.c", line 56, function: os_msys_init_once
abort() was called at PC 0x401b178f on core 0

ELF file SHA256: 4b36177f707e49f2

Backtrace: 0x4009020c:0x3ffcd220 0x400905f5:0x3ffcd240 0x401b178f:0x3ffcd260 0x40116581:0x3ffcd290 0x4010def7:0x3ffcd2b0 0x400eecd1:0x3ffcd2d0 0x400e76c9:0x3ffcd2f0 0x400dcf21:0x3ffcd310 0x400e30c9:0x3ffcd340 0x400e31f6:0x3ffcd360 0x400e5791:0x3ffcd380 0x400dcfa0:0x3ffcd420 0x400e30c9:0x3ffcd480 0x400e31f6:0x3ffcd4a0 0x400e1b0e:0x3ffcd4c0 0x400e100d:0x3ffcd510 0x400e30c9:0x3ffcd530 0x400e56e9:0x3ffcd550 0x400dcfa0:0x3ffcd5f0 0x400e30c9:0x3ffcd660 0x400e31f6:0x3ffcd680 0x400e5791:0x3ffcd6a0 0x400dcfa0:0x3ffcd740 0x400e30c9:0x3ffcd7a0 0x400e31f6:0x3ffcd7c0 0x400e5791:0x3ffcd7e0 0x400dcfa0:0x3ffcd880 0x400e30c9:0x3ffcd8f0 0x400e30f2:0x3ffcd910 0x400f5147:0x3ffcd930 0x400f54c1:0x3ffcd9c0 0x400f5525:0x3ffcd9e0 0x400d6ff7:0x3ffcda00
And if I connect to bluetooth first then MQTT

Code: Select all

Found sensor: 0 b'<a\x05\x13L\x0e' mpy-temp
Connected
stack: 1056 out of 15360
GC: total: 111168, used: 20944, free: 90224
 No. of 1-blocks: 305, 2-blocks: 55, max blk sz: 41, max free sz: 4885
Connecting to MQTT
Closing
stack: 1040 out of 15360
GC: total: 111168, used: 26832, free: 84336
 No. of 1-blocks: 323, 2-blocks: 61, max blk sz: 109, max free sz: 4885
Traceback (most recent call last):
  File "main.py", line 92, in <module>
  File "main.py", line 32, in run
  File "main.py", line 84, in connect_mqtt
  File "/lib/umqtt/simple.py", line 61, in connect
OSError: [Errno 12] ENOMEM

Post Reply