아두이노에서 AWS Lambda Restful API를 인증키와 함께 POST 로 호출하는 예제 코드입니다.
(The way how to call AWS Lambda Restful API from Arduino by HTTP POST Method)
#include <WiFiClientSecure.h> const int httpPort = 443; //for https const char* host = "abcdefghijklmn.execute-api.ap-????-1.amazonaws.com"; void requestCall() { WiFiClientSecure client; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } String url = "/prod/my/resource"; //resource path // post data String jsonbody = String("{\r\n \"param1\" : \"1234\",\r\n \"param2\" : \"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" + "api-key: abcdefffdefffff88881112343434\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); } }
건투를 빕니다!
이 게시물이 | |
AiRPAGE가 |