浏览代码

serial.print wifi SSID if connected

+ led behaviour modifications
Etienne Landon 9 年之前
父节点
当前提交
0f90bde7dc
共有 4 个文件被更改,包括 39 次插入19 次删除
  1. 2 1
      ESP_UKI.ino
  2. 11 4
      ota.h
  3. 3 1
      udp.h
  4. 23 13
      wifimgr.h

+ 2 - 1
ESP_UKI.ino

@@ -18,7 +18,7 @@
 
 void setup ( void ) {
   
-  
+  delay(500) ;
   Serial.begin(115200);
   Serial.println("Starting ESP8266");
 
@@ -39,6 +39,7 @@ void setup ( void ) {
 void loop ( void ) {
   //Serial.println(WiFi.status());
   StartConfigAP();
+  //checkOTA();
   UDP_send_receive();
 
   

+ 11 - 4
ota.h

@@ -2,11 +2,18 @@ Ticker tkOTA;  // periodic check if OTA available
 int OTA_check_ms = 100;
 bool flag_OTA = false;
 
-void loopOTA(){
+void OTA_Flag(){
+  flag_OTA = true ;
+}
+
+void checkOTA(){
     //change to ticker flag system 
+    if (flag_OTA){
+      flag_OTA = false ;
+      ArduinoOTA.handle();
+      //Serial.println("OTA check");
+    }
     
-    ArduinoOTA.handle();
-    //Serial.println("OTA check");
 }
 
 void detachOTA(){
@@ -46,7 +53,7 @@ void setupOTA(){
   });
   ArduinoOTA.begin();
   Serial.println("OTA started");
-  tkOTA.attach_ms(OTA_check_ms, loopOTA); 
+  tkOTA.attach_ms(OTA_check_ms, OTA_Flag); 
 }
 
 

+ 3 - 1
udp.h

@@ -20,12 +20,13 @@ void UDP_send_receive() {
 
   if (flag_UDP) {
     flag_UDP = false;
+    redLedState (1, 300);
       
        /*  UKI part  */
     GSR_sensor = analogRead(A0);
     //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
     UKI_UDP.beginPacket(UKI_UDP_Out_IP, UKI_UDP_Out_Port);
-    UKI_UDP.print("UKI");
+    UKI_UDP.print(UKI_NAME);
     UKI_UDP.print(" ");
     UKI_UDP.print(GSR_sensor);
     UKI_UDP.endPacket();
@@ -39,6 +40,7 @@ void UDP_send_receive() {
       UKI_UDP.print("new master ip");
       UKI_UDP.endPacket();
     }
+    redLedState (0, 300);
   }
   
 

+ 23 - 13
wifimgr.h

@@ -4,10 +4,11 @@ bool flag_SaveConfig = false;
 #define TRIGGER_PIN 12 //start onDemand config portal when set to LOW
 Ticker tkConfig ;
 bool flag_ConfigPortal = false;
+int timeout = 30000;
 
 char UKI_NAME[40];
 char UKI_UDP_PORT[6] = "9000";
-char UKI_UDP_IP[16] = "192.168.1.100";
+char UKI_UDP_IP[16] = "192.168.10.100";
 
 
 
@@ -19,7 +20,7 @@ void saveConfigCallback () {
 
 // Ticker flag to go to config mode
 void CheckTriggerPin () {
-  Serial.println("Config check");
+  //Serial.println("Config check");
   if ( digitalRead(TRIGGER_PIN) == LOW) {
     flag_ConfigPortal = true;
   }
@@ -54,7 +55,8 @@ void ReadConfig() {
           strcpy(UKI_UDP_IP, json["UKI_UDP_IP"]);
           
 
-        } else {
+        } 
+        else {
           Serial.println("failed to load json config");
         }
       }
@@ -108,7 +110,7 @@ void StartConfigAP(){
     tkConfig.detach();
     delay (500); 
 
-    ReadConfig() ; //read config.json from FS
+    //ReadConfig() ; //read config.json from FS
     
     //WiFiManager
     
@@ -140,11 +142,11 @@ void StartConfigAP(){
     //Modify below to restart config portal 
    // bool flag_connected =false ;
     //while (!flag_connected) {
-      redLedState (0, 500);
+      redLedState (1, 100);
       blueLedState (-1, 100);
-    
-      if (!wifiManager.startConfigPortal("ESP_UKI_AP")) {
+      if (!wifiManager.startConfigPortal(UKI_NAME)) {
         Serial.println("failed to connect, restarting config portal");
+        delay(2000);
         //reset and try again
         redLedState (-1, 100);
         blueLedState (-1, 100);
@@ -175,23 +177,31 @@ void StartConfigAP(){
 
 void setupWifi() {
   pinMode(TRIGGER_PIN, INPUT);
-  blueLedState (-1, 100);
+  blueLedState (-1, 300);
+  
+  ReadConfig();
   Serial.print("Connecting");
   WiFi.begin();
+  int start_time = millis();
   while(WiFi.status()!=3){
     Serial.print(".");
-    delay(100);
+    delay(1000);
+    if (millis()-start_time > timeout) {
+      Serial.println("timeout, starting config portal");
+      flag_ConfigPortal = true;
+      StartConfigAP();
+    }
   }
   Serial.println();
-  Serial.println("connected");  //add wifi ssid 
+  Serial.print("connected to ");  //add wifi ssid 
+  Serial.println(WiFi.SSID());
   blueLedState(1,500);
   //ajout attente connection + leds
   Serial.print("IP address: ");
   Serial.println(WiFi.localIP());// ou vérifier si IP = 0.0.0.0, lancer config portal
-  
-  //delay(10000);
   tkConfig.attach(5, CheckTriggerPin); // check TRIGGER_PIN state periodically
-  ReadConfig();
+  //delay(10000);
+  
 //  while(WiFi.status()<3) {
 //    Serial.print
 //clean FS, for testing