1
votes

I want to save data from an ESP32 in a network database. Therefore I need the module MySQLdb in Micropython on the ESP32. How can I install it there?

3

3 Answers

1
votes

Have you tried something like https://github.com/dvrhax/uPyMySQL ? Looks like it needs to be compiled into firmware to work on ESP8266. Maybe (have not tested by myself) would be enough for ESP32 to cross-compile with mpy-cross. Share your experiences if you try.

Other way around- write API to save data in PHP or whatever web language, and call page with GET/POST parameters. I've used this method with my hosting, created PHP script that handle GET request (http://example.com/addData.php?temp=23.4&hum=57), extract data from it (temperature and humidity) and write into database together with timestamp. On webpage I have another script that parse data from database and makes beautiful charts.

EDIT: I've been playing around recently with uPyMySQL on ESP-32 generic (No PSRAM) an can share my findings. Library does not work for me at of the box- I had to make multiple edits to make it work with my own-compiled LVGL Micropython firmware. I had to cross-compile few files to mpy format, because my microcontroller goes out of memory when loading library.

When I finally made to connect to database- it really works. Anyway, Lib has some flaws in column types (int, varchar, datetime) handling as some logic is not ported to Micropython, but hope it fixable. Lib has debug mode witch is nice if you wish to understand whats going on in background.

But do not expect to query big sets of data. I've been playing around with table with columns DateTime, Temp, Humidity, CO2. When selecting 100 records limit controller goes out of memory, for about 60-70 record it works.

Inserting works as it should, only you have to execute commit command at the end.

1
votes

running just about any database client from an ESP32 to a hosted database somewhere would be a challenge (in processing power, security and maintaining state)

I would suggest using the ESP32 to send data to a mqtt broker, and then have something else, (the server running the database, a serverless function , etc etc ) subscribe to that topic , and write any changes to the database.

0
votes

If your server has php in it then u can send your data to php and write a code to store that resived data in MySQL database. Try it and let me know.