1
+ /*
2
+ *******************************************************************************
3
+ * Copyright (c) 2021 by M5Stack
4
+ * Equipped with M5Core sample source code
5
+ * 配套 M5Core 示例源代码
6
+ * Visit the website for more information:https://docs.m5stack.com/en/core/gray
7
+ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
8
+ *
9
+ * describe:EzData.
10
+ * date:2021/10/17
11
+ *******************************************************************************
12
+ */
13
+ #include " M5Stack.h"
14
+ #include " M5_EzData.h"
15
+
16
+ // Configure the name and password of the connected wifi and your token. 配置所连接wifi的名称、密码以及你的token
17
+ const char * ssid = " Explore-F" ;
18
+ const char * password = " xingchentansuo123" ;
19
+ const char * token = " " ;
20
+
21
+ void setup () {
22
+ M5.begin (); // Initialize M5Stack
23
+ M5.Power .begin ();
24
+ if (setupWifi (ssid,password)){ // Connect to wifi. 连接到wifi
25
+ M5.Lcd .printf (" Success connecting to %s\n " ,ssid);
26
+ }else {
27
+ M5.Lcd .printf (" Connecting to %s failed\n " ,ssid);
28
+ }
29
+ }
30
+
31
+ void loop () {
32
+ // Save the data 20 to the top of the testData topic queue. 保存数据20至 testData 队列首位
33
+ if (setData (token," testData" ,20 )){
34
+ M5.Lcd .printf (" Success sending data to the topic\n " );
35
+ }else {
36
+ M5.Lcd .print (" Fail to save data\n " );
37
+ }
38
+ delay (5000 );
39
+
40
+ // Save 3 data in sequence to the first place of testList. 依次保存3个数据至 testList首位
41
+ for (int i=0 ;i<3 ;i++){
42
+ if (addToList (token," testList" ,i)){
43
+ M5.Lcd .printf (" Success sending %d to the list\n " ,i);
44
+ }else {
45
+ M5.Lcd .print (" Fail to save data\n " );
46
+ }
47
+ delay (100 );
48
+ }
49
+ delay (5000 );
50
+
51
+ // Get a piece of data from a topic and store the value in result. 从一个 topic中获取一个数据,并将值存储在 result
52
+ int result=0 ;
53
+ if (getData (token," testData" ,result)){
54
+ M5.Lcd .printf (" Success get data %d\n " ,result);
55
+ }else {
56
+ M5.Lcd .print (" Fail to get data\n " );
57
+ }
58
+ delay (5000 );
59
+
60
+ // Get a set of data from a list and store the values in the Array array. 从一个 list中获取一组数据,并将值存储在 Array数组中
61
+ int Array[3 ]={};
62
+ if (getData (token," testList" ,Array,0 ,3 )){
63
+ M5.Lcd .print (" Success get list\n " );
64
+ for (int i=0 ;i<3 ;i++){
65
+ M5.Lcd .printf (" Array[%d]=%d," ,i,Array[i]);
66
+ }
67
+ M5.Lcd .println (" " );
68
+ }else {
69
+ M5.Lcd .println (" Fail to get data" );
70
+ }
71
+ delay (5000 );
72
+
73
+ // Remove data
74
+ if (removeData (token," testData" ))
75
+ M5.Lcd .printf (" Success remove data\n " );
76
+ else
77
+ M5.Lcd .println (" Fail to remove data" );
78
+
79
+ if (removeData (token," testList" ))
80
+ M5.Lcd .printf (" Success remove data from the list\n " );
81
+ else
82
+ M5.Lcd .println (" Fail to remove data" );
83
+ delay (5000 );
84
+ M5.Lcd .fillScreen (BLACK);
85
+ M5.Lcd .setCursor (0 ,0 );
86
+ }
0 commit comments