NuMaker connection with AWS IoT thru MQTT/HTTPS

Dependencies:   MQTT_ON_AWS

Revision:
39:a26be070a2b1
Parent:
36:1bec082ad582
--- a/main.cpp	Fri Apr 10 10:51:49 2020 +0800
+++ b/main.cpp	Tue Dec 01 03:25:48 2020 +0000
@@ -33,92 +33,86 @@
  * To add more than one root, just concatenate them.
  */
 const char SSL_CA_CERT_PEM[] = "-----BEGIN CERTIFICATE-----\n"
-    "MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB\n"
-    "yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL\n"
-    "ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp\n"
-    "U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW\n"
-    "ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0\n"
-    "aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL\n"
-    "MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW\n"
-    "ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln\n"
-    "biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp\n"
-    "U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y\n"
-    "aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1\n"
-    "nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0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6XU\n"
+"5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n"
+"rqXRfboQnoZsG4q5WTP468SQvvG5\n"
+"-----END CERTIFICATE-----\n";
 
 /* User certificate which has been activated and attached with specific thing and policy */
 const char SSL_USER_CERT_PEM[] = "-----BEGIN CERTIFICATE-----\n"
-    "MIIDWTCCAkGgAwIBAgIUAzDIpEQWV/yKVo8suGhvjmFY0n4wDQYJKoZIhvcNAQEL\n"
-    "BQAwTTFLMEkGA1UECwxCQW1hem9uIFdlYiBTZXJ2aWNlcyBPPUFtYXpvbi5jb20g\n"
-    "SW5jLiBMPVNlYXR0bGUgU1Q9V2FzaGluZ3RvbiBDPVVTMB4XDTE4MDQxNzA5NDMx\n"
-    "M1oXDTQ5MTIzMTIzNTk1OVowHjEcMBoGA1UEAwwTQVdTIElvVCBDZXJ0aWZpY2F0\n"
-    "ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKsLlECiw4ud5laejJmL\n"
-    "bBhafKLdCRx6tkcjBYyEUoAC3Qs2ogqGngQgjU4QJoWpEBO/U1M+e1QtlZ2o/CiL\n"
-    "MViHA3rYvP86N/TH8pFA3aPKaeEp+WIt5v4OXdfPkVNKTotiRuRCpzRzrY4xKp11\n"
-    "ouKkVKf3FcNuKIMt/uEhje90KofBbFHQY3HFYe19qIg1m/IBV+npmNlAKElGNSB7\n"
-    "xHHLzzUuue38s+ceJyzsWuPjFiVYoeyPHF8gDVWf28XJ4KUFs80Deycqe9efroud\n"
-    "cQY/6aLDWDJXHvhenwoAIbHqUsYRoWoanrg5Cq3id5+pzVkadNV3+x9bGwROhpbQ\n"
-    "M9ECAwEAAaNgMF4wHwYDVR0jBBgwFoAUVUXg3+Dd1qSnAT9LN413zSdNoE0wHQYD\n"
-    "VR0OBBYEFIx86SOxw5k/50GtyRjUwlj+9d1gMAwGA1UdEwEB/wQCMAAwDgYDVR0P\n"
-    "AQH/BAQ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"pgrm54Jwf/xKkGwQ4vgeH2EJ+ksBa8Eg5KiLQH9OjZ9BKoeyAPyLQhF642VQmSU3\n"
+"20obAgMBAAGjYDBeMB8GA1UdIwQYMBaAFN50owFGEDexb9nOdsgXxQ+BchtzMB0G\n"
+"A1UdDgQWBBReXbnLWekyRBvkd4YfTePGd7sXIzAMBgNVHRMBAf8EAjAAMA4GA1Ud\n"
+"DwEB/wQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEAf9+gOAOTo22Oo+mpcf6SAADw\n"
+"tN+fInVMgLLW13ViB7dELAYx4YcrPRRrxK6KOQbNeFj62jOon7Zj7GQyFUAG6ePw\n"
+"TUEyuAvYNltYfF2OjsLu7XFrtM8RhmKUOKpP3WJ8AiZvnzknYcdPvAbka8TRK9zC\n"
+"13xouOMkrWD6BY+FPe+xrsCHeJAVpaCRJBLWnkMaR1fyMsL8xGBkFz02BPTO70cN\n"
+"rmVh/dbJz9JifedlcK0ZjfpU3EfiLZ/ydZWqEc2M6VGO0sLOfIahHhqKPq6hbiUu\n"
+"WiwB/ZhYjJI0vQm3/mzTXTEwSwBcRvQusoctZS6Ilb9W9KNttXtQZ5Pd+iWDAw==\n"
+"-----END CERTIFICATE-----\n";
 
 /* User private key paired with above */
 const char SSL_USER_PRIV_KEY_PEM[] = "-----BEGIN RSA PRIVATE KEY-----\n"
-    "MIIEowIBAAKCAQEAqwuUQKLDi53mVp6MmYtsGFp8ot0JHHq2RyMFjIRSgALdCzai\n"
-    "CoaeBCCNThAmhakQE79TUz57VC2Vnaj8KIsxWIcDeti8/zo39MfykUDdo8pp4Sn5\n"
-    "Yi3m/g5d18+RU0pOi2JG5EKnNHOtjjEqnXWi4qRUp/cVw24ogy3+4SGN73Qqh8Fs\n"
-    "UdBjccVh7X2oiDWb8gFX6emY2UAoSUY1IHvEccvPNS657fyz5x4nLOxa4+MWJVih\n"
-    "7I8cXyANVZ/bxcngpQWzzQN7Jyp715+ui51xBj/posNYMlce+F6fCgAhsepSxhGh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T_TEST
 
-#define AWS_IOT_MQTT_SERVER_NAME                "a1fljoeglhtf61.iot.us-east-2.amazonaws.com"
+#define AWS_IOT_MQTT_SERVER_NAME              "a13s4t1vh7t3tu-ats.iot.ap-northeast-1.amazonaws.com"
+//  "a1fljoeglhtf61.iot.us-east-2.amazonaws.com"
+
 #define AWS_IOT_MQTT_SERVER_PORT                8883
 
-#define AWS_IOT_MQTT_THINGNAME                  "Nuvoton-Mbed-D001"
-#define AWS_IOT_MQTT_CLIENTNAME                 "Nuvoton Client"
+#define AWS_IOT_MQTT_THINGNAME                  "M487_TYH_TEST"
+#define AWS_IOT_MQTT_CLIENTNAME                 "TYH_IOT"
 
 /* User self-test topic */
 const char USER_MQTT_TOPIC[] = "Nuvoton/Mbed/D001";