Arduino/ESP8266 library that allows you to easly store and retreive data from a remote (cloud) storage in a key/value fashion. CloudStorage server can be found here.
This project allows for storage and retrival of numbers (floats, ints), strings and even arrays and complex objects. The project lets you listen for changes in real time so you can keep your IOT devices connected and synced.
Open an issue or contact me if you need any help!
Quick Jump:
- Just go to your local folder for Arduino projects (usually
User/Documents/Arduino/). - Step into the folder called
libraries - Clone the repository in the
librariesfolder and restart the Arduino IDE. - Should be good to go! Try to load the example sketches from the menu, "File" -> Examples" -> "ArduinoCloudStorage"
For more information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries
- Store key/value pairs to the server
storage.put<int>("age", 20);
storage.put<float>("temperature", 25.8);
storage.put<bool>("switch_state", false);- Fetch key/value pairs from the server
int age = storage.get<int>("age");
float temperature = storage.get<float>("temperature");
bool isSwitchOn = storage.get<bool>("switch_state");- Add values to an array in the server
storage.add<float>("sensor_values", getCurrentSensorValue());
storage.add<String>("startup_dates", "17.12.2018");- Pop values from an array in the server
String color = storage.pop<String>("colors_to_show", PopFrom_End);
float temp = storage.pop<float>("tempertures", PopFrom_Start);// More advanced example of pop. In the previous example the returned value is // implicitly casted into the required return type (String, float etc..)while(true) {
auto popResult = storage.pop<String>("lines_to_print", PopFrom_Start);
if(popResult.isOK == false) break;
proccessLine(popResult.value);
if(popResult.hasNext == false) break;
}- Get an aggregate of a collection
int average = storage.avg("samples");
int min = storage.min<int>("samples");
int max = storage.max<int>("samples");- Atomic operations
int newValue = storage.inc("some_key");
int newValue = storage.dec("some_key");
// Will only set "some_key" to 3.2 if it is less than what already in some_key and returns the new valuefloat newMin = storage.put_min<float>("some_key", 3.2f);
// Will only set "some_key" to 1234.5 if it is more than what already in some_key and returns the new valuefloat newMax = storage.put_max<float>("some_key", 1234.5f);
// Puts a timestamp in the key "datetime_key" and returns the new value
String currentDatetime = storage.datetime("datetime_key");
- Listen for changes (beta)
// listen for changes on key "temperture"
storage.listen("temperture");
// Do something when a key changes
storage.onChange([&](String key){
if(key == "temperture") {
// Do Something
}
});
// Process eventswhile(true) {
storage.loop();
}- This library uses the
ArduinoJsonlibrary as a depedency. - This library uses the
ArduinoWebsocketslibrary. - You must have an instance of CloudStorage Server running.
- You must have valid
usernameandpassword(on your CloudStorage Server)
As of 18.12.2018, you could use my public instance as server (As BASE_URL): http://cloudstorage.gilmaimon.xyz:5050.
You can Click Here to register a new user on that server.
11.01.2019 Update: Server moved to port 5050.
NOTE:
- This server will not stay alive forever.
- IP and/or Port might change, take that into considiration.
- Please, don't abuse bandwith/storage (IP will be blocked and/or server will be taken down)
- Bad error reporting and handling
- No explanation on setting up a server.
See all the examples HERE.
This example sketch:
- Connects to a WiFi network
- Initializes a value in the server
- Increment the value in
loop()
CloudStorage storage("BASE_URL", "USERNAME", "PASSWORD");
voidsetup() {
Serial.begin(115200);
// Try to connect to a wifi networkWifiConnection::tryConnect("WIFI_SSID", "WIFI_PASSWORD"); // Give the ESP some time to connectdelay(3 * 1000);
// initialize value to 0if (WifiConnection::isConnected()) {
storage.put<int>("count", 0);
}
}
voidloop() {
Serial.println("Checking Connection");
if (WifiConnection::isConnected()) {
// Get the current valueint val = storage.get<int>("count");
// Log
Serial.print("Got value: ");
Serial.print(val);
Serial.println(" . Updating...");
// Increment by 1 and store in the server
storage.put<int>("count", val + 1);
} else {
Serial.println("No Connection");
}
delay(1000);
}This example sketch:
- Connects to a WiFi network
- Then, in
loop(): reads and logs sensor value to the server
CloudStorage storage("BASE_URL", "USERNAME", "PASSWORD");
voidsetup() {
Serial.begin(115200);
// Try to connect to a wifi networkWifiConnection::tryConnect("WIFI_SSID", "WIFI_PASSWORD"); // Give the ESP some time to connectdelay(3 * 1000);
}
voidloop() {
Serial.println("Checking Connection");
if (WifiConnection::isConnected()) {
// get some sensor value to logfloat value = getSomeSensorValue();
// add that value to array in the server
storage.add("sensor_values", value);
} else {
Serial.println("No Connection");
}
delay(5 * 1000);
}Open an issue or contact me if you need any help!