Browse Source

web server debug

server is working, AP or STA mode seems ok, web server does not load
dynamic pages (admin...) problem with style and script pages ?
error
Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023c84f
depc=0x00000000

ctx: cont
sp: 3fff13f0 end: 3fff16d0 offset: 01a0

>>>stack>>>
3fff1590:  3fff02f0 3ffefa2c 3fff1660 40210b4a
3fff15a0:  4023c84f 00000001 3fff15f0 40210ba2
3fff15b0:  3fff29d8 0000000f 3fff3058 402073de
3fff15c0:  00000000 00000000 00000000 4021137c
3fff15d0:  0000000a 00000030 3fff3058 4020b386
3fff15e0:  4020b390 3fff3058 3fff1610 4020b3c2
3fff15f0:  3fff3e48 0000000f 00000001 40210cf8
3fff1600:  4020b390 3fff3058 3ffefa2c 4020b57d
3fff1610:  3fff29d8 0000000f 00000001 4020a027
3fff1620:  3ffefa68 401011f3 3fff06b0 00000001
3fff1630:  00000000 0000000a 4020edf8 3fff06b0
3fff1640:  40201772 00000001 00000001 3fff06a0
3fff1650:  3fffdc20 000003e8 3ffefa2c 4020b678
3fff1660:  3ffe8d20 00000000 000003e8 0003048d
3fff1670:  3ffefa4c 3fff3fe0 4020edf8 3fff06b0
3fff1680:  40201772 00000000 3fff0699 402090df
3fff1690:  00000000 00000000 00000016 3fff06a0
3fff16a0:  3fffdc20 00000000 3fff0699 40209187
3fff16b0:  00000000 00000000 3fff0699 4020ee41
3fff16c0:  00000000 00000000 3fff06b0 40100114
<<<stack<<<

ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
Etienne Landon 9 years ago
parent
commit
20eec59c02
5 changed files with 87 additions and 64 deletions
  1. 24 32
      ESP_UKI.ino
  2. 36 4
      global.h
  3. 6 11
      includes.h
  4. 3 8
      ota.h
  5. 18 9
      web.h

+ 24 - 32
ESP_UKI.ino

@@ -1,6 +1,8 @@
 /*
     ESP_UKI
 
+    largely base on http://www.john-lassen.de/index.php/projects/esp-8266-arduino-ide-webconfig
+
   TODO :  clean webserver
           better function organizing
           add firmware number in webserver
@@ -14,6 +16,7 @@
 
 
 void setup ( void ) {
+  
   EEPROM.begin(512);
   Serial.begin(115200);
   Serial.println("Starting ES8266");
@@ -39,43 +42,32 @@ void setup ( void ) {
 
 
 void loop ( void ) {
-  
+  loop_counter += 1;
   loopWebserver();
   
   loopOTA();
 
   /*  UKI part	*/
-  GSR_sensor = analogRead(A0);
-  //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
-  UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
-  UKI_UDP.print(config.DeviceName);
-  UKI_UDP.print(" ");
-  UKI_UDP.print(GSR_sensor);
-  UKI_UDP.endPacket();
-  //yield();
-//Red_Led_State = !Red_Led_State;
-  
-  //analogWrite(Red_Led, GSR_sensor);
-
-  
-  delay(20);
-  
-
-  //Check udp in
-  int packetSize = UKI_UDP.parsePacket();
-  
-  if(packetSize) {
-    UKI_UDP_Master_IP = UKI_UDP.remoteIP();
-    UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
-    UKI_UDP.print("new master ip");
-    UKI_UDP.endPacket();
-  }
-
-
-
-
-
-
+//  GSR_sensor = analogRead(A0);
+//  //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
+//  UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
+//  UKI_UDP.print(config.DeviceName);
+//  UKI_UDP.print(" ");
+//  UKI_UDP.print(GSR_sensor);
+//  UKI_UDP.endPacket();
+//  //yield();
+//  
+//  delay(20);
+//  
+//  //Check udp in
+//  int packetSize = UKI_UDP.parsePacket();
+//  
+//  if(packetSize) {
+//    UKI_UDP_Master_IP = UKI_UDP.remoteIP();
+//    UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
+//    UKI_UDP.print("new master ip");
+//    UKI_UDP.endPacket();
+//  }
 
 
 

+ 36 - 4
global.h

@@ -3,7 +3,7 @@
 
 
 
-/* ACCESS POINT CONFIGURATION */
+/* DEFAULT ACCESS POINT CONFIGURATION */
 #define ACCESS_POINT_NAME  "ESP"
 #define ACCESS_POINT_PASSWORD  "12345678"
 boolean AdminEnabled = false; // Enable Admin Mode for a given Time
@@ -20,7 +20,7 @@ IPAddress UKI_UDP_Master_IP(192, 168, 0, 41);  //default udp address to send to.
 
 int GSR_sensor;
 int loop_counter;
-
+int counter;
 
 
 
@@ -34,11 +34,43 @@ void ConfigureWifi()
   }
 }
 
