pomera + FlashAir + ODIN-W2 + AS289R2 demo

Fork of mbed-os-example-wifi-ThingSpeak by Hiroaki Okoshi

Revision:
11:bad115ba016c
Parent:
8:72d49a084297
--- a/main.cpp	Thu Dec 22 10:24:22 2016 +0000
+++ b/main.cpp	Mon Jun 05 01:23:05 2017 +0000
@@ -1,6 +1,5 @@
-/* WiFi Example with ThingSpeak
+/* WiFi Example
  * Copyright (c) 2016 ARM Limited
- *                    Fuji Electronics Hiroaki Okoshi 2016.12.22 Modify.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,10 +28,13 @@
 ESP8266Interface wifi(D1, D0);
 #endif
 
-#include "LM75B.h"              //  温度センサー
-LM75B sensor(D14,D15);
+DigitalOut led_r(PE_0);
+DigitalOut led_b(PB_8);
 
-DigitalOut led1(LED1);
+DigitalIn sw_0(PF_2);
+DigitalIn sw_1(PB_6);
+
+Serial device(PD_8, PD_9);  // tx(p28), rx(p27)
 
 const char *sec2str(nsapi_security_t sec)
 {
@@ -66,7 +68,8 @@
 
     ap = new WiFiAccessPoint[count];
     count = wifi->scan(ap, count);
-    for (int i = 0; i < count; i++) {
+    for (int i = 0; i < count; i++)
+    {
         printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\r\n", ap[i].get_ssid(),
                sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
                ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
@@ -76,43 +79,57 @@
     delete[] ap;
 }
 
-/*
- * ThingSpeak Demo
- */
-
-void ThingSpeak_demo(NetworkInterface *net)
+void http_demo(NetworkInterface *net)
 {
     TCPSocket socket;
-    socket.open(net);   // ソケットオープン
+
+    printf("Sending HTTP request to flashair...\r\n");
 
-    socket.connect("api.thingspeak.com", 80);
-    char urlBuffer[128];
+    // Open a socket on the network interface, and create a TCP connection to www.arm.com
+    socket.open(net);
+    socket.connect("flashair", 80);
 
-    // 温度情報取得
-    float temperature = sensor.read();
+    // Send a simple http request
+    char sbuffer[] = "GET /test.txt HTTP/1.1\r\nHost: flashair\r\nConnection: Keep-Alive\r\n\r\n";
 
-    // メッセージ用テキストを生成
-    urlBuffer[0]=0;
-    sprintf(urlBuffer, "GET /update?api_key=%s&field1=%f\r\n\r\n", MBED_CONF_APP_THINGSPEAK_KEY, temperature);
+    int scount = socket.send(sbuffer, sizeof sbuffer-1);
+    printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
+    printf("%s\r\n\r\n", sbuffer);
 
-    // ThingSpeed にメッセージを送信
-    int BuffreLen = strlen(urlBuffer);
-    int scount = socket.send(urlBuffer, BuffreLen+1);
-    printf ("strlen=%d,urlBuffer=%.*s",BuffreLen,BuffreLen-2,urlBuffer);
+    // Recieve a simple http response and print out the response line
+    char rbuffer[400];
+    int rcount = socket.recv(rbuffer, sizeof rbuffer);
+    printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+   
+    //printf("test\r\n");
+    //printf("strstr(rbuffer, text/plain):%d\r\n",strstr(rbuffer, "text/plain"));
+    //printf("strstr(rbuffer, text/plain)-rb:%d\r\n",strstr(rbuffer, "text/plain")-rbuffer);
+    // printf("%.*s\r\n", strstr(rbuffer, "text/plain")-rbuffer, rbuffer);
+    printf("%s\r\n", strstr(rbuffer, "text/plain")+10);
+    // printf("%s\r\n", rbuffer);
+    //device.printf("%s\r\n", rbuffer);
 
-    // for debug    // デバグ時に受信内容を確認する。
-    // char rbuffer[64];
-    // int rcount = socket.recv(rbuffer, sizeof rbuffer);
-    // printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+    /* Text Print */
+    device.printf("* pomera printer *");
 
-    socket.close(); //ソケットクローズ
+    device.printf("%s\r\n", strstr(rbuffer, "text/plain")+10);
+    device.printf("\r\r\r\r\r\r");      // Line Feed x 6
+
+    // Close the socket to return its memory and bring down the network interface
+    socket.close();
 }
 
 int main()
 {
+    // LED & SW init
+    led_r=0;
+    led_b=1;
+    sw_0.mode(PullUp);
+    sw_1.mode(PullUp);
+
     printf("WiFi example\r\n\r\n");
 
-    scan_demo(&wifi);
+    // scan_demo(&wifi);
 
     printf("\r\nConnecting...\r\n");
     int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
@@ -120,7 +137,12 @@
         printf("\r\nConnection error\r\n");
         return -1;
     }
-
+    // Wireless LAN connected
+    //while(sw_0){}
+    printf("\r\nWireless LAN connected\r\n");
+    led_r = 1;
+    led_b = 0;
+    
     printf("Success\r\n\r\n");
     printf("MAC: %s\r\n", wifi.get_mac_address());
     printf("IP: %s\r\n", wifi.get_ip_address());
@@ -128,17 +150,11 @@
     printf("Gateway: %s\r\n", wifi.get_gateway());
     printf("RSSI: %d\r\n\r\n", wifi.get_rssi());
 
-    printf("ThingSpeak Demo\r\n");
-
-    // 60秒に1回メッセージを送信する。
-    for (int i=0 ; i<1000 ; i++) {
-        led1 = !led1;
-        printf ("%d:",i);
-        ThingSpeak_demo(&wifi); //ThingSpeed に
-        Thread::wait(60000);    //60秒に一回送信
-    }
+    http_demo(&wifi);
 
     wifi.disconnect();
 
-    printf ("Done\r\n");
-}
+    printf("\r\nDone\r\n");
+    
+
+}
\ No newline at end of file