Wio 3G with Firebase example
Fork of Wio_3G_HTTP-GET-example by
Revision 77:0194cca4103b, committed 2018-08-23
- Comitter:
- atomichan
- Date:
- Thu Aug 23 04:01:41 2018 +0000
- Parent:
- 76:fe9dd61c5f5c
- Child:
- 78:7f66af24c678
- Commit message:
- part of the preparation works for Ina-city Hackerthon
Changed in this revision
--- a/Grove_LCD_RGB_Backlight.lib Wed Aug 22 05:27:25 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/cmatz3/code/Grove_LCD_RGB_Backlight/#5ce38ef7a7db
--- a/Grove_temperature.lib Wed Aug 22 05:27:25 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/MACRUM/code/Grove_temperature/#aee37a51ccbb
--- a/PixelArray.lib Wed Aug 22 05:27:25 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/chris/code/PixelArray/#b45a70faaa83
--- a/Servo.lib Wed Aug 22 05:27:25 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- a/WS2812.lib Wed Aug 22 05:27:25 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/bridadan/code/WS2812/#6e647820f587
--- a/main.cpp Wed Aug 22 05:27:25 2018 +0000
+++ b/main.cpp Thu Aug 23 04:01:41 2018 +0000
@@ -1,10 +1,4 @@
#include "mbed.h"
-#include "Grove_LCD_RGB_Backlight.h"
-#include "Grove_temperature.h"
-#include "WS2812.h"
-#include "PixelArray.h"
-#include "Servo.h"
-
#include <sstream>
#include "easy-connect.h"
#include "https_request.h"
@@ -14,46 +8,38 @@
#error Selected target is not supported.
#endif
-#define D20 (PB_4)
-#define D19 (PB_3)
-
// on-board resources
-
Serial pc(USBTX, USBRX, 115200);
DigitalOut GrovePower(PB_10, 1);
-#define WS2812_BUF 8
-#define NUM_COLORS 8
-#define NUM_LEDS_PER_COLOR 8
-#define H0 8
-#define L0 32
-#define H1 17
-#define L1 32
-
-DigitalOut LEDPower(PE_8, 1);
-PixelArray px(WS2812_BUF);
-WS2812 ws(PB_1, WS2812_BUF, H0, L0, H1, L1);
+#define D20 (PB_4)
// Grove sensors
-DigitalOut led1(D38);
-AnalogIn ain(A6); // angle or light sensor
-InterruptIn btn(D20); // button or touch sensor
-Grove_LCD_RGB_Backlight lcd(I2C_SDA, I2C_SCL);
-Grove_temperature temp(A4);
+// buzzer
+DigitalOut buzzer(D38);
+int buzzer_on = 1, buzzer_off = 0;
+// button or touch sensor
+InterruptIn btn(D20);
uint32_t button = 0;
+int id = 0;
void push()
{
button++;
+ id++;
}
+// For your API Token, refer to "API token" in your application setting page
+const char API_TOKEN[] = "api-token";
+// Your domain name can be seen in the usage explanation with curl.
+const char URL[] = "https://{domain}.cybozu.com/k/v1/record.json";
-const char API_TOKEN[] = "tfa6Ud9FY760SfLLhHl3UBr0NFdVHEFLHvdjTsrW";
-const char URL[] = "https://devzfyjsa.cybozu.com/k/v1/record.json";
+// app_id, application id, can be checked with your application's URL
+// e.g. https://{domain}.cybozu.com/k/2/ -> app_id is 2
+int app_id = 1;
-int app_id = 1;
// JSON simplicity parser
char* j_paser( const char *buf , char *word , char *out )
@@ -77,115 +63,40 @@
return p;
}
-
-
-
+// main method. retrieve data from Kintone by HTTP GET
int main()
{
char buf[20];
btn.fall(push); // set interrupt handler
- lcd.clear();
- lcd.setRGB(0xff, 0x00, 0x00);
- lcd.locate(0, 0);
- lcd.print("Hello World!");
- lcd.locate(0, 1);
-
- // 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
-
- // for each of the colours (j) write out 10 of them
- // the pixels are written at the colour*10, plus the colour position
- // all modulus 60 so it wraps around
- for (int i = 0; i < WS2812_BUF; i++) {
- px.Set(i, colorbuf[i]);
- px.SetI(i, 0x80);
- }
-
- pc.printf("hello, Mbed world\n");
-
- /*
- int cnt = 0;
- int idx = 0;
-
- while (true) {
- pc.printf("count = %4d, button = %d, analog = %2.2f, temp = %2.2f\n", cnt++, button, ain.read(), temp.getTemperature());
- sprintf(buf, "L=%2.2f, T=%2.2f", ain.read(), temp.getTemperature());
-
- lcd.setRGB(0xff, (255*ain.read()), 0x00);
- lcd.locate(0, 1);
- lcd.print(buf);
-
- led1 = !led1;
-
- ws.write_offsets(px.getBuf(), idx, idx, idx);
- idx++;
- if (idx >= WS2812_BUF) {
- idx = 0;
- }
-
- wait(0.5);
- }
- */
+ pc.printf("Greetings from Ina-city Hackerthon on 25-26 of August\n");
+
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){
+ // 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());
+
pc.printf("\r\n----- HTTPS GET request -----\r\n");
HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, url.c_str());
@@ -208,26 +119,18 @@
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;
- */
+ int buzz_flag = 1;
+ while(buzz_flag){
+ buzzer = buzzer_on;
+ wait(.5);
+ buzzer = buzzer_off;
+ wait(.5);
+ buzz_flag = 0;
+ }
delete get_req;
@@ -238,8 +141,7 @@
wait(10.0);
}
-
- //while(fire == 0);
+
wait(1.0);
}
}
--- a/mbed_app.json Wed Aug 22 05:27:25 2018 +0000
+++ b/mbed_app.json Thu Aug 23 04:01:41 2018 +0000
@@ -3,10 +3,6 @@
],
"config": {
"sock-type": "TCP",
- "sim-pin-code": {
- "help": "SIM PIN code",
- "value": "\"0000\""
- },
"cellular_sim_pin": {
"help": "SIM PIN code",
"value": "\"0000\""
@@ -42,56 +38,18 @@
"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"],
+ "target.features_add": ["LWIP"],
"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"
- }
+ }
}
}
Toyomasa Watarai
