Error while posting something from Esp32(Micropython) to firebase

Viewed 471

I'm trying to use firebase with Micropython. It doesn't matter how many times I do this print(firebase.get(URL)). If I use firebase.put(URL, datas) or firebase.patch(URL, datas) then it successfully posts that data, but if I try to read the data print(firebase.get(URL)) then this error pops up.

Firebase library: https://github.com/vishal-android-freak/firebase-micropython-esp32

Code:

import network
import ufirebase as firebase
from time import sleep

URL = 'https://xxxxxxxxxxxxxxxx.firebaseio.com/'

wlan = network.WLAN(network.STA_IF)
if not wlan.active() or not wlan.isconnected():
    wlan.active(True)
    print('connecting to: xxxx')
    wlan.connect('xxxx', 'xxxxxxxxx')
    while not wlan.isconnected():
        pass
print('network config:', wlan.ifconfig())
datas = {'Shape': {'hos': 'fse', 'xxe': 'ter'}, 'Wps': 'Wps'}

firebase.put(URL, datas)
sleep(5)
print(firebase.get(URL))

Error:

Traceback (most recent call last):
  File "main.py", line 21, in <module>
  File "ufirebase.py", line 124, in get
  File "urequests.py", line 116, in get
  File "urequests.py", line 62, in request
OSError: [Errno 12] ENOMEM
MicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32
Type "help()" for more information.
2 Answers

got it problem is with urequests library, if you can switchback to usocket and close the socket before timeout then works fine. For urequests you need to have a board with spiram. For non-spiram based borads here is a good firebase library based on sockets micropython-firebase-realtime-database

You're calling firebase.get(URL) and getting an out of memory error.

This call returns the entire contents of the database. Apparently this is more than the amount of RAM available to MicroPython (which isn't a lot). ENOMEM means "no memory" - Python has run out of memory.

You need to change the call to request just what you're trying to fetch. In this case you might try

print(firebase.get(URL + 'Shape'))
print(firebase.get(URL + 'Was'))

You can refer to the library's documentation to see how to better use the get() method.

Related