Example programs for GR-MANGO
Dependencies: opencv-lib mbed-http
This is a collection of sample programs that work on RZ/A2M boards. You can try Mbed OS for RZ/A2M with GR-MANGO board.
Overview
Sample program files are located under the sample_programs
folder.
You can try each sample program by changing the following macro in sample_select.h
.
insample_select.h
#define SAMPLE_PROGRAM_NO 0
No. | Program file | Description |
---|---|---|
0 | sample_00_led_rtc_analogin.cpp | DigitalOut, InterruptIn, RTC, Timer and AnalogIn |
1 | sample_01_flash_write.cpp | FlashAPI sample |
2 | sample_02_ssif_loop_back.cpp | SSIF loop back sample |
4 | sample_04_ssif_wav_playback.cpp | SSIF wav playback sample (use USB memory or SD card) |
7 | sample_07_usb_func_serial.cpp | USBSerial (CDC) sample |
8 | sample_08_usb_func_mouse.cpp | USBMouse sample |
9 | sample_09_usb_func_keyboard.cpp | USBKeyboard sample |
10 | sample_10_usb_func_midi.cpp | USBMIDI sample |
11 | sample_11_usb_func_audio_1.cpp | USBAudio sample |
12 | sample_12_usb_func_audio_2.cpp | USBAudio and SSIF sample |
13 | sample_13_ether_http.cpp | Ether HTTP sample |
14 | sample_14_ether_https.cpp | Ether HTTPS sample |
16 | sample_16_usb_func_msd_1.cpp | USBMSD and FlashAPI sample |
17 | sample_17_usb_func_msd_2.cpp | USBMSD and FlashAPI sample advanced version |
18 | sample_18_mipi_drp_lcd.cpp | MIPI, DRP and LCD sample |
19 | sample_19_mipi_drp_diplayapp.cpp | MIPI, DRP and USBSerial (CDC) sample (use "DisplayApp") |
20 | sample_20_drp_dynamic_loading.cpp | DRP Dynamic Loading Sample |
21 | sample_21_deep_standby_alarm.cpp | Deep standby and RTC alarm sample |
22 | sample_22_hdmi_disp_ssif.cpp | HDMI output and SSIF wav playback Sample |
23 | sample_23_mipi_hdmi.cpp | HDMI output and MIPI Sample |
24 | sample_24_facedetection.cpp | HDMI output and face detection using OpenCV |
25 | sample_25_hdmi_mouse.cpp | HDMI output and Mouse Sample |
Notice
sample_24_facedetection.cpp
only can be compiled with GNU Compiler Collection.
About sample_24_facedetection.cpp
, this is a demonstration that can detect the face of a person without a mask. It will surround the face of a person without a mask with a red rectangle and sound alarm at the same time. To use OpenCV for face recognition, you need to prepare the followings:
・USB drive or SD card
・ Raspberry Pi Camera Module V2
・ HDMI monitor
Perform the following steps to complete face recognition sample.
1. Copy the lbpcascade_frontalface.xml to the root folder of USB drive or SD card and save it.
2. Copy the alarm.wav to the root folder of USB drive or SD card and save it.
3. Set "camera-type" value to "CAMERA_RASPBERRY_PI_832X480" in mbed_app.json
About custom boot loaders
This sample uses custom bootloader
revision 5
, and you can drag & drop the "xxxx_application.bin" file to write the program. Please see here for the detail.
How to write program
When using DAPLink
, please use xxxx.bin
as following.
- Connect the
micro USB type B terminal
to the PC using a USB cable. - You can find the
MBED
directory. - Drag & drop
xxxx.bin
to theMBED
directory. - When writing is completed, press the reset button.
When using custom bootloader
, please use xxxx_application.bin
as following.
- Connect the
USB type C terminal
to the PC using a USB cable. - Hold down
USB0
and press the reset button. - You can find the
GR-MANG
directory. - Drag & drop xxxx_application.bin to the GR-MANGO directory.
When writing is completed, press the reset button.
Attention!
For the first time only, you need to write a custom bootloader
using DAPLink
.
Terminal setting
If you want to confirm the serial communication the terminal soft on your PC, please specify the below values.
You can change the baud rate by platform.stio-baud-rate
of mbed_app.json
.
Baud rate | 115,200 |
Data | 8bit |
Parity | none |
Stop | 1bit |
Flow control | none |
sample_programs/sample_14_ether_https.cpp@16:f4798796b4a2, 2021-03-04 (annotated)
- Committer:
- luyao@os.mbed.com
- Date:
- Thu Mar 04 18:22:21 2021 +0900
- Revision:
- 16:f4798796b4a2
- Parent:
- 4:2da9e0f275a1
Modified EP952 Parameters.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 1 | /******************************************************************************* |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 2 | * DISCLAIMER |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 4 | * intended for use with Renesas products. No other uses are authorized. This |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 6 | * all applicable laws, including copyright laws. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 16 | * Renesas reserves the right, without notice, to make changes to this software |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 17 | * and to discontinue the availability of this software. By using this software, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 18 | * you agree to the additional terms and conditions found by accessing the |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 19 | * following link: |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 20 | * http://www.renesas.com/disclaimer |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 21 | * |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 22 | * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 23 | *******************************************************************************/ |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 24 | #include "sample_select.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 25 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 26 | #if (SAMPLE_PROGRAM_NO == 14) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 27 | // SAMPLE_PROGRAM_NO 14 : Ether HTTPS sample |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 28 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 29 | #if defined(TARGET_SEMB1402) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 30 | #error "Ether is not supported." |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 31 | #endif |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 32 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 33 | #include "mbed.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 34 | #include "https_request.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 35 | #include "EthernetInterface.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 36 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 37 | EthernetInterface eth; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 38 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 39 | /* List of trusted root CA certificates |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 40 | * |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 41 | * - Amazon, the CA for os.mbed.com |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 42 | * - Let's Encrypt, the CA for httpbin.org |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 43 | * - Comodo, the CA for reqres.in |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 44 | * |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 45 | * To add more root certificates, just concatenate them. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 46 | */ |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 47 | const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 48 | "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 49 | "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 50 | "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 51 | "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 52 | "b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 53 | "ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 54 | "9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 55 | "IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 56 | "VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 57 | "93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 58 | "jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 59 | "AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 60 | "A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 61 | "U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 62 | "N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 63 | "o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 64 | "5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 65 | "rqXRfboQnoZsG4q5WTP468SQvvG5\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 66 | "-----END CERTIFICATE-----\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 67 | "-----BEGIN CERTIFICATE-----\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 68 | "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 69 | "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 70 | "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 71 | "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 72 | "GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 73 | "AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 74 | "q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 75 | "SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 76 | "Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 77 | "a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 78 | "/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 79 | "AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 80 | "CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 81 | "bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 82 | "c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 83 | "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 84 | "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 85 | "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 86 | "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 87 | "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 88 | "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 89 | "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 90 | "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 91 | "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 92 | "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 93 | "-----END CERTIFICATE-----\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 94 | "-----BEGIN CERTIFICATE-----\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 95 | "MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTEL\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 96 | "MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 97 | "BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMT\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 98 | "IkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDgwMzA2MDAw\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 99 | "MDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdy\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 100 | "ZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09N\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 101 | "T0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlv\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 102 | "biBBdXRob3JpdHkwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQDR3svdcmCFYX7deSR\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 103 | "FtSrYpn1PlILBs5BAH+X4QokPB0BBO490o0JlwzgdeT6+3eKKvUDYEs2ixYjFq0J\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 104 | "cfRK9ChQtP6IHG4/bC8vCVlbpVsLM5niwz2J+Wos77LTBumjQjBAMB0GA1UdDgQW\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 105 | "BBR1cacZSBm8nZ3qQUfflMRId5nTeTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 106 | "BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA7wNbeqy3eApyt4jf/7VGFAkK+qDm\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 107 | "fQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdv\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 108 | "GDeAU/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY=\n" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 109 | "-----END CERTIFICATE-----\n"; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 110 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 111 | void dump_response(HttpResponse* res) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 112 | mbedtls_printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str()); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 113 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 114 | mbedtls_printf("Headers:\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 115 | for (size_t ix = 0; ix < res->get_headers_length(); ix++) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 116 | mbedtls_printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str()); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 117 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 118 | mbedtls_printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str()); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 119 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 120 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 121 | int main() { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 122 | NetworkInterface* network = ð |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 123 | SocketAddress address; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 124 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 125 | printf("\nConnecting...\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 126 | int ret = network->connect(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 127 | if (ret != 0) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 128 | printf("\nConnection error\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 129 | return -1; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 130 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 131 | printf("Success\n\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 132 | printf("MAC: %s\n", network->get_mac_address()); |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 133 | printf("IP: %s\n" , NSAPI_ERROR_OK == network->get_ip_address(&address) ? address.get_ip_address() : "NULL"); |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 134 | printf("Netmask: %s\n", NSAPI_ERROR_OK == network->get_netmask(&address) ? address.get_ip_address() : "NULL"); |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 135 | printf("Gateway: %s\n", NSAPI_ERROR_OK == network->get_gateway(&address) ? address.get_ip_address() : "NULL"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 136 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 137 | // GET request to developer.mbed.org |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 138 | { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 139 | printf("\n----- HTTPS GET request -----\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 140 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 141 | HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://os.mbed.com/media/uploads/mbed_official/hello.txt"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 142 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 143 | HttpResponse* get_res = get_req->send(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 144 | if (!get_res) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 145 | printf("HttpRequest failed (error code %d)\n", get_req->get_error()); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 146 | return 1; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 147 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 148 | printf("\n----- HTTPS GET response -----\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 149 | dump_response(get_res); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 150 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 151 | delete get_req; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 152 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 153 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 154 | // POST request to httpbin.org |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 155 | { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 156 | printf("\n----- HTTPS POST request -----\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 157 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 158 | HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://httpbin.org/post"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 159 | post_req->set_header("Content-Type", "application/json"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 160 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 161 | const char body[] = "{\"hello\":\"world\"}"; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 162 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 163 | HttpResponse* post_res = post_req->send(body, strlen(body)); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 164 | if (!post_res) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 165 | printf("HttpRequest failed (error code %d)\n", post_req->get_error()); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 166 | return 1; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 167 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 168 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 169 | printf("\n----- HTTPS POST response -----\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 170 | dump_response(post_res); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 171 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 172 | delete post_req; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 173 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 174 | |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 175 | ThisThread::sleep_for(osWaitForever); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 176 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 177 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 178 | #endif |