I am thinking about posting data from my enviro weather system to a document database, probably Mongodb. Does anyone know if this is possible? There is the PyMongo library for “full-grown” python, does anyone think that it could be ‘microfied’?
Hey @markV ,
Have you made any progress in using MongoDB?
I was thinking that it is only a mattero f using the python driver for Mongo and pipe the data captured by the Enviro+ library to it. But I may be wrong and seeing it too simple. This is what I need to do. TIA!
AFAIK, Mongo-DB does not natively support a REST-API, but there are 3rd-party additions you have to install on your server. Once active, you can use REST from MicroPython. You will probably have to code the various http(s) requests yourself.
The native (binary) communication with Mongo-DB is probably difficult to implement directly in MicroPython.
Thanks @bablokb for chiming in. Would you know any DB I could use that is compatible with MicroPython? In other words one that I can use the driver to pump the data capture out to the internet. TIA!
You can use various databases, e.g. mysql, mariadb and others. Just search the net for the database name of your choice together with the terms “rest api”. For mysql for example you will find many introductions and tutorials.
And to be honest, I don’t think Mongo-DB would have been a good choice anyhow. Saving numeric data from sensors in a document database is a somewhat strange approach.
But be warned: installing and running a database system needs some experience. The same holds true for database programming, e.g. table creation and maintainance and so on. But if you choose something standard, you will find many guides and tutorials that help.
The other option would be to use something like Adafruit-IO, i.e. a service that is operated by someone else.
Thanks for the tips @bablokb !
I was considering MongoDB just because it offers a time-series option. Also, I am trying to stay away of installing and manageing the DB in my raspberry but I would like to pipe the data to a Cloud DB over the Internet(that is second point I was considering MongoDB).
if that becomes cumbersome, I may considering to store in a regular file.
Cheers!
There is actually a Micropython library for SQLite called μSQLite. Although SQLite has its own quirks, it has considerably less administrative overhead than conventional relational database systems.
Interesting, thanks for the link. In this context it is not useful, since SQLite is an embedded database, but @Luca wants to send data to a remote location. Nevertheless, good to know that this DB is also available for MP (I use SQLite for many things).
I must admit that it was a casual suggestion, although if one of the alternatives is just using a file, it could still be preferable. Of course, there’s nothing wrong with using a file, either local or remote.
If I were wanting to do something similar with some potential for other applications, I would consider implementing a proxy that supports at least some of the Python DB-API. The application would use that API, although it would presumably only be doing insert or update operations, and then the library would serialise the requests and send them to its counterpart on the server, which would interact with a local database server or SQLite.
Although this might be a bit more effort than using a REST API, it could potentially avoid some of the overhead involved with HTTP transactions (if that were a consideration), as well as the deliberation that tends to be required when formulating how REST endpoints should behave.