EzData - Arduino

功能说明

EzData是M5Stack提供的一个IoT云端数据储存服务,不同的设备之间可以通过唯一token,向储存队列中插入或提取数据,实现数据共享。

刷新token 点击刷新获取token...

Github

EzData API

注意事项:
1. 以下所有操作都依赖于唯一token,该token在同一浏览器环境下是固定的, 使用前请复制token。
2. 半年时间内没有进行数据操作,则清空该token对应的数据队列。
3. 数据将按照插入时间,降序排序(最后插入的数据,在列表的首位),数据会累积保存。

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

  • 保存数据val至指定topic队列首位

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

  • 从指定的topic队列首位获取一个数据,并存储在result中

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

  • 保存数据至指定数据列表首位

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

  • 从指定的数据列表中获取一组数据,使用列表储存的优点是,支持指定数据索引偏移且可一次获取多个数据,返回值为一个list。
  • list: 列表名称
  • offset: 相对于数据列表首位的偏移
  • count: 读取数据个数

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

  • 删除topic或list,并清空队列数据。

案例程序

该案例程序使用M5Core设备,程序编译前需安装相关依赖库 M5Stack M5_EzData , 并将token及wifi信息填写到代码中。


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

// Configure the name and password of the connected wifi and your token.  配置所连接wifi的名称、密码以及你的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 wifi.  连接到wifi
    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.  保存数据20至 testData 队列首位
  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.  依次保存3个数据至 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.  从一个 topic中获取一个数据,并将值存储在 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.  从一个 list中获取一组数据,并将值存储在 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);
}
On This Page