OSDN Git Service

SPIFFS code 追加
authorTomohiro Ito <tomohiro@yzdn.yz.yamagata-u.ac.jp>
Fri, 17 Mar 2017 08:31:35 +0000 (17:31 +0900)
committerTomohiro Ito <tomohiro@yzdn.yz.yamagata-u.ac.jp>
Fri, 17 Mar 2017 08:31:35 +0000 (17:31 +0900)
trial/HTTP-MEMORY-test/HTTP-MEMORY-test.ino [new file with mode: 0644]
trial/HTTP-SPIFFS-test/HTTP-SPIFFS-test.ino [new file with mode: 0644]
trial/HTTP-SPIFFS-test/arduino.bin [new file with mode: 0644]
trial/HTTP-test/HTTP-test.ino

diff --git a/trial/HTTP-MEMORY-test/HTTP-MEMORY-test.ino b/trial/HTTP-MEMORY-test/HTTP-MEMORY-test.ino
new file mode 100644 (file)
index 0000000..3fb132a
--- /dev/null
@@ -0,0 +1,140 @@
+#include <Nefry.h>
+#include <ESP8266WiFi.h>
+#include <NTPClient.h>
+#include <WiFiUdp.h>
+#include <TimeLib.h>
+#include <ESP8266HTTPClient.h>
+
+
+//NTP test program for Nefry
+//Nefryの時計をntpで同期するためのサンプルコードです.開発中です.
+//Nefryのwifi関数を使ってWifiが切れたら再接続するように書き換えた
+
+extern "C" {
+  #include "user_interface.h"
+}
+
+#define DEVICEID ESP.getChipId()
+
+
+const String szCommandReadBaseURL = "https://a.yamagata-u.ac.jp/amenity/network/M2M/KinomaControlRequest.aspx";
+const String FingurePrintSha1 ="A5 23 3B D5 FA 6C E9 C2 8F 30 17 8F EF F9 EA C8 C5 18 49 3F";
+const char* host = "a.yamagata-u.ac.jp";
+const int httpPort = 80;
+const int httpsPort = 443;
+
+//char toSSID[] = "xxxx";
+//char ssidPASSWD[] = "xxxxxx";
+bool BlueLED=false;
+int nCounterWifiReconnect=0;
+int nCounter1s = 0;
+int nCounter30s = 0;
+int ADvalue = 0;
+bool bCommandReadingHttp = false; 
+bool bNoNTPupdated = true;
+
+WiFiUDP ntpUDP;
+// You can specify the time server pool and the offset (in seconds, can be
+// changed later with setTimeOffset() ). Additionaly you can specify the
+// update interval (in milliseconds, can be changed using setUpdateInterval() ).
+NTPClient timeClient(ntpUDP, "ntp.nict.jp", 0, 3600000);
+
+
+void timer1_ISR (void) {
+ if (WiFi.status() != WL_CONNECTED) {
+    // コネクション確立済み以外のステータスなので
+    // 無線LAN接続NG 赤色LED点灯
+    Nefry.setLed(255, 0, 0);
+    nCounterWifiReconnect++;
+    //WiFi.begin();
+      if (nCounterWifiReconnect>30){
+        nCounterWifiReconnect=0;
+        Nefry.setWifiTimeoutClear();
+        Nefry.println("Wifi TimeoutClear");
+      }
+  } else {
+    //コネクションOKなので、青色LED点灯
+    nCounterWifiReconnect=0;
+    Nefry.setLed(0, 0, 64);
+  
+  }
+  ADvalue =  analogRead(A0);
+  char buf[128];
+  //Nefry.println(ADvalue);
+  //2014-10-10T13:50:40+09:00 (TIMEZONE JST)
+  //2014-10-10T04:50:40Z (UTC)
+ // sprintf(buf,"%04d-%02d-%02dT%02d:%02d:%02dZ",year(), month(), day(),hour(),minute(),second());
+//  Nefry.println(buf);
+  nCounter1s++;  
+  nCounter30s++;
+
+}
+
+void stop_timer1() {
+  timer1_disable();
+  timer1_detachInterrupt();
+}
+
+void start_timer1(unsigned int nIntervalTime_us) {
+    timer1_isr_init();
+    timer1_attachInterrupt(timer1_ISR);
+    timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP);
+    timer1_write(clockCyclesPerMicrosecond() / 16 * nIntervalTime_us); 
+}
+void setup() {
+  // put your setup code here, to run once:
+  //NefryではWifeへの接続は不要
+ // WiFi.mode(WIFI_STA);
+   //WiFi.begin(toSSID, ssidPASSWD);
+   timeClient.begin();
+   //Nefry.println(DEVICEID);
+   start_timer1(1000000); //1000000 us間隔でタイマーを起動
+
+}
+
+void loop() {
+  
+ if (bNoNTPupdated==true){
+   if (WiFi.status() == WL_CONNECTED) {
+    Nefry.setLed(128, 0, 128);
+    timeClient.update();
+    bNoNTPupdated=false;
+    setTime(timeClient.getEpochTime());
+    //Nefry.println(timeClient.getFormattedTime());
+    Nefry.setLed(0, 0, 64);
+   }
+  }
+ if (nCounter1s >0) {
+    if (WiFi.status() == WL_CONNECTED && bCommandReadingHttp == false) {
+    bCommandReadingHttp  = true;
+    Nefry.setLed(0, 128, 0);
+    HTTPClient http;
+    String szCommandReadURL = szCommandReadBaseURL + "?DeviceID=" + DEVICEID;
+    http.begin(szCommandReadURL,FingurePrintSha1);
+    int httpCode = http.GET();
+    //Nefry.print(timeClient.getFormattedTime());
+    //Nefry.println(httpCode);
+    if(httpCode == HTTP_CODE_OK) {
+          String payload = http.getString();
+        // Nefry.println(" : " + payload);
+    }
+    http.end();
+    nCounter1s =0;
+    bCommandReadingHttp = false;
+    Nefry.setLed(0, 0, 64);
+    }
+
+  }
+
+  
+ if (WiFi.status() == WL_CONNECTED && nCounter30s > 30) {
+  nCounter30s =0;
+  Nefry.setLed(128, 0, 128);
+  timeClient.update();
+  setTime(timeClient.getEpochTime());
+  // Nefry.println(timeClient.getFormattedTime());
+  Nefry.ndelay(100);
+  Nefry.setLed(0, 0, 64);
+ }
+}
diff --git a/trial/HTTP-SPIFFS-test/HTTP-SPIFFS-test.ino b/trial/HTTP-SPIFFS-test/HTTP-SPIFFS-test.ino
new file mode 100644 (file)
index 0000000..70d28b0
--- /dev/null
@@ -0,0 +1,150 @@
+#include <Nefry.h>
+#include <ESP8266WiFi.h>
+#include <NTPClient.h>
+#include <WiFiUdp.h>
+#include <TimeLib.h>
+#include <FS.h>
+#include <ESP8266HTTPClient.h>
+
+
+//NTP test program for Nefry
+//Nefryの時計をntpで同期するためのサンプルコードです.開発中です.
+//Nefryのwifi関数を使ってWifiが切れたら再接続するように書き換えた
+//SPIFFSを使うとHTTP Clientの動作が不安定になるので,取り急ぎ,開発を中止
+
+extern "C" {
+  #include "user_interface.h"
+}
+
+#define DEVICEID ESP.getChipId()
+
+
+const String szCommandReadBaseURL = "https://a.yamagata-u.ac.jp/amenity/network/M2M/KinomaControlRequest.aspx";
+const String FingurePrintSha1 ="A5 23 3B D5 FA 6C E9 C2 8F 30 17 8F EF F9 EA C8 C5 18 49 3F";
+const char* host = "a.yamagata-u.ac.jp";
+const int httpPort = 80;
+const int httpsPort = 443;
+
+//char toSSID[] = "xxxx";
+//char ssidPASSWD[] = "xxxxxx";
+bool BlueLED=false;
+int nCounterWifiReconnect=0;
+int nCounter1s = 0;
+int nCounter30s = 0;
+int ADvalue = 0;
+bool bCommandReadingHttp = false; 
+bool bNoNTPupdated = true;
+bool bSPIFFS = false;
+
+WiFiUDP ntpUDP;
+// You can specify the time server pool and the offset (in seconds, can be
+// changed later with setTimeOffset() ). Additionaly you can specify the
+// update interval (in milliseconds, can be changed using setUpdateInterval() ).
+NTPClient timeClient(ntpUDP, "ntp.nict.jp", 0, 3600000);
+
+
+void timer1_ISR (void) {
+ if (WiFi.status() != WL_CONNECTED) {
+    // コネクション確立済み以外のステータスなので
+    // 無線LAN接続NG 赤色LED点灯
+    Nefry.setLed(255, 0, 0);
+    nCounterWifiReconnect++;
+    //WiFi.begin();
+      if (nCounterWifiReconnect>30){
+        nCounterWifiReconnect=0;
+        Nefry.setWifiTimeoutClear();
+        Nefry.println("Wifi TimeoutClear");
+      }
+  } else {
+    //コネクションOKなので、青色LED点灯
+    nCounterWifiReconnect=0;
+    Nefry.setLed(0, 0, 64);
+  
+  }
+  ADvalue =  analogRead(A0);
+  char buf[128];
+  //Nefry.println(ADvalue);
+  //2014-10-10T13:50:40+09:00 (TIMEZONE JST)
+  //2014-10-10T04:50:40Z (UTC)
+ // sprintf(buf,"%04d-%02d-%02dT%02d:%02d:%02dZ",year(), month(), day(),hour(),minute(),second());
+//  Nefry.println(buf);
+  nCounter1s++;  
+  nCounter30s++;
+
+}
+
+void stop_timer1() {
+  timer1_disable();
+  timer1_detachInterrupt();
+}
+
+void start_timer1(unsigned int nIntervalTime_us) {
+    timer1_isr_init();
+    timer1_attachInterrupt(timer1_ISR);
+    timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP);
+    timer1_write(clockCyclesPerMicrosecond() / 16 * nIntervalTime_us); 
+}
+void setup() {
+  // put your setup code here, to run once:
+  //NefryではWifeへの接続は不要
+ // WiFi.mode(WIFI_STA);
+   //WiFi.begin(toSSID, ssidPASSWD);
+   timeClient.begin();
+   //Nefry.println(DEVICEID);
+   start_timer1(1000000); //1000000 us間隔でタイマーを起動
+   //SPIFFSのサンプル特性
+//  bSPIFFS = SPIFFS.begin();
+  //SPIFFS.format();
+}
+
+void loop() {
+  
+ if (bNoNTPupdated==true){
+   if (WiFi.status() == WL_CONNECTED) {
+    Nefry.setLed(128, 0, 128);
+    timeClient.update();
+    bNoNTPupdated=false;
+    setTime(timeClient.getEpochTime());
+ //   Nefry.println(timeClient.getFormattedTime());
+    Nefry.setLed(0, 0, 64);
+   }
+  }
+ if (nCounter1s >0) {
+    if (WiFi.status() == WL_CONNECTED && bCommandReadingHttp == false) {
+      bCommandReadingHttp  = true;
+      Nefry.setLed(0, 128, 0);
+    HTTPClient http;
+    String szCommandReadURL = szCommandReadBaseURL + "?DeviceID=" + DEVICEID;
+    http.begin(szCommandReadURL,FingurePrintSha1);
+    int httpCode = http.GET();
+    //Nefry.print(timeClient.getFormattedTime());
+    //Nefry.println(httpCode);
+    if(httpCode == HTTP_CODE_OK) {
+          String payload = http.getString();
+        // Nefry.println(" : " + payload);
+    }
+    http.end();
+    nCounter1s =0;
+    bCommandReadingHttp = false;
+    Nefry.setLed(0, 0, 64);
+    }
+
+  }
+
+  
+ if (WiFi.status() == WL_CONNECTED && nCounter30s > 30) {
+  nCounter30s =0;
+  Nefry.setLed(128, 0, 128);
+  timeClient.update();
+    setTime(timeClient.getEpochTime());
+   // Nefry.println(timeClient.getFormattedTime());
+   Nefry.ndelay(100);
+   Nefry.setLed(0, 0, 64);
+    if (bSPIFFS==false ) {
+      Nefry.println("SPIFFS.begin fail");
+    }else{
+      Nefry.println("SPIFFS.begin complete");
+    }
+ }
+}
diff --git a/trial/HTTP-SPIFFS-test/arduino.bin b/trial/HTTP-SPIFFS-test/arduino.bin
new file mode 100644 (file)
index 0000000..32c4942
Binary files /dev/null and b/trial/HTTP-SPIFFS-test/arduino.bin differ
index 336dff0..2c4610c 100644 (file)
@@ -106,7 +106,6 @@ void loop() {
   }
  
  if (nCounter1s >0) {
-  nCounter1s =0;
     if (WiFi.status() == WL_CONNECTED && bCommandReadingHttp == false) {
       bCommandReadingHttp  = true;
       Nefry.setLed(0, 128, 0);
@@ -119,9 +118,10 @@ void loop() {
     if(httpCode == HTTP_CODE_OK) {
           String payload = http.getString();
         // Nefry.println(" : " + payload);
-         bCommandReadingHttp = false;
     }
     http.end();
+    nCounter1s =0;
+    bCommandReadingHttp = false;
     Nefry.setLed(0, 0, 64);
     }