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

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

共有設定を別ファイルとした

File size: 2.4 KB
Line 
1#include "rca.h"
2#include "ESP8266.h"
3#include "Client_ESP8266.h"
4#include "ThingSpeak.h"
5
6#include "../examples_gdef.h"
7
8ESP8266Client wifi_client;
9
10void 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
80unsigned long myChannelNumber =THINGSPEAK_CHANNELNUMBER ;
81const char * myWriteAPIKey = THINGSPEAK_WRITEAPIKEY ;
82
83int cnt1;
84int cnt2;
85
86#include <math.h>
87int a;
88float temperature;
89int B=3975; //B value of the thermistor
90float resistance;
91
92void 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}
Note: See TracBrowser for help on using the repository browser.