pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

EzData 1.0 - Arduino

1. Function Description

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

1.1 Introduction

  • Token: The unique field for accessing and reading/writing data.
  • Topic: The key for storing queue-formatted data under a Token. The number of Topics allowed under the same Token: Topic + List Topic ≤ 100.
    • Each Topic allows at most ≤1000 entries.
    • Use setData to insert new data into the queue using a stack method (last in, first out), each insertion adds the data to the head of the queue.
    • Use getData to retrieve the data at the head of the queue. The original data will be deleted from the sequence.
  • List Topic:
    • The key for storing list-formatted data under a Token. The number of Topics allowed under the same Token: Topic + List Topic ≤ 100.
    • Use addToList to insert new data into the list; each insertion appends it to the end of the list.
    • Use getData to read list data of a specified index or range. The returned data is a list.

1.2 Obtain Token

Open 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 use incognito mode.

2. Example Program

This example program uses the CoreS3 device to test Ezdata data upload and retrieval. Before compiling the program, you need to install the following dependent libraries, and fill in the Token and Wi-Fi information in the code.

#include "M5Unified.h"
#include "M5_EzData.h"

const char* ssid     = "ssid";
const char* password = "password";
const char* token    = "token";

void setup()
{
    M5.begin();
    M5.Display.println("Wi-Fi connecting...");
    if (setupWifi(ssid, password)) {
        M5.Display.println("Wi-Fi connected!");
    } else {
        M5.Display.println("Wi-Fi connect failed");
    }
}

void loop()
{
    // Save the data 100 to the top of the testData topic queue.
    if (setData(token, "testData", 100)) {
        M5.Display.println("Success sending data to the testData");
    } else {
        M5.Display.println("Fail");
    }
    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.Display.printf("Success sending %d to the list\n", i);
        } else {
            M5.Display.println("Fail");
        }
        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.Display.printf("Success get data %d\n", result);
    } else {
        M5.Display.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] = {0};
    if (getData(token, "testList", Array, 0, 3)) {
        M5.Display.print("Success get list\n");
        for (int i = 0; i < 3; i++) {
            M5.Display.printf("Array[%d]=%d,", i, Array[i]);
        }
        M5.Display.println("");
    } else {
        M5.Display.println("Fail to get data");
    }
    delay(5000);

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

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

3. Control Panel

If you need to view or share data, you can visit the EzData control panel page through the following URL by passing in the Token parameter.

# https://ezdata.m5stack.com/debugger/?token=dCtdfg3u5id72J8xxxxxxxxxxxxxxx
https://ezdata.m5stack.com/debugger/?token={token}

4. API

4.1 setData

Function Prototype:

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

Function Description:

  • Save data val to the head of the specified topic queue.

Parameters:

  • const char *token
    • Ezdata token
  • const char *topic
    • Data topic of Ezdata
  • int val
    • The value to be written

Return Value:

  • int:
    • 1: Sent successfully
    • 0: Failed to send

4.2 getData

Function Prototype:

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

Function Description:

  • Get one piece of data from the head of the specified topic queue and store it in result.

Parameters:

  • const char *token
    • Ezdata token
  • const char *topic
    • Data topic of Ezdata
  • int &result
    • Reference to the variable storing the data

Return Value:

  • int:
    • 1: Read successfully
    • 0: Failed to read

4.3 addToList

Function Prototype:

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

Function Description:

  • Save the data to the head of the specified data list.

Parameters:

  • const char *token
    • Ezdata token
  • const char *list
    • Data list topic of Ezdata
  • int val
    • The value to be written

Return Value:

  • int:
    • 1: Sent successfully
    • 0: Failed to send

4.4 getData (list)

Function Prototype:

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

Function Description:

  • Get a group of data from the specified data list. The advantage of using a list to store is that it supports specifying the data index offset and can retrieve multiple data at a time. The return value is a list.

Parameters:

  • const char *token
    • Ezdata token
  • const char *list
    • Data list topic of Ezdata
  • int *Array
    • Pointer to the variable storing the list data
  • int offset
    • Offset relative to the head of the data list
  • int count
    • Number of data to read

Return Value:

  • int *:
    • int *Array: Successfully read, returns the data list pointer
    • 0: Failed to read

4.5 removeData

Function Prototype:

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

Function Description:

  • Delete a topic or list topic and clear the queue data.

Parameters:

  • const char *token
    • Ezdata token
  • const char *field
    • Ezdata topic / list topic

Return Value:

  • int:
    • 1: Deleted successfully
    • 0: Failed to delete
On This Page