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