pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

EzData 1.0 - Arduino

Function Description

EzData is an IoT cloud data storage service provided by M5Stack. Different devices can insert or extract data from a storage queue via a unique Token to achieve data sharing.

Concept Introduction

  • Token: The unique field for accessing and reading/writing data

  • topic: The key for storing data in a queue form under the Token, allowing storage of topic + list topic quantity ≤ 100

    • Each topic allows inserting ≤ 1000 pieces of data
    • Use the SAVE API to insert new data into the queue, using a stack method (first in last out), each time inserting data at the head of the queue.
    • Use the GET API to retrieve the data located at the head of the queue. The original data is deleted from the sequence.
  • list topic:

    • The key for storing data in a list form under the Token, allowing storage of topic + list topic quantity ≤ 100
    • Use the SAVE API to insert new data into the list, appending each new data to the end of the list.
    • Use the GET API to read list data of a specified index or range. Returned data is in list form.

Get Token

Open the UiFlow Web IDE Version 1.0, click the EzData option in the Blockly list to view the Token of the current browser. To ensure the uniqueness of the Token, please use a fixed browser and do not enable incognito mode.

EzData API

Notes
1. All the following operations depend on the unique Token, which is fixed in the same browser environment (do not use incognito mode). Please copy the Token before use.
2. If no data operation is performed within half a year, the data queue corresponding to the Token will be cleared.
3. Data will be sorted in descending order by insertion time (the last inserted data is at the head of the list), and data will be stored cumulatively.

Save data val to the head of the specified topic queue

setData(const char *token, const char *topic, int val)

Get a piece of data from the head of the specified topic queue and store it in result

getData(const char *token, const char *topic, int& result)

Save data to the head of the specified data list

addToList(const char *token, const char *list, int val)

Get a set of data from the specified data list

getData(const char *token, const char *list, int *Array, int offset, int count)

  • The advantage of using a list for storage is that it supports specifying data index offsets and can retrieve multiple data at once. The return value is a list.
  • list: List name
  • offset: Offset relative to the head of the data list
  • count: The number of data to read

Delete topic or list and clear the queue data

removeData(const char *token, const char *field)

Github

Example Program

This example program uses an M5Core device. Before compiling the program, you need to install the related dependency libraries M5Stack and M5_EzData, and fill in the Token and Wi-Fi information in the code.


#include "M5Stack.h"
#include "M5_EzData.h"

// Configure the name and password of the connected Wi-Fi and your token.
const char* ssid = "Explore-F";
const char* password = "xingchentansuo123";
const char* token = "";

void setup() {
  M5.begin();   //Initialize M5Stack
  M5.Power.begin();
  if(setupWifi(ssid,password)){ //Connect to Wi-Fi
    M5.Lcd.printf("Success connecting to %s\n",ssid);
  }else{
    M5.Lcd.printf("Connecting to %s failed\n",ssid);
  }
}

void loop() {
   //Save the data 20 to the top of the testData topic queue.
  if(setData(token,"testData",20)){
    M5.Lcd.printf("Success sending data to the topic\n");
  }else{
    M5.Lcd.print("Fail to save data\n");
  }
  delay(5000);

  //Save 3 data in sequence to the first place of testList.
  for(int i=0;i<3;i++){
    if(addToList(token,"testList",i)){
      M5.Lcd.printf("Success sending %d to the list\n",i);
    }else{
      M5.Lcd.print("Fail to save data\n");
    }
    delay(100);
  }
  delay(5000);

  //Get a piece of data from a topic and store the value in result.
  int result=0;
  if(getData(token,"testData",result)){
    M5.Lcd.printf("Success get data %d\n",result);
  }else{
    M5.Lcd.print("Fail to get data\n");
  }
  delay(5000);

  //Get a set of data from a list and store the values in the Array array
  int Array[3]={};
  if(getData(token,"testList",Array,0,3)){
    M5.Lcd.print("Success get list\n");
    for(int i=0;i<3;i++){
      M5.Lcd.printf("Array[%d]=%d,",i,Array[i]);
    }
    M5.Lcd.println("");
  }else{
    M5.Lcd.println("Fail to get data");
  }
  delay(5000);

  //Remove data
  if(removeData(token,"testData"))
    M5.Lcd.printf("Success remove data\n");
  else
    M5.Lcd.println("Fail to remove data");

  if(removeData(token,"testList"))
    M5.Lcd.printf("Success remove data from the list\n");
  else
    M5.Lcd.println("Fail to remove data");
  delay(5000);
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setCursor(0,0);
}

Dashboard

If you need to view or share data, you can visit the EzData Dashboard page.

On This Page