메뉴 건너뛰기

프로그래밍


아두이노에서 두근두근 OPEN API를 인증키와 함께 POST로 호출하는 예제 코드입니다.

(The way how to call DKDK Open API from Arduino by HTTPS POST Method)


#include <WiFiClientSecure.h>

  const int httpPort = 443; //for https
  const char* host = "api.dkdk.io";

void requestCall() {
  WiFiClientSecure client;

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  String url = "/v2/dkdk"; //resource path

  // post data
  String jsonbody = String("{\r\n \"user_uuid\" : \"MY_USER_UUID\",\r\n  \"action\" : \"touch\"\r\n  \"friend_uuids\" : [\"1234-567\"]\r\n  \"pattern_uuid\" : \"1234-1234\"\r\n}";

  // This will send the request to the server
  String requestBody = String("POST ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "dkdk-token: DKDK-TOKEN\r\n" +
             "Content-Type: application/json\r\n" +
             "Cache-Control: no-cache\r\n" +
             "Content-length: " + String(jsonbody.length()) + "\r\n\r\n" +
             jsonbody;

  client.print(requestBody); 
 
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
}


건투를 빕니다!







번호 제목 날짜 조회 수
공지 [TIP] PYTHON 에서 "UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 6987: illegal multibyte sequence" 오류 날때... [52] 2016.02.20 246890
공지 [펌] ARM GCC Inline Assembler Cookbook 2006.08.18 44847
공지 [TIP] R에서 페이스북 페이지 정보 크롤링 하기 [6] 2017.02.11 26258
169 [TIP] MacOS의 크롬에서 keyup 이벤트가 두 번 호출 되는 오류 2023.07.15 537
168 [TIP] C#의 Hashtable을 안전하게 사용하려면 2023.06.10 280
167 [TIP] 윈도우 부팅 완료 후 Process.Start로 cmd.exe 실행 결과를 못 얻을 때 2023.05.29 609
166 [TIP] PYTHON으로 유튜브 채널 영상, 조회수, 설명 크롤링 2021.07.22 5014
165 [TIP] vector<Point2f> 파라메터를 JNI에서 자바로 전달하기 (the way how to pass vector<Point2f> variable to JAVA code layer) 2020.06.27 701
164 [TIP] 외부 (PHP)코드에서 XE에 게시물 등록하기 2020.05.30 3156
163 [TIP] Node.js 에서 현재 기상정보 API 호출하기 2020.02.22 4586
162 [TIP] gcc 빌드중에 /usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in ... 와 같은 오류를 만났을 때 2019.11.25 1706
161 [TIP] Windows UWP에서 시리얼 포트가 열리지 않을때 2019.11.08 1620
160 [TIP] 화면 스크롤시 HTML Element가 화면의 중간에 위치하면 감지하기 2019.10.03 4065
159 [TIP] Visual Studio 2019 에서 (배포용)설치파일 만들기 2019.09.30 3976
158 [TIP] Android에서 MS의 Face Rest API사용하기 (How to use the MS Face API on Android) 2019.07.16 855
157 [TIP] Xcode에서 boost 사용하는 방법 2019.06.28 651
» [TIP] 아두이노에서 두근두근 Open API 호출하기 2019.06.04 3033
155 [TIP] AWS Lambda, API Gateway 를 이용하여 S3에 파일 업로드 하기 2018.06.12 2156
154 [TIP] 파이선에서 AWS Lambda API 호출시 Cognito 사용자 토큰으로 권한 확인하기 2018.06.11 1674
153 [TIP] 파이선에서 AWS Cognito 에 Sign-up, Sign-in 하는 예제 2018.06.08 1802
152 [TIP] Ajax에서 AWS Lambda Rest API CALL 하기 (How to call AWS Lambda API from Ajax) 2018.02.12 1445
151 [TIP] 각종 OAuth 로그인 예제 [6] 2018.01.30 1344
150 [TIP] 파이선에서 AWS Lambda로 만든 Restful API 호출하기 (How to call AWS Lambda Restful API from Python) 2018.01.23 1261
위로