9. ThingSpeak - sunbang123/Smart_device GitHub Wiki
- ThingSpeak๋ IoT ๋๋ฐ์ด์ค์์ ์์งํ ์ผ์ ๋ฐ์ดํฐ๋ฅผ ํด๋ผ์ฐ๋ ์๋ฒ์ ์ ์ฅํ๊ณ , ์ด๋ฅผ ๋ถ์ํ๊ณ ์๊ฐํํ๋ IoT ํ๋ซํผ
- ์จ๋ผ์ธ ์์์ ๋ฐ์ดํฐ ์์ง, ์ ์ฅ, ๋ถ์, ์๊ฐํ, ๊ณต์ ๋ฑ์ IoT ์๋น์ค๋ฅผ ์ ๊ณต
- RESTful API๋ฅผ ์ ๊ณตํ๋ฏ๋ก, ๋ค๋ฅธ ์์ฉ ํ๋ก๊ทธ๋จ๊ณผ ์ฐ๋ํ์ฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํจ
-
ThingSpeak ํํ์ด์ง์ ํ์๊ฐ์ ์ ํจ.
-
My Channels์์ New Channel์ ๋ง๋ฆ

- New Channel์์ Field ์ด๋ฆ์ ์ง์ ํจ.
- Arduino IDE์์ ThingSpeak ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํจ.
- ํ์ฌ ์ฐ๊ฒฐ๋ WIFI ์ด๋ฆ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํ ๋ค์ ์ค์ต์ฝ๋์ ์ ๋ ฅ.
์ค์ต ์ฝ๋
#include <WiFi.h>
#include <ThingSpeak.h>
const char* ssid = "[WIFI ์ด๋ฆ]";
const char* password = "[WIFI password]";
...
- ThingSpeak My Channel๋ก ๋ค์ด๊ฐ์ Channel ID์ APIํค๋ฅผ ํ์ธํ ๋ค์ ์ค์ต์ฝ๋์ ์ ๋ ฅ.
...
WiFiClient client;
unsigned long ch1_ID = 2126281;
const char* ch1_WriteKey = "AGP30QRISWWCJ0ZO";
void setup() {
Serial.begin(115200);
delay(10);
initWiFi();
ThingSpeak.begin(client);
}
void loop() {
int i;
for (i = 0; i < 4; ++i) {
ThingSpeak.writeField(ch1_ID, 1, i, ch1_WriteKey);
delay(2000);
}
}
void initWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
}
-
์ ๋ก๋
-
ThingSpeak ์ฐจํธ ํ์ธ.
- ThingSpeak์ ์๋์ด๋ ธ ์ฐ๋์ ๋ํ ๊ธฐ์ด ์ง์์ ์ต๋ํ๊ณ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ๋ฐฐ์ธ ์ ์์์.
- API๋ฅผ ์ด์ฉํ์ฌ ํ๋ก๊ทธ๋จ๊ณผ ์ฐ๋ํ์ฌ ํ์ฉํ๋ ์ ์ด ์ธ์๊น์์.