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 /* NTPClient.h */
Osamu Nakamura 0:813a237f1c50 2 /* Copyright (C) 2012 mbed.org, MIT License
Osamu Nakamura 0:813a237f1c50 3 *
Osamu Nakamura 0:813a237f1c50 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Osamu Nakamura 0:813a237f1c50 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Osamu Nakamura 0:813a237f1c50 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Osamu Nakamura 0:813a237f1c50 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Osamu Nakamura 0:813a237f1c50 8 * furnished to do so, subject to the following conditions:
Osamu Nakamura 0:813a237f1c50 9 *
Osamu Nakamura 0:813a237f1c50 10 * The above copyright notice and this permission notice shall be included in all copies or
Osamu Nakamura 0:813a237f1c50 11 * substantial portions of the Software.
Osamu Nakamura 0:813a237f1c50 12 *
Osamu Nakamura 0:813a237f1c50 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Osamu Nakamura 0:813a237f1c50 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Osamu Nakamura 0:813a237f1c50 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Osamu Nakamura 0:813a237f1c50 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Osamu Nakamura 0:813a237f1c50 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Osamu Nakamura 0:813a237f1c50 18 */
Osamu Nakamura 0:813a237f1c50 19
Osamu Nakamura 0:813a237f1c50 20 /** \file
Osamu Nakamura 0:813a237f1c50 21 NTP Client header file
Osamu Nakamura 0:813a237f1c50 22 */
Osamu Nakamura 0:813a237f1c50 23
Osamu Nakamura 0:813a237f1c50 24 #ifndef NTPCLIENT_H_
Osamu Nakamura 0:813a237f1c50 25 #define NTPCLIENT_H_
Osamu Nakamura 0:813a237f1c50 26 #if !((__cplusplus == 199711L) && !defined (__STRICT_ANSI__))
Osamu Nakamura 0:813a237f1c50 27 #include <cstdint>
Osamu Nakamura 0:813a237f1c50 28
Osamu Nakamura 0:813a237f1c50 29 using std::uint8_t;
Osamu Nakamura 0:813a237f1c50 30 using std::uint16_t;
Osamu Nakamura 0:813a237f1c50 31 using std::uint32_t;
Osamu Nakamura 0:813a237f1c50 32 #endif
Osamu Nakamura 0:813a237f1c50 33 #include "UDPSocket.h"
Osamu Nakamura 0:813a237f1c50 34
Osamu Nakamura 0:813a237f1c50 35 #define NTP_DEFAULT_PORT 123
Osamu Nakamura 0:813a237f1c50 36 #define NTP_DEFAULT_TIMEOUT 4000
Osamu Nakamura 0:813a237f1c50 37
Osamu Nakamura 0:813a237f1c50 38 ///NTP client results
Osamu Nakamura 0:813a237f1c50 39 enum NTPResult
Osamu Nakamura 0:813a237f1c50 40 {
Osamu Nakamura 0:813a237f1c50 41 NTP_DNS, ///<Could not resolve name
Osamu Nakamura 0:813a237f1c50 42 NTP_PRTCL, ///<Protocol error
Osamu Nakamura 0:813a237f1c50 43 NTP_TIMEOUT, ///<Connection timeout
Osamu Nakamura 0:813a237f1c50 44 NTP_CONN, ///<Connection error
Osamu Nakamura 0:813a237f1c50 45 NTP_OK = 0, ///<Success
Osamu Nakamura 0:813a237f1c50 46 };
Osamu Nakamura 0:813a237f1c50 47
Osamu Nakamura 0:813a237f1c50 48 /** NTP Client to update the mbed's RTC using a remote time server
Osamu Nakamura 0:813a237f1c50 49 *
Osamu Nakamura 0:813a237f1c50 50 */
Osamu Nakamura 0:813a237f1c50 51 class NTPClient
Osamu Nakamura 0:813a237f1c50 52 {
Osamu Nakamura 0:813a237f1c50 53 public:
Osamu Nakamura 0:813a237f1c50 54 /**
Osamu Nakamura 0:813a237f1c50 55 Instantiate the NTP client
Osamu Nakamura 0:813a237f1c50 56 */
Osamu Nakamura 0:813a237f1c50 57 NTPClient();
Osamu Nakamura 0:813a237f1c50 58
Osamu Nakamura 0:813a237f1c50 59 /**Get current time (blocking)
Osamu Nakamura 0:813a237f1c50 60 Update the time using the server host
Osamu Nakamura 0:813a237f1c50 61 Blocks until completion
Osamu Nakamura 0:813a237f1c50 62 @param host NTP server IPv4 address or hostname (will be resolved via DNS)
Osamu Nakamura 0:813a237f1c50 63 @param port port to use; defaults to 123
Osamu Nakamura 0:813a237f1c50 64 @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
Osamu Nakamura 0:813a237f1c50 65 @return 0 on success, NTP error code (<0) on failure
Osamu Nakamura 0:813a237f1c50 66 */
Osamu Nakamura 0:813a237f1c50 67 NTPResult setTime(const char* host, uint16_t port = NTP_DEFAULT_PORT, uint32_t timeout = NTP_DEFAULT_TIMEOUT); //Blocking
Osamu Nakamura 0:813a237f1c50 68
Osamu Nakamura 0:813a237f1c50 69 private:
Osamu Nakamura 0:813a237f1c50 70 struct NTPPacket //See RFC 4330 for Simple NTP
Osamu Nakamura 0:813a237f1c50 71 {
Osamu Nakamura 0:813a237f1c50 72 //WARN: We are in LE! Network is BE!
Osamu Nakamura 0:813a237f1c50 73 //LSb first
Osamu Nakamura 0:813a237f1c50 74 unsigned mode : 3;
Osamu Nakamura 0:813a237f1c50 75 unsigned vn : 3;
Osamu Nakamura 0:813a237f1c50 76 unsigned li : 2;
Osamu Nakamura 0:813a237f1c50 77
Osamu Nakamura 0:813a237f1c50 78 uint8_t stratum;
Osamu Nakamura 0:813a237f1c50 79 uint8_t poll;
Osamu Nakamura 0:813a237f1c50 80 uint8_t precision;
Osamu Nakamura 0:813a237f1c50 81 //32 bits header
Osamu Nakamura 0:813a237f1c50 82
Osamu Nakamura 0:813a237f1c50 83 uint32_t rootDelay;
Osamu Nakamura 0:813a237f1c50 84 uint32_t rootDispersion;
Osamu Nakamura 0:813a237f1c50 85 uint32_t refId;
Osamu Nakamura 0:813a237f1c50 86
Osamu Nakamura 0:813a237f1c50 87 uint32_t refTm_s;
Osamu Nakamura 0:813a237f1c50 88 uint32_t refTm_f;
Osamu Nakamura 0:813a237f1c50 89 uint32_t origTm_s;
Osamu Nakamura 0:813a237f1c50 90 uint32_t origTm_f;
Osamu Nakamura 0:813a237f1c50 91 uint32_t rxTm_s;
Osamu Nakamura 0:813a237f1c50 92 uint32_t rxTm_f;
Osamu Nakamura 0:813a237f1c50 93 uint32_t txTm_s;
Osamu Nakamura 0:813a237f1c50 94 uint32_t txTm_f;
Osamu Nakamura 0:813a237f1c50 95 } __attribute__ ((packed));
Osamu Nakamura 0:813a237f1c50 96
Osamu Nakamura 0:813a237f1c50 97 UDPSocket m_sock;
Osamu Nakamura 0:813a237f1c50 98
Osamu Nakamura 0:813a237f1c50 99 };
Osamu Nakamura 0:813a237f1c50 100
Osamu Nakamura 0:813a237f1c50 101
Osamu Nakamura 0:813a237f1c50 102 #endif /* NTPCLIENT_H_ */
Osamu Nakamura 0:813a237f1c50 103