source: rtos_arduino/trunk/examples/ThingSpeak_basic/rca_app.cpp@ 190

Last change on this file since 190 was 190, checked in by ertl-honda, 8 years ago

Thinkgspeakのサポート

File size: 2.3 KB
Line 
1#include "rca.h"
2#include "ESP8266.h"
3#include "Client_ESP8266.h"
4#include "ThingSpeak.h"
5
6#define SSID ""
7#define PASSWORD ""
8
9ESP8266Client wifi;
10
11void 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(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(SSID, 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)) {
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
81unsigned long myChannelNumber = 103978;
82const char * myWriteAPIKey = "D1G413IIE3QBNWGG";
83int cnt1;
84int cnt2;
85
86void loop() {
87 int ret;
88 ThingSpeak.setField(1,cnt1);
89 ThingSpeak.setField(2,cnt2);
90
91 cnt1 += 1;
92 cnt2 += 2;
93
94 // Write the fields that you've set all at once.
95 ret = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
96 Serial.print("Call writeFields() : return code is ");
97 Serial.println(ret);
98
99 delay(20000);
100}
Note: See TracBrowser for help on using the repository browser.