1 | #include "rca.h"
|
---|
2 | #include "ESP8266.h"
|
---|
3 | #include "Client_ESP8266.h"
|
---|
4 | #include "ThingSpeak.h"
|
---|
5 |
|
---|
6 | #define STA_SSID ""
|
---|
7 | #define STA_PASSWORD ""
|
---|
8 |
|
---|
9 | ESP8266Client wifi_client;
|
---|
10 |
|
---|
11 | void setup()
|
---|
12 | {
|
---|
13 | int ret;
|
---|
14 |
|
---|
15 | Serial.begin(115200);
|
---|
16 | Serial.print("Milkcocoa SDK demo");
|
---|
17 |
|
---|
18 | // Connect to WiFi access point.
|
---|
19 | Serial.println(); Serial.println();
|
---|
20 | Serial.print("Connecting to ");
|
---|
21 | Serial.println(STA_SSID);
|
---|
22 |
|
---|
23 | ret = WiFi.begin(Serial5, 115200);
|
---|
24 |
|
---|
25 | if(ret == 1) {
|
---|
26 | Serial.print("Cannot communicate with ESP8266.");
|
---|
27 | while(1);
|
---|
28 | } else if(ret == 2) {
|
---|
29 | Serial.println("FW Version mismatch.");
|
---|
30 | Serial.print("FW Version:");
|
---|
31 | Serial.println(WiFi.getVersion().c_str());
|
---|
32 | Serial.print("Supported FW Version:");
|
---|
33 | Serial.println(ESP8266_SUPPORT_VERSION);
|
---|
34 | while(1);
|
---|
35 | } else {
|
---|
36 | Serial.print("begin ok\r\n");
|
---|
37 | }
|
---|
38 |
|
---|
39 | Serial.print("FW Version:");
|
---|
40 | Serial.println(WiFi.getVersion().c_str());
|
---|
41 |
|
---|
42 | if (WiFi.setOprToStation()) {
|
---|
43 | Serial.print("to station ok\r\n");
|
---|
44 | } else {
|
---|
45 | Serial.print("to station err\r\n");
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (WiFi.joinAP(STA_SSID, STA_PASSWORD)) {
|
---|
49 | Serial.print("Join AP success\r\n");
|
---|
50 | Serial.print("IP: ");
|
---|
51 | Serial.println(WiFi.getLocalIP().c_str());
|
---|
52 | } else {
|
---|
53 | Serial.print("Join AP failure\r\n");
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (WiFi.stopServer()) {
|
---|
57 | Serial.print("Stop server ok\r\n");
|
---|
58 | } else {
|
---|
59 | Serial.print("Stop server err\r\n");
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (WiFi.disableMUX()) {
|
---|
63 | Serial.print("single ok\r\n");
|
---|
64 | } else {
|
---|
65 | Serial.print("single err\r\n");
|
---|
66 | }
|
---|
67 |
|
---|
68 | //Setup
|
---|
69 | if (ThingSpeak.begin(wifi_client)) {
|
---|
70 | Serial.print("ThingSpeak.begin() ok\r\n");
|
---|
71 | } else {
|
---|
72 | Serial.print("ThingSpeak.begin() err\r\n");
|
---|
73 | }
|
---|
74 |
|
---|
75 | pinMode(13, OUTPUT);
|
---|
76 | digitalWrite(13, LOW);
|
---|
77 |
|
---|
78 | Serial.println("setup end\r\n");
|
---|
79 | }
|
---|
80 |
|
---|
81 | unsigned long myChannelNumber =
|
---|
82 | const char * myWriteAPIKey = "";
|
---|
83 | int cnt1;
|
---|
84 | int cnt2;
|
---|
85 |
|
---|
86 | void loop() {
|
---|
87 | int ret;
|
---|
88 |
|
---|
89 | ThingSpeak.setField(1,cnt1);
|
---|
90 | ThingSpeak.setField(2,cnt2);
|
---|
91 |
|
---|
92 | cnt1 += 1;
|
---|
93 | cnt2 += 2;
|
---|
94 |
|
---|
95 | // Write the fields that you've set all at once.
|
---|
96 | ret = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
|
---|
97 | Serial.print("Call writeFields() : return code is ");
|
---|
98 | Serial.println(ret);
|
---|
99 |
|
---|
100 | delay(20000);
|
---|
101 | }
|
---|