Search code examples
mongodbarduinoesp8266nodemcu

is it possible to send data to a mongodb cluster with esp8266?


I am making a Car overspeeding detector, so, for that, I have to send data to a database. I am using MySQL At the moment but I want a better database for this. So, I found MongoDB, But dunno that even is it possible to send data to a MongoDB cluster with esp8266?


Solution

  • Use HTTP(S) as a transport and server side API backend which will be responsible for working with a database.

    There are many reasons why it is not feasible to make code for resource constrained devices which could communicate with databases directly.

    • [resources] they have small amount of RAM and ROM - adding DB code to run alongside application code quite often do not fit available footprint.
    • [security] it is not wise to expose DB port into the wild from security point of view
    • [security] some databases support encryption of communication channel but it is not used in a majority of cases. It can be tempting to use clear-text communication to decrease footprint but gives third-party access to the traffic.
    • [security] direct DB access implies sharing single set of credentials accross army of devices and SPI Flash can be desoldered and password can be easily extracted from desoldered SPI Flash (I doubt that ESP8266 has built-in support for encryption of firmware)
    • [security] giving DB credentials to anyone usually gives them acces to things you did not plan initially - it is possible to configure proper permissions for DB users to limit access to extra things but quite often developers do not have enough time or experience to tighten things properly.
    • [???] etc

    There are multiple HTTP API micro-frameworks which allow you to build HTTP API for server side - it is Layer which allows you to hide DB backend from clients. Good frameworks even have DBAL (db abstraction layer) which allows you to write code and db structure in an DB agnostic way - so you can switch from one db type to another with as little effort as changing single line in a config file.