kintone devCamp 2018 MbedによるIoTエッジデバイス入門 向けサンプルプログラム

Dependencies:   C12832 LM75B MMA7660 mbed-http

Files at this revision

API Documentation at this revision

Comitter:
JKsoft_main
Date:
Wed Aug 01 00:14:57 2018 +0000
Commit message:
First Release

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
C12832.lib Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
MMA7660.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
easy-connect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-http.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.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
ssl_ca_pem.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/chris/code/C12832/#7de323fa46fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/chris/code/LM75B/#6a70c9303bbe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA7660.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/Sissors/code/MMA7660/#36a163511e34
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,57 @@
+# Getting started with Blinky on mbed OS
+
+This guide reviews the steps required to get Blinky working on an mbed OS platform.
+
+Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Import the example application
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the following result:
+
+```
+[snip]
++----------------------------+-------+-------+------+
+| Module                     | .text | .data | .bss |
++----------------------------+-------+-------+------+
+| Misc                       | 13939 |    24 | 1372 |
+| core/hal                   | 16993 |    96 |  296 |
+| core/rtos                  |  7384 |    92 | 4204 |
+| features/FEATURE_IPV4      |    80 |     0 |  176 |
+| frameworks/greentea-client |  1830 |    60 |   44 |
+| frameworks/utest           |  2392 |   512 |  292 |
+| Subtotals                  | 42618 |   784 | 6384 |
++----------------------------+-------+-------+------+
+Allocated Heap: unknown
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 7168 bytes
+Total RAM memory (data + bss + heap + stack): 7168 bytes
+Total Flash memory (text + data + misc): 43402 bytes
+Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your mbed device to the computer over USB.
+1. Copy the binary file to the mbed device.
+1. Press the reset button to start the program.
+
+The LED on your platform turns on and off.
+
+## Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/easy-connect.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/easy-connect/#aaf89690919fc378799e680119a58a222402799f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include <sstream>
+#include "easy-connect.h"
+#include "https_request.h"
+#include "ssl_ca_pem.h"
+#include "C12832.h"
+#include "MMA7660.h"
+#include "LM75B.h"
+
+C12832 lcd(D11, D13, D12, D7, D10);
+MMA7660 MMA(D14,D15);
+LM75B sensor(D14,D15);
+
+Serial pc(USBTX,USBRX);
+
+const char API_TOKEN[] = "api-token";
+const char URL[] = "https://{domain}.cybozu.com/k/v1/record.json";
+
+int app_id = 2;
+
+bool post_kintone(NetworkInterface* nif, const char *url, int app_id_, char* field_code, float value)
+{    
+    HttpsRequest* post_req = new HttpsRequest(nif, SSL_CA_PEM, HTTP_POST, url);
+    post_req->set_header("X-Cybozu-API-Token", API_TOKEN);
+    post_req->set_header("Content-Type", "application/json");
+    
+    std::stringstream ss_body;
+        
+    ss_body << "{\"app\": " << app_id_ << ", \"record\": {\"" << field_code << "\": {\"value\": \"" << value << "\"}}}\n";
+    
+    string body = ss_body.str();
+
+    printf("body:%s\r\n",body.c_str());
+    
+    HttpResponse* post_res = post_req->send(body.c_str(), body.length());
+    
+    printf("res:%s\r\n",post_res->get_body_as_string().c_str());
+    
+    
+    if(post_res->get_status_code() == 200){
+        delete post_req;
+        return true;
+    }
+    
+    delete post_req;    
+    
+    return false;
+}
+
+// main() runs in its own thread in the OS
+int main() {
+    NetworkInterface* network = NULL;
+
+    pc.baud(115200);
+
+    lcd.cls();
+    lcd.locate(0,3);
+    lcd.printf("Network Connect..");
+
+    pc.printf("\r\n----- Start -----\r\n");
+    
+    network = easy_connect(true);    // If true, prints out connection details.
+    if (!network) {
+        pc.printf("\r\n----- Network Error -----\r\n");
+        return -1;
+    }
+
+    lcd.printf("OK");
+    pc.printf("\r\n----- Network Connected -----\r\n");
+    
+    wait(2.0);
+    
+    while(1) {
+        lcd.cls();
+        lcd.locate(0,3);
+        lcd.printf("x=%.2f y=%.2f z=%.2f",MMA.x(), MMA.y(), MMA.z());
+        
+        float temp = sensor.read();
+        lcd.locate(0,14);
+        lcd.printf("Temp = %.1f\n", temp);
+        
+        bool ret = post_kintone(network, URL, app_id, "temp", temp);
+        pc.printf("\n----- HTTPS POST response [%s]----- \n\r",ret== true ? "OK" : "NG");
+        
+        wait(10.0);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-http.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/sandbox/code/mbed-http/#9a04ed79d67e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#35fa909641fedcad9bbe0c7300d4ccdf15a2b71a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,59 @@
+{
+    "macros": [
+    ],
+    "config": {
+        "main-stack-size": {
+            "value": 8192
+        },
+        "network-interface":{
+            "help": "options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, WIFI_RTW, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD",
+            "value": "WIFI_ESP8266"
+        },
+        "mesh_radio_type": {
+            "help": "options are ATMEL, MCR20",
+            "value": "ATMEL"
+        },
+        "esp8266-tx": {
+            "help": "Pin used as TX (connects to ESP8266 RX)",
+            "value": "D1"
+        },
+        "esp8266-rx": {
+            "help": "Pin used as RX (connects to ESP8266 TX)",
+            "value": "D0"
+        },
+        "wifi-ssid": {
+            "value": "\"ssid\""
+        },
+        "wifi-password": {
+            "value": "\"password\""
+        },
+        "esp8266-debug": {
+            "value": null
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
+            "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+            "mbed-mesh-api.6lowpan-nd-channel": 12,
+            "mbed-trace.enable": 0,
+            "platform.stdio-baud-rate": 115200,
+            "platform.stdio-convert-newlines": false
+           },
+        "RZ_A1H": {
+            "target.macros_add": ["MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES"]
+           },
+        "HEXIWEAR": {
+            "esp8266-tx": "PTD3",
+            "esp8266-rx": "PTD2"
+        },
+        "NUCLEO_F401RE": {
+            "esp8266-tx": "D8",
+            "esp8266-rx": "D2"
+        },
+        "NUCLEO_F411RE": {
+            "esp8266-tx": "D8",
+            "esp8266-rx": "D2"
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ssl_ca_pem.h	Wed Aug 01 00:14:57 2018 +0000
@@ -0,0 +1,29 @@
+const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
+"MIIFADCCA+igAwIBAgIBBzANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
+"EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
+"HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
+"ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTExMDUwMzA3MDAw\n"
+"MFoXDTMxMDUwMzA3MDAwMFowgcYxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n"
+"b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n"
+"aG5vbG9naWVzLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydHMuc3RhcmZpZWxk\n"
+"dGVjaC5jb20vcmVwb3NpdG9yeS8xNDAyBgNVBAMTK1N0YXJmaWVsZCBTZWN1cmUg\n"
+"Q2VydGlmaWNhdGUgQXV0aG9yaXR5IC0gRzIwggEiMA0GCSqGSIb3DQEBAQUAA4IB\n"
+"DwAwggEKAoIBAQDlkGZL7PlGcakgg77pbL9KyUhpg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