Skip to content

Repository files navigation

arduino-library-badgeBuild Status

Arduino-CloudStorage

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:

How To Install

  1. Just go to your local folder for Arduino projects (usually User/Documents/Arduino/).
  2. Step into the folder called libraries
  3. Clone the repository in the libraries folder and restart the Arduino IDE.
  4. 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

Features & Syntax

  1. Store key/value pairs to the server
storage.put<int>("age", 20);
storage.put<float>("temperature", 25.8);
storage.put<bool>("switch_state", false);
  1. 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");
  1. Add values to an array in the server
storage.add<float>("sensor_values", getCurrentSensorValue());
storage.add<String>("startup_dates", "17.12.2018");
  1. 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;
}
  1. Get an aggregate of a collection
int average = storage.avg("samples");
int min = storage.min<int>("samples");
int max = storage.max<int>("samples");
  1. 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");
  1. 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();
}

Requirements

  • This library uses the ArduinoJson library as a depedency. arduino-library-badge
  • This library uses the ArduinoWebsockets library. arduino-library-badge
  • You must have an instance of CloudStorage Server running.
  • You must have valid username and password (on your CloudStorage Server)

Public Experiment 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)

Known Issues

  • Bad error reporting and handling
  • No explanation on setting up a server.

Examples

See all the examples HERE.

Increment Value in Server

This example sketch:

  1. Connects to a WiFi network
  2. Initializes a value in the server
  3. 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);
}

Log Sensor Values

This example sketch:

  1. Connects to a WiFi network
  2. 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!

About

Arduino Arduino library for the CloudStorage server project. The library provides easy access to server-stored values and operations.

Topics

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages