thingspark example
Dependencies: MbedJSONValue mbed-http HTS221
Revision 38:7734b54de565, committed 2019-12-28
- Comitter:
- master_k1
- Date:
- Sat Dec 28 07:53:23 2019 +0000
- Parent:
- 37:e809fd407dc9
- Child:
- 39:9856f09a1333
- Commit message:
- add thingspark api example
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Sat Dec 28 07:53:23 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/samux/code/MbedJSONValue/#10a99cdf7846
--- a/mbed-os.lib Mon Oct 21 11:56:25 2019 +0000 +++ b/mbed-os.lib Sat Dec 28 07:53:23 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0 +https://github.com/ARMmbed/mbed-os/#bacf37894945a5c9b7619b709eeabeeb68d25d9c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/channel-entrys.cpp Sat Dec 28 07:53:23 2019 +0000
@@ -0,0 +1,132 @@
+#include "select-demo.h"
+
+#if DEMO == DEMO_CHANNEL_ENTRYS
+
+#include "mbed.h"
+#include "https_request.h"
+#include "network-helper.h"
+#include "mbed_mem_trace.h"
+
+char* thingspark_URL = "http://api.thingspark.kr";
+char* thingspark_APIkey = "1yUxh3Dh77DUQyOt";
+char urlBuffer[256];
+
+/* List of trusted root CA certificates
+ * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
+ *
+ * To add more root certificates, just concatenate them.
+ */
+const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
+ "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n"
+ "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
+ "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMF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\n"
+ "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n"
+ "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n"
+ "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n"
+ "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n"
+ "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n"
+ "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
+ "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
+ "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
+ "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
+ "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
+ "-----END CERTIFICATE-----\n";
+
+void dump_response(HttpResponse* res) {
+ printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
+
+ printf("Headers:\n");
+ for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
+ printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
+ }
+ printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+}
+
+
+int main() {
+ unsigned int updateCnt=0;
+
+ printf("DISCO-L457VG-IOT01A WiFi + thingspark example\r\n");
+
+#ifdef MBED_MAJOR_VERSION
+ printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+#endif
+
+ printf("<< =========== Network check.. =========== >>\r\n");
+
+ // Connect to the network with the default networking interface
+ // if you use WiFi: see mbed_app.json for the credentials
+ NetworkInterface* network = connect_to_default_network_interface();
+ if (!network) {
+ printf("Cannot connect to the network, see serial output\n");
+ return 1;
+ }
+
+ printf("Successfully access to network\n\n");
+
+ printf("MAC: %s\n", network->get_mac_address());
+ printf("IP: %s\n", network->get_ip_address());
+ printf("Netmask: %s\n", network->get_netmask());
+ printf("Gateway: %s\n", network->get_gateway());
+
+ printf("<< =========== Sensor check.. =========== >>\r\n");
+
+ // Do a GET request to thingspark.kr
+ while(1){
+ // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
+ // To receive chunked response, pass in a callback as last parameter to the constructor.
+
+ sprintf(urlBuffer, "https://api.thingspark.kr/channels/%d/entrys?results=%d", 65550, 10);
+
+ printf("[DEBUG] %s\n", urlBuffer);
+ HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, urlBuffer);
+
+ HttpResponse* get_res = get_req->send();
+ if (!get_res) {
+ printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+ return 1;
+ }
+ printf("\n----- HTTPS GET response -----\n");
+ dump_response(get_res);
+
+ delete get_req;
+
+ wait(10);
+ }
+
+ wait(osWaitForever);
+}
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/channel-field-entrys.cpp Sat Dec 28 07:53:23 2019 +0000
@@ -0,0 +1,152 @@
+#include "select-demo.h"
+
+#if DEMO == DEMO_CHANNEL_FIELD_ENTRYS
+
+#include "mbed.h"
+#include "https_request.h"
+#include "network-helper.h"
+#include "mbed_mem_trace.h"
+#include "MbedJSONValue.h"
+#include <string>
+
+
+
+char* thingspark_URL = "http://api.thingspark.kr";
+char* thingspark_APIkey = "1yUxh3Dh77DUQyOt";
+char urlBuffer[256];
+
+/* List of trusted root CA certificates
+ * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
+ *
+ * To add more root certificates, just concatenate them.
+ */
+const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
+ "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n"
+ "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
+ "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n"
+ "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n"
+ "b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n"
+ "ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n"
+ "9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n"
+ "IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n"
+ "VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n"
+ "93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n"
+ "jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n"
+ "AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n"
+ "A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n"
+ "U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n"
+ "N+g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"AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n"
+ "CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n"
+ "bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n"
+ "c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n"
+ "VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n"
+ "ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n"
+ "MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n"
+ "Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n"
+ "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n"
+ "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
+ "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
+ "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
+ "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
+ "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
+ "-----END CERTIFICATE-----\n";
+
+void dump_response(HttpResponse* res) {
+ printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
+
+ printf("Headers:\n");
+ for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
+ printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
+ }
+
+ const char * json = res->get_body_as_string().c_str();
+
+ printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), json);
+
+/*
+ MbedJSONValue mbedjson;
+
+
+ //parse the previous string and fill the object demo
+ parse(mbedjson, json);
+
+ std::string my_str;
+ my_str = mbedjson["channel"].get<std::string>();
+ printf("channel: %s\r\n", my_str.c_str());
+
+ // channel, entrys[]*/
+}
+
+
+int main() {
+ unsigned int updateCnt=0;
+
+ printf("DISCO-L457VG-IOT01A WiFi + thingspark example\r\n");
+
+#ifdef MBED_MAJOR_VERSION
+ printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+#endif
+
+ printf("<< =========== Network check.. =========== >>\r\n");
+
+ // Connect to the network with the default networking interface
+ // if you use WiFi: see mbed_app.json for the credentials
+ NetworkInterface* network = connect_to_default_network_interface();
+ if (!network) {
+ printf("Cannot connect to the network, see serial output\n");
+ return 1;
+ }
+
+ printf("Successfully access to network\n\n");
+
+ printf("MAC: %s\n", network->get_mac_address());
+ printf("IP: %s\n", network->get_ip_address());
+ printf("Netmask: %s\n", network->get_netmask());
+ printf("Gateway: %s\n", network->get_gateway());
+
+ printf("<< =========== Sensor check.. =========== >>\r\n");
+
+ // Do a GET request to thingspark.kr
+ while(1){
+ // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
+ // To receive chunked response, pass in a callback as last parameter to the constructor.
+
+ sprintf(urlBuffer, "https://api.thingspark.kr/channels/%d/fields/%d?results=%d", 65550, 1, 1);
+
+ printf("[DEBUG] %s\n", urlBuffer);
+ HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, urlBuffer);
+
+ HttpResponse* get_res = get_req->send();
+ if (!get_res) {
+ printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+ return 1;
+ }
+ printf("\n----- HTTPS GET response -----\n");
+ dump_response(get_res);
+
+ delete get_req;
+
+ wait(10);
+ }
+
+ wait(osWaitForever);
+}
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/last-channel-entry.cpp Sat Dec 28 07:53:23 2019 +0000
@@ -0,0 +1,132 @@
+#include "select-demo.h"
+
+#if DEMO == DEMO_LAST_CHANNEL_ENTRY
+
+#include "mbed.h"
+#include "https_request.h"
+#include "network-helper.h"
+#include "mbed_mem_trace.h"
+
+char* thingspark_URL = "http://api.thingspark.kr";
+char* thingspark_APIkey = "1yUxh3Dh77DUQyOt";
+char urlBuffer[256];
+
+/* List of trusted root CA certificates
+ * currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
+ *
+ * To add more root certificates, just concatenate them.
+ */
+const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
+ "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n"
+ "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
+ "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n"
+ "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n"
+ "b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n"
+ "ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n"
+ "9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n"
+ "IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n"
+ "VOujw5H5SNz/0egwLX0td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mtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
+ "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
+ "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
+ "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
+ "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
+ "-----END CERTIFICATE-----\n";
+
+void dump_response(HttpResponse* res) {
+ printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
+
+ printf("Headers:\n");
+ for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
+ printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
+ }
+ printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+}
+
+
+int main() {
+ unsigned int updateCnt=0;
+
+ printf("DISCO-L457VG-IOT01A WiFi + thingspark example\r\n");
+
+#ifdef MBED_MAJOR_VERSION
+ printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+#endif
+
+ printf("<< =========== Network check.. =========== >>\r\n");
+
+ // Connect to the network with the default networking interface
+ // if you use WiFi: see mbed_app.json for the credentials
+ NetworkInterface* network = connect_to_default_network_interface();
+ if (!network) {
+ printf("Cannot connect to the network, see serial output\n");
+ return 1;
+ }
+
+ printf("Successfully access to network\n\n");
+
+ printf("MAC: %s\n", network->get_mac_address());
+ printf("IP: %s\n", network->get_ip_address());
+ printf("Netmask: %s\n", network->get_netmask());
+ printf("Gateway: %s\n", network->get_gateway());
+
+ printf("<< =========== Sensor check.. =========== >>\r\n");
+
+ // Do a GET request to thingspark.kr
+ while(1){
+ // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
+ // To receive chunked response, pass in a callback as last parameter to the constructor.
+
+ sprintf(urlBuffer, "https://api.thingspark.kr/channels/%d/last", 65550);
+
+ printf("[DEBUG] %s\n", urlBuffer);
+ HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, urlBuffer);
+
+ HttpResponse* get_res = get_req->send();
+ if (!get_res) {
+ printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+ return 1;
+ }
+ printf("\n----- HTTPS GET response -----\n");
+ dump_response(get_res);
+
+ delete get_req;
+
+ wait(10);
+ }
+
+ wait(osWaitForever);
+}
+
+#endif
--- a/source/main-http.cpp Mon Oct 21 11:56:25 2019 +0000
+++ b/source/main-http.cpp Sat Dec 28 07:53:23 2019 +0000
@@ -10,9 +10,9 @@
static DevI2C devI2c(PB_11,PB_10);
static HTS221Sensor hum_temp(&devI2c);
-//theKsystemsURL = "https://api.theksystem.com/update?apiKey=9Q8vOz1lguaV6Ou4&field1=21"
+
char* thingspark_URL = "http://api.thingspark.kr";
-char* thingspark_APIkey = "hKqQALm22Hd79N6I";
+char* thingspark_APIkey = "1yUxh3Dh77DUQyOt";
char urlBuffer[256];
void dump_response(HttpResponse* res) {
@@ -84,26 +84,7 @@
printf("\nUpdate count %d (Every 30sec, data update to thingspark server)\n",updateCnt++);
wait(30);
}
-#if 0
- // POST request to httpbin.org
- {
- HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
- post_req->set_header("Content-Type", "application/json");
- const char body[] = "{\"hello\":\"world\"}";
-
- HttpResponse* post_res = post_req->send(body, strlen(body));
- if (!post_res) {
- printf("HttpRequest failed (error code %d)\n", post_req->get_error());
- return 1;
- }
-
- printf("\n----- HTTP POST response -----\n");
- dump_response(post_res);
-
- delete post_req;
- }
-#endif
wait(osWaitForever);
}
--- a/source/main-https.cpp Mon Oct 21 11:56:25 2019 +0000
+++ b/source/main-https.cpp Sat Dec 28 07:53:23 2019 +0000
@@ -8,6 +8,16 @@
#include "mbed_trace.h"
#include "https_request.h"
#include "network-helper.h"
+#include "mbed_mem_trace.h"
+#include "HTS221Sensor.h"
+
+static DevI2C devI2c(PB_11,PB_10);
+static HTS221Sensor hum_temp(&devI2c);
+
+char* thingspark_URL = "https://api.thingspark.kr";
+char* thingspark_APIkey = "1yUxh3Dh77DUQyOt";
+char urlBuffer[256];
+
/* List of trusted root CA certificates
* currently two: Amazon, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
@@ -72,15 +82,59 @@
printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
}
-int main() {
+int main() {
+ unsigned int updateCnt=0;
+ float hum_val=12, temp_val=34;
+
NetworkInterface* network = connect_to_default_network_interface();
if (!network) {
printf("Cannot connect to the network, see serial output\n");
return 1;
}
+
+ printf("Successfully access to network\n\n");
+
+ printf("MAC: %s\n", network->get_mac_address());
+ printf("IP: %s\n", network->get_ip_address());
+ printf("Netmask: %s\n", network->get_netmask());
+ printf("Gateway: %s\n", network->get_gateway());
+
+ printf("<< =========== Sensor check.. =========== >>\r\n");
+
+ hum_temp.init(NULL);
+ hum_temp.enable();
+
+ mbed_trace_init();
+
+ // Do a GET request to thingspark.kr
+ while(1){
+ // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
+ // To receive chunked response, pass in a callback as last parameter to the constructor.
+
+ hum_temp.get_humidity(&hum_val);
+ hum_temp.get_temperature(&temp_val);
+ printf("HT221 hum: %.1f %, temp: %.1f C\n", hum_val, temp_val);
+ sprintf(urlBuffer, "%s/update?apiKey=%s&field1=%.1f&field2=%.1f", thingspark_URL, thingspark_APIkey, hum_val, temp_val);
+
+ printf("[DEBUG] %s\n", urlBuffer);
+
+ HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, urlBuffer);
- mbed_trace_init();
+ HttpResponse* get_res = get_req->send();
+ if (!get_res) {
+ printf("HttpRequest failed (error code %d)\n", get_req->get_error());
+ return 1;
+ }
+ printf("\n----- HTTPS GET response -----\n");
+ dump_response(get_res);
+
+ delete get_req;
+ printf("\nUpdate count %d (Every 30sec, data update to thingspark server)\n", updateCnt++);
+ wait(30);
+ }
+
+#if 0
// GET request to os.mbed.com
{
printf("\n----- HTTPS GET request -----\n");
@@ -118,6 +172,7 @@
delete post_req;
}
+#endif
wait(osWaitForever);
}
--- a/source/select-demo.h Mon Oct 21 11:56:25 2019 +0000 +++ b/source/select-demo.h Sat Dec 28 07:53:23 2019 +0000 @@ -2,13 +2,12 @@ #define _SELECT_METHOD_H_ #define DEMO_HTTP 1 -#define DEMO_HTTP_SOCKET_REUSE 2 -#define DEMO_HTTP_IPV6 3 -#define DEMO_HTTPS 4 -#define DEMO_HTTPS_SOCKET_REUSE 5 -#define DEMO_HTTPS_CHUNKED_REQUEST 6 -#define DEMO_TESTS 7 +#define DEMO_HTTPS 2 +#define DEMO_CHANNEL_ENTRYS 3 +#define DEMO_LAST_CHANNEL_ENTRY 4 +#define DEMO_CHANNEL_FIELD_ENTRYS 5 -#define DEMO DEMO_HTTP + +#define DEMO DEMO_CHANNEL_FIELD_ENTRYS #endif // _SELECT_METHOD_H_
--- a/wifi-ism43362.lib Mon Oct 21 11:56:25 2019 +0000 +++ b/wifi-ism43362.lib Sat Dec 28 07:53:23 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/wifi-ism43362/#66d17b95a60aa53ccf775c9942997d7a2178ef56 +https://github.com/ARMmbed/wifi-ism43362/#31e1c8c6fa0ab4bc2f0291bd4fa5890ea7012947