Wio 3G with Firebase example
Fork of Wio_3G_HTTP-GET-example by
Revision 76:fe9dd61c5f5c, committed 2018-08-22
- Comitter:
- atomichan
- Date:
- Wed Aug 22 05:27:25 2018 +0000
- Parent:
- 75:f93c0063755c
- Child:
- 77:0194cca4103b
- Commit message:
- used for Ina-city Hackerthon
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/easy-connect.lib Wed Aug 22 05:27:25 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/easy-connect/#aaf89690919fc378799e680119a58a222402799f
--- a/main.cpp Fri Aug 10 09:07:14 2018 +0000
+++ b/main.cpp Wed Aug 22 05:27:25 2018 +0000
@@ -5,6 +5,11 @@
#include "PixelArray.h"
#include "Servo.h"
+#include <sstream>
+#include "easy-connect.h"
+#include "https_request.h"
+#include "ssl_ca_pem.h"
+
#if !defined(TARGET_WIO_3G)
#error Selected target is not supported.
#endif
@@ -45,6 +50,36 @@
}
+const char API_TOKEN[] = "tfa6Ud9FY760SfLLhHl3UBr0NFdVHEFLHvdjTsrW";
+const char URL[] = "https://devzfyjsa.cybozu.com/k/v1/record.json";
+
+int app_id = 1;
+
+// JSON simplicity parser
+char* j_paser( const char *buf , char *word , char *out )
+{
+ int i = 0;
+ char *p;
+ char _word[64] = "\"\0";
+
+ strcat(_word , word );
+ strcat(_word , "\"" );
+
+ p = strstr( (char*)buf , _word ) + 2 + strlen(_word);
+
+ while( (p[i] != ',')&&(p[i] != '\n')&&(p[i] != '"') )
+ {
+ out[i] = p[i];
+ i++;
+ }
+ out[i] = '\0';
+
+ return p;
+}
+
+
+
+
int main()
{
char buf[20];
@@ -59,7 +94,7 @@
// set up the colours we want to draw with
const int colorbuf[NUM_COLORS] = {0x000000, 0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f, 0x2f2f2f};
- ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
+ ::ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
// for each of the colours (j) write out 10 of them
// the pixels are written at the colour*10, plus the colour position
@@ -71,6 +106,7 @@
pc.printf("hello, Mbed world\n");
+ /*
int cnt = 0;
int idx = 0;
@@ -92,4 +128,118 @@
wait(0.5);
}
+ */
+ 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) {
+ //lcd.printf("NG");
+ 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){
+ int id = 10;
+
+ /*
+ // ID select
+ lcd.cls();
+ lcd.locate(0,3);
+ lcd.printf("Please select id.");
+ while(fire == 0){
+ lcd.locate(0,14);
+ lcd.printf("id = ");
+ if( up == 1) id++;
+ if( down == 1) id--;
+ lcd.printf("%d ",id);
+ wait(0.2);
+ }
+
+ lcd.cls();
+ lcd.locate(0,3);
+ lcd.printf("It is polling with the selected id.");
+ */
+
+ // Set url
+ std::stringstream ss_url;
+ std::string s_url(URL);
+
+ ss_url << s_url << "?app=" << app_id << "&id=" << id;
+
+ string url = ss_url.str();
+
+ pc.printf("%s\r\n",url.c_str());
+
+ while(1){
+ pc.printf("\r\n----- HTTPS GET request -----\r\n");
+ HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, url.c_str());
+
+ get_req->set_header("X-Cybozu-API-Token", API_TOKEN);
+
+ HttpResponse* get_res = get_req->send();
+
+ pc.printf("\n----- HTTPS GET response [%d]-----\n",get_res->get_status_code());
+
+ if(get_res->get_status_code() == 200){
+ pc.printf("\n----- HTTPS GET response 200 -----\n");
+ const char* body = get_res->get_body_as_string().c_str();
+
+ pc.printf("%s\r\n",body);
+
+ // Response JSON parse
+ char value[256];
+
+ char* p = j_paser(body,"日付",value);
+ j_paser(p,"value",value);
+ printf("date:%s\r\n",value);
+
+ /*
+ lcd.cls();
+ lcd.locate(0,3);
+ lcd.printf("Date:%s",value);
+ */
+
+ p = j_paser(body,"文字列__1行_",value);
+ j_paser(p,"value",value);
+ printf("%s\r\n",value);
+
+ /*
+ lcd.locate(0,14);
+ lcd.printf("name:%s",value);
+
+ // Sound an alert
+ spkr.period(1.0/5000.0);
+ spkr=0.5;
+ wait(1.0);
+ spkr=0.0;
+ */
+
+ delete get_req;
+
+ break;
+ }
+
+ delete get_req;
+
+ wait(10.0);
+ }
+
+ //while(fire == 0);
+ wait(1.0);
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-http.lib Wed Aug 22 05:27:25 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/teams/sandbox/code/mbed-http/#383e9bfbfbed
--- a/mbed-os.lib Fri Aug 10 09:07:14 2018 +0000 +++ b/mbed-os.lib Wed Aug 22 05:27:25 2018 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#50bd61a4a72332baa6b1bac6caccb44dc5423309 +https://github.com/ARMmbed/mbed-os/#f8b140f8d7cb226e41486c5df66ac4f3ce699219
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Wed Aug 22 05:27:25 2018 +0000
@@ -0,0 +1,97 @@
+{
+ "macros": [
+ ],
+ "config": {
+ "sock-type": "TCP",
+ "sim-pin-code": {
+ "help": "SIM PIN code",
+ "value": "\"0000\""
+ },
+ "cellular_sim_pin": {
+ "help": "SIM PIN code",
+ "value": "\"0000\""
+ },
+ "cellular_apn": {
+ "help": "The APN string to use for this SIM/network, set to 0 if none",
+ "value": "\"soracom.io\""
+ },
+ "cellular_username": {
+ "help": "The user name string to use for this APN, set to zero if none",
+ "value": "\"sora\""
+ },
+ "cellular_password": {
+ "help": "The password string to use for this APN, set to 0 if none",
+ "value": "\"sora\""
+ },
+ "echo-server-hostname": {
+ "help": "Echo server host name.",
+ "value": "\"echo.mbedcloudtesting.com\""
+ },
+ "echo-server-port": {
+ "help": "Echo server port number.",
+ "value": 7
+ },
+ "trace-level": {
+ "help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
+ "macro_name": "MBED_TRACE_MAX_LEVEL",
+ "value": "TRACE_LEVEL_INFO"
+ },
+ "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": "CELLULAR_ONBOARD"
+ },
+ "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": "\"AirPort38991\""
+ },
+ "wifi-password": {
+ "value": "\"3060025132786\""
+ },
+ "esp8266-debug": {
+ "value": null
+ }
+ },
+ "target_overrides": {
+ "*": {
+ "target.features_add": ["LWIP","NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
+ "lwip.ipv4-enabled": true,
+ "lwip.ethernet-enabled": false,
+ "lwip.ppp-enabled": true,
+ "lwip.tcp-enabled": true,
+ "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+ "mbed-mesh-api.6lowpan-nd-channel": 12,
+ "mbed-trace.enable": 1,
+ "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 22 05:27:25 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" +"DwAwggEKAoIBAQDlkGZL7PlGcakgg77pbL9KyUhpgXVObST2yxcT+LBxWYR6ayuF\n" +"pDS1FuXLzOlBcCykLtb6Mn3hqN6UEKwxwcDYav9ZJ6t21vwLdGu4p64/xFT0tDFE\n" +"3ZNWjKRMXpuJyySDm+JXfbfYEh/JhW300YDxUJuHrtQLEAX7J7oobRfpDtZNuTlV\n" +"Bv8KJAV+L8Y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