+void setupWifi() {
+  
+  //if no config in eeprom, start as default access point
+  if (!ReadConfig())  {
+    WiFi.mode(WIFI_AP);
+    WiFi.softAP( ACCESS_POINT_NAME , ACCESS_POINT_PASSWORD);
+    Serial.println("Starting default access point (SSID:ESP, pwd:12345678)");
+    Serial.println(WiFi.softAPIP());
+    }
+  //if config in eeprom, try and connect to wifi, if fail after timeout start access point with config.name SSID
+  else {  
+    WiFi.mode(WIFI_STA);
+    ConfigureWifi();
+    Serial.println("Connecting to configured wifi network");
+    while (WiFi.status() != 3) {
+      counter++;
+      Serial.print(".");
+      Serial.println(WiFi.status());
+
+      if (counter > 50) {
+        Serial.println("failed");
+        Serial.println("Starting as access point, SSID:"+ (String)config.DeviceName.c_str()+" pwd:" + (String)ACCESS_POINT_PASSWORD);
+        WiFi.mode(WIFI_AP);
+        //WiFi.softAP( ACCESS_POINT_NAME , ACCESS_POINT_PASSWORD);
+        WiFi.softAP( config.DeviceName.c_str() , ACCESS_POINT_PASSWORD);
+        Serial.println(WiFi.softAPIP());
+        break;
+        }
+      }
+    } 
+ 
+}
 
 
-void setupWifi(){
+void setupWifi_old(){
   if (!ReadConfig())  {
-    // DEFAULT CONFIG
+    // DEFAULT CONFIG 
     config.ssid = "Freebox-6F7B3C";
     config.password = "accessorem6-gignendi7-insultare!";
     config.dhcp = true;

+ 6 - 11
includes.h

@@ -19,17 +19,12 @@ WiFiUDP UKI_UDP;
 
 
 
-#include "helpers.h"
-
-#include "leds.h"
-#include "eeprom.h"
-#include "global.h"
-#include "web.h"
-
-
-
-
-#include "ota.h"
+#include "helpers.h"  //some helpers functions
+#include "leds.h"     //config and functions relative to leds
+#include "eeprom.h"   //config and functions relative to config permanent storage
+#include "global.h"   //config and functions relative to wifi and access point configuration
+#include "web.h"      //config and functions relative to configuration web server
+#include "ota.h"      //config and functions relative to ota firmware updates
 
 
 

+ 3 - 8
ota.h

@@ -30,21 +30,16 @@ void setupOTA(){
     digitalWrite(Blue_Led, HIGH);
   });
   ArduinoOTA.begin();
+  Serial.println("OTA started");
 }
 
 void loopOTA(){
-  if (loop_counter == 10)  {
-    loop_counter = 0;
-    server.handleClient();
-    Red_Led_State = !Red_Led_State;
-    digitalWrite(Red_Led, Red_Led_State);
-    delay(10);
-    }
+  
   if (loop_counter == 5)  {
     ArduinoOTA.handle();
     delay(10);
     }
-  loop_counter += 1;
+  
   if (Refresh)  {
     Refresh = false;
     ///Serial.println("Refreshing...");

+ 18 - 9
web.h

@@ -112,7 +112,7 @@ void Second_Tick()
 
 
 void setupWebserver(){
-  server.on ( "/", []() {Serial.println("admin.html"); server.send ( 200, "text/html", web_AdminMainPage ); }  );
+  server.on ( "/", []() {server.send ( 200, "text/html", web_AdminMainPage ); } );
   server.on ( "/admin.html", []() {Serial.println("admin.html"); server.send ( 200, "text/html", web_AdminMainPage ); }  );
   server.on ( "/config.html", send_network_configuration_html );
   server.on ( "/info.html", []() { Serial.println("info.html"); server.send ( 200, "text/html", web_Information ); }  );
@@ -125,6 +125,7 @@ void setupWebserver(){
   server.on ( "/admin/infovalues", send_information_values_html );
   server.on ( "/admin/ntpvalues", send_NTP_configuration_values_html );
   server.on ( "/admin/generalvalues", send_general_configuration_values_html);
+  //server.on ( "/admin/devicename", [] () {Serial.println("devicename");    send_devicename_value_html;});
   server.on ( "/admin/devicename",     send_devicename_value_html);
   /* old led management
   server.on ( "/", []() {digitalWrite(Blue_Led, LOW); Serial.println("admin.html"); server.send ( 200, "text/html", web_AdminMainPage ); digitalWrite(Blue_Led, HIGH);  }  );
@@ -146,7 +147,6 @@ void setupWebserver(){
   server.onNotFound ( []() {
     Serial.println("Page Not Found");
     server.send ( 400, "text/html", "Page not Found" );
-//    ledBlink(Blue_Led, 10, 100);
   }  );
   server.begin();
   Serial.println( "HTTP server started" );
@@ -157,13 +157,22 @@ void setupWebserver(){
 
 
 void loopWebserver(){
-  if (AdminEnabled)  {
-    if (AdminTimeOutCounter > AdminTimeOut)   {
-      AdminEnabled = false;
-      Serial.println("Admin Mode disabled!");
-      WiFi.mode(WIFI_STA);
-    }
-  }
+//  if (AdminEnabled)  {
+//    if (AdminTimeOutCounter > AdminTimeOut)   {
+//      AdminEnabled = false;
+//      Serial.println("Admin Mode disabled!");
+//      WiFi.mode(WIFI_STA);
+//    }
+//  }
+  server.handleClient();
+//  if (loop_counter == 10)  {
+//    loop_counter = 0;
+//    server.handleClient();
+//    Red_Led_State = !Red_Led_State;
+//    digitalWrite(Red_Led, Red_Led_State);
+//    delay(10);
+//    }
+//    
   if (config.Update_Time_Via_NTP_Every  > 0 )  {
     if (cNTP_Update > 5 && firstStart)    {
       NTPRefresh();