Sample program that can send the recognition data from HVC-P2 to Fujitsu IoT Platform using REST (HTTP)

Dependencies:   AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP USBHost_custom easy-connect-gr-peach mbed-http picojson

Information

Here are both English and Japanese description. First, English description is shown followed by Japanese one. 本ページには英語版と日本語版の説明があります。まず英語版、続いて日本語版の説明となります。

Overview

This sample program shows how to send the cognitive data gathered by Omron HVC-P2 (Human Vision Components B5T-007001) to IoT Platform managed by FUJITSU ( http://jp.fujitsu.com/solutions/cloud/k5/function/paas/iot-platform/ ).

Hardware Configuration

/media/uploads/dkato/composition_hvcp2_demo.jpg

When executing this sample program, please configure the above H/W as shown below:
/media/uploads/dkato/composition_hvcp2_demo_2.jpg

Also, please close JP3 of GR-PEACH as follows:
/media/uploads/RyoheiHagimoto/usb.jpg

Application Preconfiguration

Build Procedure

  • Import this sample program onto mbed Compiler
  • In GR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp, please replace <ACCESS CODE> with the access code you set up on IoT Platform. For details on how to set up Access Code, please refer to the above Application Setup. Then, please delete the line beginning with #error macro.

Access Code configuration

#define ACCESS_CODE <Access CODE>
#error "You need to replace <Access CODE for your resource> with yours"
  • In GR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp, please replace <Base URI>, <Tenant ID> and <Path-to-Resource> below with yours and delete the line beginning with #error macro. For details on <Base URI> and <Tenant ID>, please contact FUJITSU LIMITED. Also, for details on <Path-to-Resource>, please refer to the above Application Setup.

URI configuration

std::string put_uri_base("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>.json");
#error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
**snip**
std::string get_uri("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>/_past.json");
#error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
  • Compile the program. If compilation is successfully terminated, the binary should be downloaded on your PC.
  • Plug Ethernet cable into GR-PEACH
  • Plug micro-USB cable into the port which lies on the next to RESET button. If GR-PEACH is successfully recognized, it appears as the USB flash disk named mbed as show below:
    /media/uploads/HinoNaka/mbed_drive.png
  • Copy the downloaded binary to mbed drive
  • Press RESET button on GR-PEACH in order to run the program. If it's successfully run, you can see the following message on terminal:
    /media/uploads/HinoNaka/iotplatform_log.png

Format of Data to be sent to IoT Platform

In this program, the cognitive data sent from HVC-P2 is serialized in the following JSON format and send it to IoT Platform:

  • Face detection data

{
    "RecodeType": "HVC-P2(face)"
    "id": <GR-PEACH ID>-<Sensor ID>"
    "FaceRectangle": {
        "Height": xxxx,
        "Left": xxxx,
        "Top": xxxx,
        "Width": xxxx,
    },
    "Gender": "male" or "female",
    "Scores": {
        "Anger": zzz,
        "Hapiness": zzz,
        "Neutral": zzz,
        "Sadness": zzz,
        "Surprise": zzz
    }
}

xxxx: Top-left coordinate, width and height of the rectangle circumscribing the detected face in LCD display coordinate system
zzz: the value indicating the expression estimated from the detected face

//

  • Body detection data

{
    "RecodeType": "HVC-P2(body)"
    "id": <GR-PEACH ID>-<Sensor ID>"
    "BodyRectangle": {
        "Height": xxxx,
        "Left": xxxx,
        "Top": xxxx,
        "Width": xxxx,
    }
}

xxxx: Top-left coordinate, width and height of the rectangle circumscribing the detected body in LCD display coordinate system

概要

本プログラムは、オムロン社製HVC-P2 (Human Vision Components B5T-007001)で収集した各種認識データを、富士通社のIoT Platform ( http://jp.fujitsu.com/solutions/cloud/k5/function/paas/iot-platform/ ) に送信するサンプルプログラムです。

ハードウェア構成

/media/uploads/dkato/composition_hvcp2_demo.jpg

本プログラムを動作させる場合、上記H/Wを下図のように接続してください。 /media/uploads/dkato/composition_hvcp2_demo_2.jpg

また下図に示すGR-PEACHのJP3をショートしてください。 /media/uploads/RyoheiHagimoto/usb.jpg

アプリケーションの事前設定

ビルド手順

  • 本サンプルプログラムをmbed Compilerにインポートします
  • 下記に示すGR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp中の<ACCESS CODE> を、IoT Platform上で設定したアクセスコードで上書きしてください。<Access Code>の設定方法につきましては、上述のApplication Setupを参照願います。また #errorマクロで始まる行を削除してください。

Access Code configuration

#define ACCESS_CODE <Access CODE>
#error "You need to replace <Access CODE for your resource> with yours"
  • 下記に示すGR-PEACH_HVC-P2_IoTPlatform_http/IoT_Platform/iot_platform.cpp中の<Base URI><Tenant ID>、および<Path-to-Resource>>を適当な値に置換えるとともに、#errorマクロで始まる行を削除してください。ここで、<Base URI>、 <Tenant ID>の詳細につきましては富士通社へご確認願います。また<Path-to-Resource>>につきましては、Application Setupの項を参照ください。

URI configuration

std::string put_uri_base("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>.json");
#error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
(中略)
std::string get_uri("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>/_past.json");
#error "You need to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
  • プログラムをコンパイルします。コンパイルが正常終了すると、バイナリがお使いのPCにダウンロードされます。
  • GR-PEACHのRJ-45コネクタにEthernetケーブルを差し込んでください。
  • USBA - Micro USBケーブルを、GR-PEACHのRESETボタンの隣に配置されたMicro USBポートに差し込んでください。GR-PEACHが正常に認識されると、下図に示すようにGR-PEACHがmbedという名称のUSBドライブとして認識されます。
    /media/uploads/HinoNaka/mbed_drive.png
  • ダウンロードしたバイナリをmbedドライブにコピーします。
  • RESETボタンを押下してプログラムを実行します。正常に実行された場合、下記に示すメッセージがターミナル上に表示されます。
    /media/uploads/HinoNaka/iotplatform_log.png

送信データフォーマット

本プログラムでは、HVC-P2が収集した認識データを下記のJSONフォーマットにシリアライズし、IoT Platformへ送信します。

  • Face detection data

{
    "RecodeType": "HVC-P2(face)"
    "id": <GR-PEACH ID>-<Sensor ID>"
    "FaceRectangle": {
        "Height": xxxx,
        "Left": xxxx,
        "Top": xxxx,
        "Width": xxxx,
    },
    "Gender": "male" or "female",
    "Scores": {
        "Anger": zzz,
        "Hapiness": zzz,
        "Neutral": zzz,
        "Sadness": zzz,
        "Surprise": zzz
    }
}

xxxx: LCD表示座標系における検出した顔に外接する矩形の左上座標・幅・高さ
zzz: 検出した顔から推定した各種感情を示す数値

//

  • Body detection data

{
    "RecodeType": "HVC-P2(body)"
    "id": <GR-PEACH ID>-<Sensor ID>"
    "BodyRectangle": {
        "Height": xxxx,
        "Left": xxxx,
        "Top": xxxx,
        "Width": xxxx,
    }
}

xxxx: LCD表示座標系における検出した人体に外接する矩形の左上座標・幅・高さ
Committer:
Osamu Nakamura
Date:
Thu Sep 07 18:15:54 2017 +0900
Revision:
0:813a237f1c50
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Osamu Nakamura 0:813a237f1c50 1 #include "mbed.h"
Osamu Nakamura 0:813a237f1c50 2 #include "picojson.h"
Osamu Nakamura 0:813a237f1c50 3 #include "iot_platform.h"
Osamu Nakamura 0:813a237f1c50 4 #include <string>
Osamu Nakamura 0:813a237f1c50 5 #include <iostream>
Osamu Nakamura 0:813a237f1c50 6 #include <vector>
Osamu Nakamura 0:813a237f1c50 7 #include "easy-connect.h"
Osamu Nakamura 0:813a237f1c50 8 #include "http_request.h"
Osamu Nakamura 0:813a237f1c50 9 #include "NTPClient.h"
Osamu Nakamura 0:813a237f1c50 10 #include <time.h>
Osamu Nakamura 0:813a237f1c50 11
Osamu Nakamura 0:813a237f1c50 12 /* Detect result */
Osamu Nakamura 0:813a237f1c50 13 result_hvcp2_fd_t result_hvcp2_fd[DETECT_MAX];
Osamu Nakamura 0:813a237f1c50 14 result_hvcp2_bd_t result_hvcp2_bd[DETECT_MAX];
Osamu Nakamura 0:813a237f1c50 15 uint32_t result_hvcp2_bd_cnt;
Osamu Nakamura 0:813a237f1c50 16 uint32_t result_hvcp2_fd_cnt;
Osamu Nakamura 0:813a237f1c50 17
Osamu Nakamura 0:813a237f1c50 18 Timer http_resp_time; // response time
Osamu Nakamura 0:813a237f1c50 19 uint16_t data[4]; //for color data
Osamu Nakamura 0:813a237f1c50 20
Osamu Nakamura 0:813a237f1c50 21 #define JST_OFFSET 9
Osamu Nakamura 0:813a237f1c50 22
Osamu Nakamura 0:813a237f1c50 23 #define ACCESS_CODE "Bearer <ACCESS CODE>"
Osamu Nakamura 0:813a237f1c50 24 #error "You have to replace the above <ACCESS CODE> with yours"
Osamu Nakamura 0:813a237f1c50 25
Osamu Nakamura 0:813a237f1c50 26 std::string put_uri_base("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>.json");
Osamu Nakamura 0:813a237f1c50 27 #error "You have to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
Osamu Nakamura 0:813a237f1c50 28
Osamu Nakamura 0:813a237f1c50 29 std::string put_uri;
Osamu Nakamura 0:813a237f1c50 30
Osamu Nakamura 0:813a237f1c50 31 // json-object for camera
Osamu Nakamura 0:813a237f1c50 32 picojson::object o_bd[DETECT_MAX], o_fd[DETECT_MAX], o_fr[DETECT_MAX], o_scr[DETECT_MAX];
Osamu Nakamura 0:813a237f1c50 33 // json-object for sensor
Osamu Nakamura 0:813a237f1c50 34 picojson::object o_acc, o_atmo, o_col, o_temp;
Osamu Nakamura 0:813a237f1c50 35
Osamu Nakamura 0:813a237f1c50 36 picojson::array data_array_acc(6);
Osamu Nakamura 0:813a237f1c50 37 picojson::array data_array_atmo(6);
Osamu Nakamura 0:813a237f1c50 38 picojson::array data_array_col(6);
Osamu Nakamura 0:813a237f1c50 39 picojson::array data_array_temp(6);
Osamu Nakamura 0:813a237f1c50 40
Osamu Nakamura 0:813a237f1c50 41 // URI for GET request
Osamu Nakamura 0:813a237f1c50 42 std::string get_uri("<Base URI>/v1/<Tenant ID>/<Path-to-Resource>/_past.json");
Osamu Nakamura 0:813a237f1c50 43 #error "You have to replace <Base URI>, <Tenant ID> and <Path-to-Resource> with yours"
Osamu Nakamura 0:813a237f1c50 44
Osamu Nakamura 0:813a237f1c50 45 void dump_response(HttpResponse* res)
Osamu Nakamura 0:813a237f1c50 46 {
Osamu Nakamura 0:813a237f1c50 47 DEBUG_PRINT("Status: %d - %s\n", res->get_status_code(),
Osamu Nakamura 0:813a237f1c50 48 res->get_status_message().c_str());
Osamu Nakamura 0:813a237f1c50 49
Osamu Nakamura 0:813a237f1c50 50 DEBUG_PRINT("Headers:\n");
Osamu Nakamura 0:813a237f1c50 51 for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
Osamu Nakamura 0:813a237f1c50 52 DEBUG_PRINT("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(),
Osamu Nakamura 0:813a237f1c50 53 res->get_headers_values()[ix]->c_str());
Osamu Nakamura 0:813a237f1c50 54 }
Osamu Nakamura 0:813a237f1c50 55 DEBUG_PRINT("\nBody (%d bytes):\n\n%s\n", res->get_body_length(),
Osamu Nakamura 0:813a237f1c50 56 res->get_body_as_string().c_str());
Osamu Nakamura 0:813a237f1c50 57 }
Osamu Nakamura 0:813a237f1c50 58
Osamu Nakamura 0:813a237f1c50 59 std::string create_put_uri(std::string uri_base)
Osamu Nakamura 0:813a237f1c50 60 {
Osamu Nakamura 0:813a237f1c50 61 time_t ctTime;
Osamu Nakamura 0:813a237f1c50 62 struct tm *pnow;
Osamu Nakamura 0:813a237f1c50 63 char date_and_hour[50];
Osamu Nakamura 0:813a237f1c50 64 std::string uri;
Osamu Nakamura 0:813a237f1c50 65
Osamu Nakamura 0:813a237f1c50 66 ctTime = time(NULL);
Osamu Nakamura 0:813a237f1c50 67 pnow = localtime(&ctTime);
Osamu Nakamura 0:813a237f1c50 68 sprintf(date_and_hour, "?$date=%04d%02d%02dT%02d%02d%02d.000%%2B%02d00",
Osamu Nakamura 0:813a237f1c50 69 (pnow->tm_year + 1900), (pnow->tm_mon + 1), pnow->tm_mday,
Osamu Nakamura 0:813a237f1c50 70 (pnow->tm_hour + JST_OFFSET - pnow->tm_isdst), pnow->tm_min,
Osamu Nakamura 0:813a237f1c50 71 pnow->tm_sec, (JST_OFFSET - pnow->tm_isdst));
Osamu Nakamura 0:813a237f1c50 72
Osamu Nakamura 0:813a237f1c50 73 uri = uri_base + date_and_hour;
Osamu Nakamura 0:813a237f1c50 74
Osamu Nakamura 0:813a237f1c50 75 return(uri);
Osamu Nakamura 0:813a237f1c50 76 }
Osamu Nakamura 0:813a237f1c50 77
Osamu Nakamura 0:813a237f1c50 78 int iot_put(NetworkInterface *network, picojson::object o4)
Osamu Nakamura 0:813a237f1c50 79 {
Osamu Nakamura 0:813a237f1c50 80
Osamu Nakamura 0:813a237f1c50 81 #ifdef ENABLED_NTP
Osamu Nakamura 0:813a237f1c50 82 put_uri = create_put_uri(put_uri_base);
Osamu Nakamura 0:813a237f1c50 83 #else
Osamu Nakamura 0:813a237f1c50 84 put_uri = put_uri_base;
Osamu Nakamura 0:813a237f1c50 85 #endif // ENABLED_NTP
Osamu Nakamura 0:813a237f1c50 86
Osamu Nakamura 0:813a237f1c50 87 // PUT request to IoT Platform
Osamu Nakamura 0:813a237f1c50 88 HttpRequest* put_req = new HttpRequest(network, HTTP_PUT, put_uri.c_str());
Osamu Nakamura 0:813a237f1c50 89 put_req->set_header("Authorization", ACCESS_CODE);
Osamu Nakamura 0:813a237f1c50 90
Osamu Nakamura 0:813a237f1c50 91 picojson::value v_all(o4);
Osamu Nakamura 0:813a237f1c50 92
Osamu Nakamura 0:813a237f1c50 93 std::string body = v_all.serialize();
Osamu Nakamura 0:813a237f1c50 94
Osamu Nakamura 0:813a237f1c50 95 HttpResponse* put_res = put_req->send(body.c_str(), body.length());
Osamu Nakamura 0:813a237f1c50 96
Osamu Nakamura 0:813a237f1c50 97 if (!put_res) {
Osamu Nakamura 0:813a237f1c50 98 DEBUG_PRINT("HttpRequest failed (error code %d)\n", put_req->get_error());
Osamu Nakamura 0:813a237f1c50 99 return 1;
Osamu Nakamura 0:813a237f1c50 100 }
Osamu Nakamura 0:813a237f1c50 101
Osamu Nakamura 0:813a237f1c50 102 delete put_req;
Osamu Nakamura 0:813a237f1c50 103 return 0;
Osamu Nakamura 0:813a237f1c50 104 }
Osamu Nakamura 0:813a237f1c50 105
Osamu Nakamura 0:813a237f1c50 106 int iot_get(NetworkInterface *network)
Osamu Nakamura 0:813a237f1c50 107 {
Osamu Nakamura 0:813a237f1c50 108 // Do GET request to IoT Platform
Osamu Nakamura 0:813a237f1c50 109 // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
Osamu Nakamura 0:813a237f1c50 110 // To receive chunked response, pass in a callback as last parameter to the constructor.
Osamu Nakamura 0:813a237f1c50 111 HttpRequest* get_req = new HttpRequest(network, HTTP_GET, get_uri.c_str());
Osamu Nakamura 0:813a237f1c50 112 get_req->set_header("Authorization", ACCESS_CODE);
Osamu Nakamura 0:813a237f1c50 113
Osamu Nakamura 0:813a237f1c50 114 HttpResponse* get_res = get_req->send();
Osamu Nakamura 0:813a237f1c50 115
Osamu Nakamura 0:813a237f1c50 116 if (!get_res) {
Osamu Nakamura 0:813a237f1c50 117 DEBUG_PRINT("HttpRequest failed (error code %d)\n", get_req->get_error());
Osamu Nakamura 0:813a237f1c50 118 return 1;
Osamu Nakamura 0:813a237f1c50 119 }
Osamu Nakamura 0:813a237f1c50 120
Osamu Nakamura 0:813a237f1c50 121 DEBUG_PRINT("\n----- HTTP GET response -----\n");
Osamu Nakamura 0:813a237f1c50 122
Osamu Nakamura 0:813a237f1c50 123 delete get_req;
Osamu Nakamura 0:813a237f1c50 124
Osamu Nakamura 0:813a237f1c50 125 return 0;
Osamu Nakamura 0:813a237f1c50 126 }
Osamu Nakamura 0:813a237f1c50 127
Osamu Nakamura 0:813a237f1c50 128 int send_hvc_info(NetworkInterface *network)
Osamu Nakamura 0:813a237f1c50 129 {
Osamu Nakamura 0:813a237f1c50 130 /* No face detect */
Osamu Nakamura 0:813a237f1c50 131 if (result_hvcp2_fd_cnt == 0) {
Osamu Nakamura 0:813a237f1c50 132 /* Do nothing */
Osamu Nakamura 0:813a237f1c50 133 } else {
Osamu Nakamura 0:813a237f1c50 134 for (uint32_t i = 0; i < result_hvcp2_fd_cnt; i++) {
Osamu Nakamura 0:813a237f1c50 135 /* picojson-object clear */
Osamu Nakamura 0:813a237f1c50 136 o_fd[i].clear();
Osamu Nakamura 0:813a237f1c50 137 o_fr[i].clear();
Osamu Nakamura 0:813a237f1c50 138 o_scr[i].clear();
Osamu Nakamura 0:813a237f1c50 139 /* Type */
Osamu Nakamura 0:813a237f1c50 140 o_fd[i]["RecordType"] = picojson::value((string)"HVC-P2(face)");
Osamu Nakamura 0:813a237f1c50 141 o_fd[i]["id"] = picojson::value((string) "0001-0005");
Osamu Nakamura 0:813a237f1c50 142 /* Age */
Osamu Nakamura 0:813a237f1c50 143 o_fd[i]["Age"] = picojson::value((double)result_hvcp2_fd[i].age.age);
Osamu Nakamura 0:813a237f1c50 144 /* Gender */
Osamu Nakamura 0:813a237f1c50 145 o_fd[i]["Gender"] = picojson::value((double)result_hvcp2_fd[i].gender.gender);
Osamu Nakamura 0:813a237f1c50 146 /* FaceRectangle */
Osamu Nakamura 0:813a237f1c50 147 o_fr[i]["Top"] = picojson::value((double)result_hvcp2_fd[i].face_rectangle.MinY);
Osamu Nakamura 0:813a237f1c50 148 o_fr[i]["Left"] = picojson::value((double)result_hvcp2_fd[i].face_rectangle.MinX);
Osamu Nakamura 0:813a237f1c50 149 o_fr[i]["Width"] = picojson::value((double)result_hvcp2_fd[i].face_rectangle.Width);
Osamu Nakamura 0:813a237f1c50 150 o_fr[i]["Height"] = picojson::value((double)result_hvcp2_fd[i].face_rectangle.Height);
Osamu Nakamura 0:813a237f1c50 151 /* Scores */
Osamu Nakamura 0:813a237f1c50 152 o_scr[i]["Neutral"] = picojson::value((double)result_hvcp2_fd[i].scores.score_neutral);
Osamu Nakamura 0:813a237f1c50 153 o_scr[i]["Anger"] = picojson::value((double)result_hvcp2_fd[i].scores.score_anger);
Osamu Nakamura 0:813a237f1c50 154 o_scr[i]["Happiness"] = picojson::value((double)result_hvcp2_fd[i].scores.score_happiness);
Osamu Nakamura 0:813a237f1c50 155 o_scr[i]["Surprise"] = picojson::value((double)result_hvcp2_fd[i].scores.score_surprise);
Osamu Nakamura 0:813a237f1c50 156 o_scr[i]["Sadness"] = picojson::value((double)result_hvcp2_fd[i].scores.score_sadness);
Osamu Nakamura 0:813a237f1c50 157 /* insert 2 structures */
Osamu Nakamura 0:813a237f1c50 158 o_fd[i]["FaceRectangle"] = picojson::value(o_fr[i]);
Osamu Nakamura 0:813a237f1c50 159 o_fd[i]["Scores"] = picojson::value(o_scr[i]);
Osamu Nakamura 0:813a237f1c50 160 }
Osamu Nakamura 0:813a237f1c50 161 }
Osamu Nakamura 0:813a237f1c50 162
Osamu Nakamura 0:813a237f1c50 163 /* No body detect */
Osamu Nakamura 0:813a237f1c50 164 if (result_hvcp2_bd_cnt == 0) {
Osamu Nakamura 0:813a237f1c50 165 /* Do nothing */
Osamu Nakamura 0:813a237f1c50 166 } else {
Osamu Nakamura 0:813a237f1c50 167 for (uint32_t i = 0; i < result_hvcp2_bd_cnt; i++) {
Osamu Nakamura 0:813a237f1c50 168 /* picojson-object clear */
Osamu Nakamura 0:813a237f1c50 169 o_bd[i].clear();
Osamu Nakamura 0:813a237f1c50 170 /* Type */
Osamu Nakamura 0:813a237f1c50 171 o_bd[i]["RecordType"] = picojson::value((string)"HVC-P2(body)");
Osamu Nakamura 0:813a237f1c50 172 o_bd[i]["id"] = picojson::value((string)"0001-0006");
Osamu Nakamura 0:813a237f1c50 173 /* BodyRectangle */
Osamu Nakamura 0:813a237f1c50 174 o_bd[i]["Top"] = picojson::value((double)result_hvcp2_bd[i].body_rectangle.MinY);
Osamu Nakamura 0:813a237f1c50 175 o_bd[i]["Left"] = picojson::value((double)result_hvcp2_bd[i].body_rectangle.MinX);
Osamu Nakamura 0:813a237f1c50 176 o_bd[i]["Width"] = picojson::value((double)result_hvcp2_bd[i].body_rectangle.Width);
Osamu Nakamura 0:813a237f1c50 177 o_bd[i]["Height"] = picojson::value((double)result_hvcp2_bd[i].body_rectangle.Height);
Osamu Nakamura 0:813a237f1c50 178 }
Osamu Nakamura 0:813a237f1c50 179 }
Osamu Nakamura 0:813a237f1c50 180
Osamu Nakamura 0:813a237f1c50 181 DEBUG_PRINT("Face detect count : %d\n", result_hvcp2_fd_cnt);
Osamu Nakamura 0:813a237f1c50 182 DEBUG_PRINT("Body detect count : %d\n", result_hvcp2_bd_cnt);
Osamu Nakamura 0:813a237f1c50 183
Osamu Nakamura 0:813a237f1c50 184 http_resp_time.reset();
Osamu Nakamura 0:813a237f1c50 185 http_resp_time.start();
Osamu Nakamura 0:813a237f1c50 186
Osamu Nakamura 0:813a237f1c50 187 /* send data */
Osamu Nakamura 0:813a237f1c50 188 if (result_hvcp2_fd_cnt == 0) {
Osamu Nakamura 0:813a237f1c50 189 /* No need to send data */
Osamu Nakamura 0:813a237f1c50 190 } else {
Osamu Nakamura 0:813a237f1c50 191 for (uint32_t i = 0; i < result_hvcp2_fd_cnt; i++) {
Osamu Nakamura 0:813a237f1c50 192 iot_put(network, o_fd[i]);
Osamu Nakamura 0:813a237f1c50 193 }
Osamu Nakamura 0:813a237f1c50 194 }
Osamu Nakamura 0:813a237f1c50 195 if (result_hvcp2_bd_cnt == 0) {
Osamu Nakamura 0:813a237f1c50 196 /* No need to send data */
Osamu Nakamura 0:813a237f1c50 197 } else {
Osamu Nakamura 0:813a237f1c50 198 for (uint32_t i = 0; i < result_hvcp2_bd_cnt; i++) {
Osamu Nakamura 0:813a237f1c50 199 iot_put(network, o_bd[i]);
Osamu Nakamura 0:813a237f1c50 200 }
Osamu Nakamura 0:813a237f1c50 201 }
Osamu Nakamura 0:813a237f1c50 202 DEBUG_PRINT("iot_put() Response time:%dms\n", http_resp_time.read_ms());
Osamu Nakamura 0:813a237f1c50 203 return 0;
Osamu Nakamura 0:813a237f1c50 204 }
Osamu Nakamura 0:813a237f1c50 205
Osamu Nakamura 0:813a237f1c50 206 void iot_ready_task(void)
Osamu Nakamura 0:813a237f1c50 207 {
Osamu Nakamura 0:813a237f1c50 208
Osamu Nakamura 0:813a237f1c50 209 /* Initialize http */
Osamu Nakamura 0:813a237f1c50 210 NetworkInterface *network = easy_connect(true);
Osamu Nakamura 0:813a237f1c50 211 MBED_ASSERT(network);
Osamu Nakamura 0:813a237f1c50 212
Osamu Nakamura 0:813a237f1c50 213 #ifdef ENABLED_NTP
Osamu Nakamura 0:813a237f1c50 214 // Generate the string indicating the date and hour specified for PUT request
Osamu Nakamura 0:813a237f1c50 215 NTPClient ntp;
Osamu Nakamura 0:813a237f1c50 216 time_t ctTime;
Osamu Nakamura 0:813a237f1c50 217 struct tm *pnow;
Osamu Nakamura 0:813a237f1c50 218 NTPResult ret;
Osamu Nakamura 0:813a237f1c50 219
Osamu Nakamura 0:813a237f1c50 220 ret = ntp.setTime("ntp.nict.jp");
Osamu Nakamura 0:813a237f1c50 221 MBED_ASSERT( ret==0 );
Osamu Nakamura 0:813a237f1c50 222
Osamu Nakamura 0:813a237f1c50 223 ctTime = time(NULL);
Osamu Nakamura 0:813a237f1c50 224 #endif // Enabled_NTP
Osamu Nakamura 0:813a237f1c50 225
Osamu Nakamura 0:813a237f1c50 226 while (1) {
Osamu Nakamura 0:813a237f1c50 227
Osamu Nakamura 0:813a237f1c50 228 semaphore_wait_ret = iot_ready_semaphore.wait();
Osamu Nakamura 0:813a237f1c50 229 MBED_ASSERT(semaphore_wait_ret != -1);
Osamu Nakamura 0:813a237f1c50 230
Osamu Nakamura 0:813a237f1c50 231 /* send hvc-p2 data */
Osamu Nakamura 0:813a237f1c50 232 http_resp_time.reset();
Osamu Nakamura 0:813a237f1c50 233 http_resp_time.start();
Osamu Nakamura 0:813a237f1c50 234 send_hvc_info(network);
Osamu Nakamura 0:813a237f1c50 235 DEBUG_PRINT("send_hvc_info() Response time:%dms\n", http_resp_time.read_ms());
Osamu Nakamura 0:813a237f1c50 236
Osamu Nakamura 0:813a237f1c50 237 iot_ready_semaphore.release();
Osamu Nakamura 0:813a237f1c50 238
Osamu Nakamura 0:813a237f1c50 239 Thread::wait(WAIT_TIME);
Osamu Nakamura 0:813a237f1c50 240 };
Osamu Nakamura 0:813a237f1c50 241 }