Initial setup for TheKsystem.

Dependencies:   mbed-http HTS221

Files at this revision

API Documentation at this revision

Comitter:
Daniel_Lee
Date:
Mon Oct 21 06:49:02 2019 +0000
Parent:
35:4b847971db1b
Child:
37:e80cbc5cd080
Commit message:
Initial setup for TheKsystem.

Changed in this revision

HTS221.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
source/main-http.cpp Show annotated file Show diff for this revision Revisions of this file
wifi-ism43362.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTS221.lib	Mon Oct 21 06:49:02 2019 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/ST/code/HTS221/#ccf7f36492ae
--- a/mbed_app.json	Fri Jan 04 13:32:26 2019 +0100
+++ b/mbed_app.json	Mon Oct 21 06:49:02 2019 +0000
@@ -22,7 +22,7 @@
             "mbed-http.http-buffer-size": 2048,
             "nsapi.default-wifi-security": "WPA_WPA2",
             "nsapi.default-wifi-ssid": "\"SSID\"",
-            "nsapi.default-wifi-password": "\"Password\""
+            "nsapi.default-wifi-password": "\"PASSWORD\""
         },
         "DISCO_L475VG_IOT01A": {
             "target.network-default-interface-type" : "WIFI"
--- a/source/main-http.cpp	Fri Jan 04 13:32:26 2019 +0100
+++ b/source/main-http.cpp	Mon Oct 21 06:49:02 2019 +0000
@@ -6,6 +6,14 @@
 #include "http_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);
+//theKsystemsURL = "https://api.theksystem.com/update?apiKey=9Q8vOz1lguaV6Ou4&field1=21"
+char* theKsystemsURL = "http://api.theksystem.com";
+char* theKsystemsAPIkey = "9Q8vOz1lguaV6Ou4";
+char urlBuffer[256];
 
 void dump_response(HttpResponse* res) {
     printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
@@ -17,7 +25,19 @@
     printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
 }
 
+
 int main() {
+    unsigned int updateCnt=0;
+    float hum_val=12, temp_val=34;
+    
+    printf("DISCO-L457VG-IOT01A WiFi + TheKsystem 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();
@@ -26,12 +46,31 @@
         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");
+    unsigned int a=0;
+    hum_temp.init(NULL);
+    hum_temp.enable();
+
     // Do a GET request to httpbin.org
-    {
+    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.
-        HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://httpbin.org/status/418");
 
+        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", theKsystemsURL, theKsystemsAPIkey, hum_val, temp_val);
+
+        printf("[DEBUG] %s\n", urlBuffer);
+        HttpRequest* get_req = new HttpRequest(network, HTTP_GET, urlBuffer);
+        
         HttpResponse* get_res = get_req->send();
         if (!get_res) {
             printf("HttpRequest failed (error code %d)\n", get_req->get_error());
@@ -42,8 +81,10 @@
         dump_response(get_res);
 
         delete get_req;
+        printf("\nUpdate count %d (Every 10sec, data update to theK server)\n",updateCnt++);
+        wait(10);
     }
-
+#if 0
     // POST request to httpbin.org
     {
         HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
@@ -62,7 +103,7 @@
 
         delete post_req;
     }
-
+#endif
     wait(osWaitForever);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wifi-ism43362.lib	Mon Oct 21 06:49:02 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/wifi-ism43362/#66d17b95a60aa53ccf775c9942997d7a2178ef56