Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Grove_temperature mbed-http
Fork of Mbed-to-cybozu-kintone_post_sample by
Revision 2:687ce876e4ee, committed 2018-08-24
- Comitter:
- MACRUM
- Date:
- Fri Aug 24 00:41:04 2018 +0000
- Parent:
- 1:6c0383514e5b
- Commit message:
- Code clean-up
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6c0383514e5b -r 687ce876e4ee main.cpp
--- a/main.cpp Thu Aug 23 04:06:06 2018 +0000
+++ b/main.cpp Fri Aug 24 00:41:04 2018 +0000
@@ -9,81 +9,72 @@
#error Selected target is not supported.
#endif
-// on-board resources
-Serial pc(USBTX, USBRX, 115200);
-DigitalOut GrovePower(PB_10, 1);
-
-#define D20 (PB_4)
-
-// Grove sensors
-// Temperature sensor
-Grove_temperature tempSensor(A4);
-
-
// For your API Token, refer to "API token" in your application setting page
// Please DO NOT FORGET to assign "add records" to your key.
-const char API_TOKEN[] = "api-token";
-// Your domain name can be seen in the usage explanation with curl.
+const char API_TOKEN[] = "api-key";
+
+// Your domain name can be seen in the usage explanation with curl.
const char URL[] = "https://{domain}.cybozu.com/k/v1/record.json";
// app_id, application id, can be checked with your application's URL
// e.g. https://{domain}.cybozu.com/k/3/ -> app_id is 3
int app_id = 3;
+// on-board resources
+Serial pc(USBTX, USBRX, 115200);
+DigitalOut GrovePower(PB_10, 1);
+
+// Grove sensors
+// Temperature sensor
+Grove_temperature tempSensor(A4);
+
bool post_kintone(NetworkInterface* nif, const char *url, int app_id_, char* field_code, float value)
-{
+{
HttpsRequest* post_req = new HttpsRequest(nif, SSL_CA_PEM, HTTP_POST, url);
post_req->set_header("X-Cybozu-API-Token", API_TOKEN);
post_req->set_header("Content-Type", "application/json");
-
+
std::stringstream ss_body;
-
+
ss_body << "{\"app\": " << app_id_ << ", \"record\": {\"" << field_code << "\": {\"value\": \"" << value << "\"}}}\n";
-
- string body = ss_body.str();
- printf("body:%s\r\n",body.c_str());
-
+ string body = ss_body.str();
+ pc.printf("body:%s\n",body.c_str());
+
HttpResponse* post_res = post_req->send(body.c_str(), body.length());
-
- printf("res:%s\r\n",post_res->get_body_as_string().c_str());
-
-
- if(post_res->get_status_code() == 200){
+ pc.printf("res:%s\n",post_res->get_body_as_string().c_str());
+
+ if(post_res->get_status_code() == 200) {
delete post_req;
return true;
}
-
- delete post_req;
-
+
+ delete post_req;
return false;
}
// main() runs in its own thread in the OS
-int main() {
- pc.printf("Greetings from Ina-city Hackerthon on 25-26 of August\n");
-
- NetworkInterface* network = NULL;
+int main()
+{
- pc.printf("\r\n----- Start -----\r\n");
-
+ NetworkInterface* network = NULL;
network = easy_connect(true); // If true, prints out connection details.
+
if (!network) {
- pc.printf("\r\n----- Network Error -----\r\n");
+ pc.printf("\n----- Network Error -----\n");
return -1;
}
- pc.printf("\r\n----- Network Connected -----\r\n");
-
+ pc.printf("\n----- Network Connected -----\n");
wait(2.0);
-
+
while(1) {
-
+
float currentTemp = tempSensor.getTemperature();
-
+
bool ret = post_kintone(network, URL, app_id, "temp", currentTemp);
- pc.printf("\n----- HTTPS POST response [%s]----- \n\r",ret== true ? "OK" : "NG");
-
+ pc.printf("\n----- HTTPS POST response [%s]-----\n",ret== true ? "OK" : "NG");
+
wait(10.0);
}
}
