We needed a simple and efficient way to store configuration settings and values between projects, using a non-volatile Ferromagnetic Random Access Memory (FRAM).
What is Embedis?Embedis is a very small, in-memory, data structure store for key/value pairs; and why it is also known as a "keystore server". Embedis can be used as a database, cache, and message broker, with it's publish and subscribe mechanisms. Embedis uses a syntax similar to the popular "Redis" program, which has API/bindings available for C/C++, Python, Ruby, TCL, etc.
In this example the Embedis command interpreter is connected to the Serial Monitor (i.e. Serial.print), however we have examples that show it running several simultaneous connections at once, including Telnet, WWW, MQTT, and others.
The Embedis database is persistent, and can be used across multiple projects to configure your program settings for the specific hardware and network configuration that you are using. The Embedis database supports EEPROM storage by default, but can also add other memory devices easily, as we show with this example, by adding an external SPI FRAM such as the MB85RS64 (8K bytes), MB85RS256 (32K bytes) or the FM25V10 (128K bytes). These devices come in both SPI and I2C interface "flavors", if you are looking for the I2C version, we have an I2C_FRAM Project covering that interface.
Now, you don't need to recompile your program and reflash your device in order to change your device and project settings anymore. Project settings can be changed "on-the-fly" with just a serial or wireless interface! (some settings changes however, will require a restart/reboot to take effect.)
Installing EmbedisTo Install Embedis in the Arduino IDE, please see the Detailed Install Directions. Embedis is installed using the Arduino Library Manager, from the top menu bar:
Sketch -> Include Library -> Manage Libraries -> Embedis
You will also need the ESP8266 tools and ESP8266 sketch data download utility installed with Arduino IDE 1.6.7 or later. For more information, please follow the board manager install directions at ESP8266/Arduino.
Installing the Adafruit SPI FRAM LibraryThe Adafruit FRAM SPI library is installed using the Arduino Library Manager, from the top menu bar:
Sketch -> Include Library -> Manage Libraries -> Adafruit FRAM SPI
After installing the Embedis library in the Arduino IDE, the Embedis examples will be available under the menu as:
File -> Examples -> Embedis -> esp8266 -> Embedis_SPI_FRAM
Make sure to select your specific ESP8266 board model under the Board Manager, and set the "port" to the correct COM: port for your board. Then just press the "Download" button to compile and download your project.
Using the Example Embedis_SPI_FRAM ProjectOnce you have flashed your board using the Upload command, open the Arduino Serial Monitor and you can begin giving commands to Embedis. Type "commands" into the Arduino Serial Monitor, and get a list of commands:
Now this is where it gets really interesting, you have two (2) different memories available to you to store your data in, which in Embedis are referred to as "DICTIONARIES" and these are named EEPROM and SPI_FRAM.
By using the Embedis "select" command, you can select which memory you are going to use to read and write, for example when you type "select EEPROM", then Embedis will return the number of bytes of free space in the EEPROM dictionary. The ESP8266 normally gives you 4096 bytes of "emulated" EEPROM, and two (2) of those bytes are used by Embedis for a pointer, so you have 4094 bytes to work with.
Similarly, when you "select SPI_FRAM", Embedis will select the SPI_FRAM and return the number of free bytes in that Embedis Keystore.
Now you can start to add data to your Embedis Keystore using the "set" and "get" commands. Since the last "Dictionary" that was selected was the SPI_FRAM, that is where our data will be written, for example:
So we created a key named "IPADDR" and set it to "192.168.1.127". Make sure to use quotes around any string with spaces or special characters. Now let's use the "get IPADDR" command to retrieve the data from the Embedis Keystore.
There are many advanced features of Embedis, including the ability to publish and subscribe to changes in keys and the logging system. We'll cover those in upcoming projects here at the thingSoC platform!
Happy Hacking!
Comments