![[Wemos D1] 2. Thinkspeak에 데이터를 올리는 방법](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FboMLkI%2FbtqHscLNV8i%2F1u0wH886mKl9ZpLUKFPJ0k%2Fimg.png)
[Wemos D1] 2. Thinkspeak에 데이터를 올리는 방법IoT/Arduino2020. 8. 27. 20:53
Table of Contents
두번째로 @Thinkspeak에 데이터를 올리는 방법을 소개하겠습니다.
우선 Thinkspeak란 IoT센서 값이나 다양한 데이터들을 모아 그래프로 볼 수 있게 해주는? 사이트라고 생각해주시면 되겠습니다.
IoT Analytics - ThingSpeak Internet of Things
Weather Station This project shows how to build an Arduino-based weather station that sends data to ThingSpeak. Once the data is collected, MATLAB is used to view trends of the data, plot histograms of the data, calculate dew point from the raw temperature
thingspeak.com
우선 여기 회원가입을 하신다음
새로운 채널을 만들어줍니다.
Name : 채널이름
Description : 채널설명
Field 1 : 저장될 데이터 필드 1
더필요하면 2,3 쭉쭉 만들어 사용하면됩니다.
원하는 대로 만드셨다면
API Keys를 눌러 API창으로 들어가 본인의 API키를 확인합니다.
////////////////////////////////////
// 토양 수분센서 단
// thingSpeak에 값 전송 하는데 필요한 대기시간 15초 이상
unsigned long currentMillis = millis();
if((currentMillis % 16000) == 0){
// 토양 수분센서로부터 측정된 값을 읽습니다.
int value = analogRead(soil);
// 토양 수분센서로부터 측정된 값를 시리얼 모니터에 출력합니다.
Serial.print("read sensor value : ");
Serial.println(value);
// server api.thingspeak.com의 포트 80에 접속한다.
if(client.connect(server, 80)){ // 접속성공시 true, 실패시 false return
// apiKey의 뒤에 field1값을 붙이서 보낼 값을 만들어준다.
String postStr = apiKey;
postStr += "&field1=";
postStr += String(value);
postStr += "\r\n\r\n";
// POST로 값 전송
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
}
반응형
'IoT > Arduino' 카테고리의 다른 글
[Wemos D1] 1. WiFi 연결하는 법 (0) | 2020.06.29 |
---|---|
[아두이노] LCD 알파벳 표현하기 (0) | 2020.06.26 |
[아두이노] 키패드 입력받기 (0) | 2020.05.26 |
[아두이노] 아날로그 핀으로 모터움직이기(MAP함수) (0) | 2020.05.26 |
[아두이노] IR리모컨을 이용한 LED RGB변경 (0) | 2020.05.26 |
@반나무 :: 반나무_뿌리
3년차 WPF 개발자입니다.
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!