mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-11 19:59:00 +08:00
Sync with devt git
Move helper functions to static class CONFIG Separate STA and AP information in EEPROM (IP, mode, etc) Allow to change AP or STA data without set as default mode Reorg the wifi setup Add 2 safe mode - if mode is client and failed got to AP with EEPROM setting, if AP failed use default value for AP mode prepare code for SD Direct access
This commit is contained in:
parent
2728b467a1
commit
18210a9cc7
@ -22,6 +22,11 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "webinterface.h"
|
#include "webinterface.h"
|
||||||
|
#ifdef SDCARD_FEATURE
|
||||||
|
#ifndef FS_NO_GLOBALS
|
||||||
|
#define FS_NO_GLOBALS
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
||||||
String COMMAND::buffer_serial;
|
String COMMAND::buffer_serial;
|
||||||
@ -41,14 +46,14 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
break;
|
break;
|
||||||
case 100:
|
case 100:
|
||||||
if (!CONFIG::isSSIDValid(cmd_params.c_str()))Serial.println("\nError");
|
if (!CONFIG::isSSIDValid(cmd_params.c_str()))Serial.println("\nError");
|
||||||
if(!CONFIG::write_string(EP_SSID,cmd_params.c_str())) {
|
if(!CONFIG::write_string(EP_STA_SSID,cmd_params.c_str())) {
|
||||||
Serial.println("\nError");
|
Serial.println("\nError");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println("\nOk");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 101:
|
case 101:
|
||||||
if(!CONFIG::write_string(EP_PASSWORD,cmd_params.c_str())) {
|
if(!CONFIG::write_string(EP_STA_PASSWORD,cmd_params.c_str())) {
|
||||||
Serial.println("\nError");
|
Serial.println("\nError");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println("\nOk");
|
||||||
@ -81,7 +86,34 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
} else {
|
} else {
|
||||||
mode=DHCP_MODE;
|
mode=DHCP_MODE;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_IP_MODE,mode)) {
|
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
||||||
|
Serial.println("\nError");
|
||||||
|
} else {
|
||||||
|
Serial.println("\nOk");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 105:
|
||||||
|
if (!CONFIG::isSSIDValid(cmd_params.c_str()))Serial.println("\nError");
|
||||||
|
if(!CONFIG::write_string(EP_AP_SSID,cmd_params.c_str())) {
|
||||||
|
Serial.println("\nError");
|
||||||
|
} else {
|
||||||
|
Serial.println("\nOk");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 106:
|
||||||
|
if(!CONFIG::write_string(EP_AP_PASSWORD,cmd_params.c_str())) {
|
||||||
|
Serial.println("\nError");
|
||||||
|
} else {
|
||||||
|
Serial.println("\nOk");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 107:
|
||||||
|
if (cmd_params=="STATIC") {
|
||||||
|
mode = STATIC_IP_MODE;
|
||||||
|
} else {
|
||||||
|
mode=DHCP_MODE;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
||||||
Serial.println("\nError");
|
Serial.println("\nError");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println("\nOk");
|
||||||
@ -211,6 +243,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
void COMMAND::check_command(String buffer)
|
void COMMAND::check_command(String buffer)
|
||||||
{
|
{
|
||||||
String buffer2;
|
String buffer2;
|
||||||
|
//if direct access to SDCard no need to handle the M20 command answer
|
||||||
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
static bool bfileslist=false;
|
static bool bfileslist=false;
|
||||||
static uint32_t start_list=0;
|
static uint32_t start_list=0;
|
||||||
//if SD list is not on going
|
//if SD list is not on going
|
||||||
@ -229,6 +263,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
(web_interface->blockserial) = true;
|
(web_interface->blockserial) = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#ifdef TEMP_MONITORING_FEATURE
|
#ifdef TEMP_MONITORING_FEATURE
|
||||||
int Tpos = buffer.indexOf("T:");
|
int Tpos = buffer.indexOf("T:");
|
||||||
#endif
|
#endif
|
||||||
@ -360,6 +395,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
} else { //listing file is on going
|
} else { //listing file is on going
|
||||||
//check if we are too long
|
//check if we are too long
|
||||||
if ((millis()-start_list)>30000) { //timeout in case of problem
|
if ((millis()-start_list)>30000) { //timeout in case of problem
|
||||||
@ -383,6 +419,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//read a buffer in an array
|
//read a buffer in an array
|
||||||
|
293
esp3d/config.cpp
293
esp3d/config.cpp
@ -25,6 +25,17 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CONFIG::esp_restart(){
|
||||||
|
LOG("Restarting\n")
|
||||||
|
Serial.flush();
|
||||||
|
delay(500);
|
||||||
|
Serial.swap();
|
||||||
|
delay(100);
|
||||||
|
ESP.restart();
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CONFIG::isHostnameValid(const char * hostname)
|
bool CONFIG::isHostnameValid(const char * hostname)
|
||||||
@ -166,12 +177,62 @@ String CONFIG::formatBytes(size_t bytes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//helper to convert string to IP
|
||||||
|
//do not use IPAddress.fromString() because lack of check point and error result
|
||||||
|
//return number of parts
|
||||||
|
byte CONFIG::split_ip (const char * ptr,byte * part)
|
||||||
|
{
|
||||||
|
if (strlen(ptr)>15 || strlen(ptr)< 7) {
|
||||||
|
part[0]=0;
|
||||||
|
part[1]=0;
|
||||||
|
part[2]=0;
|
||||||
|
part[3]=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char pstart [16];
|
||||||
|
char * ptr2;
|
||||||
|
strcpy(pstart,ptr);
|
||||||
|
ptr2 = pstart;
|
||||||
|
byte i = strlen(pstart);
|
||||||
|
byte pos = 0;
|
||||||
|
for (byte j=0; j<i; j++) {
|
||||||
|
if (pstart[j]=='.') {
|
||||||
|
if (pos==4) {
|
||||||
|
part[0]=0;
|
||||||
|
part[1]=0;
|
||||||
|
part[2]=0;
|
||||||
|
part[3]=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
pstart[j]=0x0;
|
||||||
|
part[pos]=atoi(ptr2);
|
||||||
|
pos++;
|
||||||
|
ptr2 = &pstart[j+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
part[pos]=atoi(ptr2);
|
||||||
|
return pos+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//just simple helper to convert mac address to string
|
||||||
|
char * CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH])
|
||||||
|
{
|
||||||
|
static char macstr [18];
|
||||||
|
if (0>sprintf(macstr,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) {
|
||||||
|
strcpy (macstr, "00:00:00:00:00:00");
|
||||||
|
}
|
||||||
|
return macstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//read a string
|
//read a string
|
||||||
//a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char
|
//a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char
|
||||||
bool CONFIG::read_string(int pos, char byte_buffer[], int size_max)
|
bool CONFIG::read_string(int pos, char byte_buffer[], int size_max)
|
||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
|
LOG("Error read string\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -198,6 +259,7 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) {
|
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) {
|
||||||
|
LOG("Error read string\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
byte b = 13; // non zero for the while loop below
|
byte b = 13; // non zero for the while loop below
|
||||||
@ -221,6 +283,7 @@ bool CONFIG::read_buffer(int pos, byte byte_buffer[], int size_buffer)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
|
LOG("Error read buffer\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
@ -239,6 +302,7 @@ bool CONFIG::read_byte(int pos, byte * value)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (pos+1 > EEPROM_SIZE) {
|
if (pos+1 > EEPROM_SIZE) {
|
||||||
|
LOG("Error read byte\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -262,10 +326,16 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
|
|||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
switch (pos)
|
switch (pos)
|
||||||
{
|
{
|
||||||
case EP_SSID:
|
case EP_ADMIN_PWD:
|
||||||
|
case EP_USER_PWD:
|
||||||
|
maxsize = MAX_LOCAL_PASSWORD_LENGTH;
|
||||||
|
break;
|
||||||
|
case EP_AP_SSID:
|
||||||
|
case EP_STA_SSID:
|
||||||
maxsize = MAX_SSID_LENGTH;
|
maxsize = MAX_SSID_LENGTH;
|
||||||
break;
|
break;
|
||||||
case EP_PASSWORD:
|
case EP_AP_PASSWORD:
|
||||||
|
case EP_STA_PASSWORD:
|
||||||
maxsize = MAX_PASSWORD_LENGTH;
|
maxsize = MAX_PASSWORD_LENGTH;
|
||||||
break;
|
break;
|
||||||
case EP_HOSTNAME:
|
case EP_HOSTNAME:
|
||||||
@ -276,6 +346,7 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
|
||||||
|
LOG("Error write string\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//copy the value(s)
|
//copy the value(s)
|
||||||
@ -296,6 +367,7 @@ bool CONFIG::write_buffer(int pos, const byte * byte_buffer, int size_buffer)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
|
LOG("Error write buffer\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -313,6 +385,7 @@ bool CONFIG::write_byte(int pos, const byte value)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (pos+1 > EEPROM_SIZE) {
|
if (pos+1 > EEPROM_SIZE) {
|
||||||
|
LOG("Error write byte\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -327,28 +400,49 @@ bool CONFIG::reset_config()
|
|||||||
if(!CONFIG::write_byte(EP_WIFI_MODE,DEFAULT_WIFI_MODE)) {
|
if(!CONFIG::write_byte(EP_WIFI_MODE,DEFAULT_WIFI_MODE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_string(EP_SSID,FPSTR(DEFAULT_SSID))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_string(EP_PASSWORD,FPSTR(DEFAULT_PASSWORD))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_byte(EP_IP_MODE,DEFAULT_IP_MODE)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_buffer(EP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_buffer(EP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_buffer(EP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,INTEGER_LENGTH)) {
|
if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,INTEGER_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_PHY_MODE,DEFAULT_PHY_MODE)) {
|
if(!CONFIG::write_string(EP_AP_SSID,FPSTR(DEFAULT_AP_SSID))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_string(EP_AP_PASSWORD,FPSTR(DEFAULT_AP_PASSWORD))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_string(EP_STA_SSID,FPSTR(DEFAULT_STA_SSID))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_string(EP_STA_PASSWORD,FPSTR(DEFAULT_STA_PASSWORD))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_byte(EP_AP_IP_MODE,DEFAULT_AP_IP_MODE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_byte(EP_STA_IP_MODE,DEFAULT_STA_IP_MODE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_STA_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_STA_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_byte(EP_STA_PHY_MODE,DEFAULT_PHY_MODE)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_AP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::write_byte(EP_AP_PHY_MODE,DEFAULT_PHY_MODE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE)) {
|
if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE)) {
|
||||||
@ -400,6 +494,32 @@ void CONFIG::print_config()
|
|||||||
uint8_t ipbuf[4];
|
uint8_t ipbuf[4];
|
||||||
byte bbuf=0;
|
byte bbuf=0;
|
||||||
int ibuf=0;
|
int ibuf=0;
|
||||||
|
if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH)) {
|
||||||
|
Serial.print(F("Baud rate: "));
|
||||||
|
Serial.println(ibuf);
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading baud rate"));
|
||||||
|
}
|
||||||
|
if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) {
|
||||||
|
Serial.print(F("Sleep mode: "));
|
||||||
|
if (byte(bbuf)==WIFI_NONE_SLEEP) {
|
||||||
|
Serial.println(F("None"));
|
||||||
|
} else if (byte(bbuf)==WIFI_LIGHT_SLEEP) {
|
||||||
|
Serial.println(F("Light"));
|
||||||
|
} else if (byte(bbuf)==WIFI_MODEM_SLEEP) {
|
||||||
|
Serial.println(F("Modem"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F("???"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading sleep mode"));
|
||||||
|
}
|
||||||
|
if (CONFIG::read_string(EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH)) {
|
||||||
|
Serial.print(F("Hostname: "));
|
||||||
|
Serial.println(sbuf);
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading hostname"));
|
||||||
|
}
|
||||||
if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) {
|
if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) {
|
||||||
Serial.print(F("Mode: "));
|
Serial.print(F("Mode: "));
|
||||||
if (byte(bbuf) == CLIENT_MODE) {
|
if (byte(bbuf) == CLIENT_MODE) {
|
||||||
@ -416,17 +536,37 @@ void CONFIG::print_config()
|
|||||||
Serial.println(F("Error reading mode"));
|
Serial.println(F("Error reading mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
if (CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
Serial.print(F("SSID: "));
|
Serial.print(F("Client SSID: "));
|
||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading SSID"));
|
Serial.println(F("Error reading SSID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_IP_MODE, &bbuf )) {
|
if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) {
|
||||||
Serial.print(F("IP Mode: "));
|
Serial.print(F("STA IP Mode: "));
|
||||||
if (byte(bbuf)==STATIC_IP_MODE) {
|
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||||
Serial.println(F("Static"));
|
Serial.println(F("Static"));
|
||||||
|
if (CONFIG::read_buffer(EP_STA_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("IP: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading IP"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CONFIG::read_buffer(EP_STA_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("Subnet: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading subnet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CONFIG::read_buffer(EP_STA_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("Gateway: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading gateway"));
|
||||||
|
}
|
||||||
} else if (byte(bbuf)==DHCP_MODE) {
|
} else if (byte(bbuf)==DHCP_MODE) {
|
||||||
Serial.println(F("DHCP"));
|
Serial.println(F("DHCP"));
|
||||||
} else {
|
} else {
|
||||||
@ -436,36 +576,8 @@ void CONFIG::print_config()
|
|||||||
Serial.println(F("Error reading IP mode"));
|
Serial.println(F("Error reading IP mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
if (CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) {
|
||||||
Serial.print(F("IP: "));
|
Serial.print(F("STA Phy mode: "));
|
||||||
Serial.println(IPAddress(ipbuf).toString());
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Error reading IP"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
|
||||||
Serial.print(F("Subnet: "));
|
|
||||||
Serial.println(IPAddress(ipbuf).toString());
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Error reading subnet"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
|
||||||
Serial.print(F("Gateway: "));
|
|
||||||
Serial.println(IPAddress(ipbuf).toString());
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Error reading gateway"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH)) {
|
|
||||||
Serial.print(F("Baud rate: "));
|
|
||||||
Serial.println(ibuf);
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Error reading baud rate"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_PHY_MODE, &bbuf )) {
|
|
||||||
Serial.print(F("Phy mode: "));
|
|
||||||
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
||||||
Serial.println(F("11b"));
|
Serial.println(F("11b"));
|
||||||
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||||
@ -479,19 +591,60 @@ void CONFIG::print_config()
|
|||||||
Serial.println(F("Error reading phy mode"));
|
Serial.println(F("Error reading phy mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) {
|
if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
Serial.print(F("Sleep mode: "));
|
Serial.print(F("AP SSID: "));
|
||||||
if (byte(bbuf)==WIFI_NONE_SLEEP) {
|
Serial.println(sbuf);
|
||||||
Serial.println(F("None"));
|
} else {
|
||||||
} else if (byte(bbuf)==WIFI_LIGHT_SLEEP) {
|
Serial.println(F("Error reading SSID"));
|
||||||
Serial.println(F("Light"));
|
}
|
||||||
} else if (byte(bbuf)==WIFI_MODEM_SLEEP) {
|
|
||||||
Serial.println(F("Modem"));
|
if (CONFIG::read_byte(EP_AP_IP_MODE, &bbuf )) {
|
||||||
|
Serial.print(F("AP IP Mode: "));
|
||||||
|
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||||
|
Serial.println(F("Static"));
|
||||||
|
if (CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("IP: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading IP"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CONFIG::read_buffer(EP_AP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("Subnet: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading subnet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CONFIG::read_buffer(EP_AP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||||
|
Serial.print(F("Gateway: "));
|
||||||
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading gateway"));
|
||||||
|
}
|
||||||
|
} else if (byte(bbuf)==DHCP_MODE) {
|
||||||
|
Serial.println(F("DHCP"));
|
||||||
|
} else {
|
||||||
|
Serial.println(intTostr(bbuf));
|
||||||
|
Serial.println(F("???"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Error reading IP mode"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) {
|
||||||
|
Serial.print(F("AP Phy mode: "));
|
||||||
|
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
||||||
|
Serial.println(F("11b"));
|
||||||
|
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||||
|
Serial.println(F("11g"));
|
||||||
|
} else if (byte(bbuf)==WIFI_PHY_MODE_11N) {
|
||||||
|
Serial.println(F("11n"));
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("???"));
|
Serial.println(F("???"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading sleep mode"));
|
Serial.println(F("Error reading phy mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_CHANNEL, &bbuf )) {
|
if (CONFIG::read_byte(EP_CHANNEL, &bbuf )) {
|
||||||
@ -556,13 +709,6 @@ void CONFIG::print_config()
|
|||||||
Serial.println(F("Error reading refresh page"));
|
Serial.println(F("Error reading refresh page"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_string(EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH)) {
|
|
||||||
Serial.print(F("Hostname: "));
|
|
||||||
Serial.println(sbuf);
|
|
||||||
} else {
|
|
||||||
Serial.println(F("Error reading hostname"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) {
|
if (CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) {
|
||||||
Serial.print(F("XY feed rate: "));
|
Serial.print(F("XY feed rate: "));
|
||||||
Serial.println(ibuf);
|
Serial.println(ibuf);
|
||||||
@ -642,6 +788,11 @@ void CONFIG::print_config()
|
|||||||
Serial.println(F("???"));
|
Serial.println(F("???"));
|
||||||
#endif
|
#endif
|
||||||
Serial.print(F("SD Card support: "));
|
Serial.print(F("SD Card support: "));
|
||||||
|
#ifdef SDCARD_FEATURE
|
||||||
|
Serial.println(F("Enabled"));
|
||||||
|
#else
|
||||||
|
Serial.println(F("Disabled"));
|
||||||
|
#endif
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
Serial.print(F("Debug Enabled :"));
|
Serial.print(F("Debug Enabled :"));
|
||||||
#ifdef DEBUG_OUTPUT_SPIFFS
|
#ifdef DEBUG_OUTPUT_SPIFFS
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
#define MARLINKIMBRA 3
|
#define MARLINKIMBRA 3
|
||||||
#define SMOOTHIEWARE 4
|
#define SMOOTHIEWARE 4
|
||||||
|
|
||||||
|
//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware)
|
||||||
|
#define FIRMWARE_TARGET SMOOTHIEWARE
|
||||||
|
|
||||||
//comment to disable
|
//comment to disable
|
||||||
//MDNS_FEATURE: this feature allow type the name defined
|
//MDNS_FEATURE: this feature allow type the name defined
|
||||||
//in web browser by default: http:\\esp8266.local and connect
|
//in web browser by default: http:\\esp8266.local and connect
|
||||||
@ -34,7 +37,7 @@
|
|||||||
#define SSDP_FEATURE
|
#define SSDP_FEATURE
|
||||||
|
|
||||||
//NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
|
//NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
|
||||||
//#define NETBIOS_FEATURE
|
#define NETBIOS_FEATURE
|
||||||
|
|
||||||
//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
|
//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
|
||||||
#define CAPTIVE_PORTAL_FEATURE
|
#define CAPTIVE_PORTAL_FEATURE
|
||||||
@ -77,35 +80,51 @@
|
|||||||
//FLOW_MONITORING_FEATURE : catch the specific answer and store it to variable
|
//FLOW_MONITORING_FEATURE : catch the specific answer and store it to variable
|
||||||
#define FLOW_MONITORING_FEATURE
|
#define FLOW_MONITORING_FEATURE
|
||||||
|
|
||||||
//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware)
|
|
||||||
#define FIRMWARE_TARGET REPETIER4DV
|
|
||||||
|
|
||||||
//DEBUG Flag
|
//DEBUG Flag do not do this when connected to printer !!!
|
||||||
//#define DEBUG_ESP3D
|
//#define DEBUG_ESP3D
|
||||||
//#define DEBUG_OUTPUT_SPIFFS
|
//#define DEBUG_OUTPUT_SPIFFS
|
||||||
|
//#define DEBUG_OUTPUT_SD
|
||||||
#define DEBUG_OUTPUT_SERIAL
|
#define DEBUG_OUTPUT_SERIAL
|
||||||
|
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
#ifdef DEBUG_OUTPUT_SPIFFS
|
#ifdef DEBUG_OUTPUT_SPIFFS
|
||||||
#define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
#define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
||||||
|
#else
|
||||||
|
#ifdef SDCARD_FEATURE
|
||||||
|
#ifdef DEBUG_OUTPUT_SD
|
||||||
|
#define LOG(string) {if(CONFIG::hasSD()){LOCKSD() File logfile = SD.open("/log.txt", "a+");logfile.print(string);logfile.close();RELEASESD()}}
|
||||||
#else
|
#else
|
||||||
#define LOG(string) {Serial.print(string);}
|
#define LOG(string) {Serial.print(string);}
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
#define LOG(string) {Serial.print(string);}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define LOG(string) {}
|
#define LOG(string) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SDCARD_FEATURE
|
||||||
|
#define FSFILE fs::File
|
||||||
|
#define FSDIR fs::Dir
|
||||||
|
#define FSINFO fs::FSInfo
|
||||||
|
#else
|
||||||
#define FSFILE File
|
#define FSFILE File
|
||||||
#define FSDIR fs::Dir
|
#define FSDIR fs::Dir
|
||||||
#define FSINFO FSInfo
|
#define FSINFO FSInfo
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_h
|
#ifndef CONFIG_h
|
||||||
#define CONFIG_h
|
#define CONFIG_h
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
extern "C" {
|
||||||
|
#include "user_interface.h"
|
||||||
|
}
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "0.8.0"
|
#define FW_VERSION "0.8.50"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
|
|
||||||
@ -118,14 +137,14 @@
|
|||||||
//position in EEPROM
|
//position in EEPROM
|
||||||
//AP mode = 1; Station client mode = 2
|
//AP mode = 1; Station client mode = 2
|
||||||
#define EP_WIFI_MODE 0 //1 byte = flag
|
#define EP_WIFI_MODE 0 //1 byte = flag
|
||||||
#define EP_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
#define EP_STA_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||||
#define EP_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
|
#define EP_STA_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
|
||||||
#define EP_IP_MODE 99 //1 byte = flag
|
#define EP_STA_IP_MODE 99 //1 byte = flag
|
||||||
#define EP_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx
|
#define EP_STA_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx
|
||||||
#define EP_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
|
#define EP_STA_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
|
||||||
#define EP_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
|
#define EP_STA_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
|
||||||
#define EP_BAUD_RATE 112 //4 bytes = int
|
#define EP_BAUD_RATE 112 //4 bytes = int
|
||||||
#define EP_PHY_MODE 116 //1 byte = flag
|
#define EP_STA_PHY_MODE 116 //1 byte = flag
|
||||||
#define EP_SLEEP_MODE 117 //1 byte = flag
|
#define EP_SLEEP_MODE 117 //1 byte = flag
|
||||||
#define EP_CHANNEL 118 //1 byte = flag
|
#define EP_CHANNEL 118 //1 byte = flag
|
||||||
#define EP_AUTH_TYPE 119 //1 byte = flag
|
#define EP_AUTH_TYPE 119 //1 byte = flag
|
||||||
@ -139,14 +158,24 @@
|
|||||||
#define EP_E_FEEDRATE 172//4 bytes = int
|
#define EP_E_FEEDRATE 172//4 bytes = int
|
||||||
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||||
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||||
//next available is 218
|
#define EP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||||
//space left 256 - 218 = 38
|
#define EP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
|
||||||
|
#define EP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
|
||||||
|
#define EP_AP_MASK_VALUE 320 //4 bytes xxx.xxx.xxx.xxx
|
||||||
|
#define EP_AP_GATEWAY_VALUE 324 //4 bytes xxx.xxx.xxx.xxx
|
||||||
|
#define EP_AP_IP_MODE 329 //1 byte = flag
|
||||||
|
#define EP_AP_PHY_MODE 182 //1 byte = flag
|
||||||
|
//next available is 330
|
||||||
|
//space left 512 - 330 = 18
|
||||||
|
|
||||||
//default values
|
//default values
|
||||||
#define DEFAULT_WIFI_MODE AP_MODE
|
#define DEFAULT_WIFI_MODE AP_MODE
|
||||||
const char DEFAULT_SSID [] PROGMEM = "ESP8266";
|
const char DEFAULT_AP_SSID [] PROGMEM = "ESP8266";
|
||||||
const char DEFAULT_PASSWORD [] PROGMEM = "12345678";
|
const char DEFAULT_AP_PASSWORD [] PROGMEM = "12345678";
|
||||||
#define DEFAULT_IP_MODE STATIC_IP_MODE
|
const char DEFAULT_STA_SSID [] PROGMEM = "ESP8266";
|
||||||
|
const char DEFAULT_STA_PASSWORD [] PROGMEM = "12345678";
|
||||||
|
const byte DEFAULT_STA_IP_MODE = DHCP_MODE;
|
||||||
|
const byte DEFAULT_AP_IP_MODE = STATIC_IP_MODE;
|
||||||
const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1};
|
const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1};
|
||||||
const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0};
|
const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0};
|
||||||
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
|
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
|
||||||
@ -172,7 +201,7 @@ const char DEFAULT_USER_LOGIN [] PROGMEM = "user";
|
|||||||
|
|
||||||
|
|
||||||
//sizes
|
//sizes
|
||||||
#define EEPROM_SIZE 256 //max is 512
|
#define EEPROM_SIZE 512 //max is 512
|
||||||
#define MAX_SSID_LENGTH 32
|
#define MAX_SSID_LENGTH 32
|
||||||
#define MIN_SSID_LENGTH 1
|
#define MIN_SSID_LENGTH 1
|
||||||
#define MAX_PASSWORD_LENGTH 64
|
#define MAX_PASSWORD_LENGTH 64
|
||||||
@ -182,6 +211,7 @@ const char DEFAULT_USER_LOGIN [] PROGMEM = "user";
|
|||||||
#define IP_LENGTH 4
|
#define IP_LENGTH 4
|
||||||
#define INTEGER_LENGTH 4
|
#define INTEGER_LENGTH 4
|
||||||
#define MAX_HOSTNAME_LENGTH 32
|
#define MAX_HOSTNAME_LENGTH 32
|
||||||
|
#define WL_MAC_ADDR_LENGTH 6
|
||||||
|
|
||||||
class CONFIG
|
class CONFIG
|
||||||
{
|
{
|
||||||
@ -203,6 +233,10 @@ public:
|
|||||||
static bool isIPValid(const char * IP);
|
static bool isIPValid(const char * IP);
|
||||||
static char * intTostr(int value);
|
static char * intTostr(int value);
|
||||||
static String formatBytes(size_t bytes);
|
static String formatBytes(size_t bytes);
|
||||||
|
static char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]);
|
||||||
|
static byte split_ip (const char * ptr,byte * part);
|
||||||
|
static void esp_restart();
|
||||||
|
static void flashfromSD(const char * Filename, int flashtype);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,7 @@ $INCLUDE[header.inc]$
|
|||||||
<div class="panel-heading">Access Point</div>
|
<div class="panel-heading">Access Point</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
<div class="checkbox"><label class="control-label"><input type="checkbox" name="DEFAULT_MODE" $IS_DEFAULT_MODE$>Default Mode</label></div><br>
|
||||||
<div class="form-group $AP_SSID_STATUS$">
|
<div class="form-group $AP_SSID_STATUS$">
|
||||||
<label class="control-label" for="CONFIG1">SSID: </label><br>
|
<label class="control-label" for="CONFIG1">SSID: </label><br>
|
||||||
<input type="text" class="form-control" id="CONFIG1" name="SSID" placeholder="SSID (8~32)" max="32" value="$AP_SSID$" style="width: auto;"></div>
|
<input type="text" class="form-control" id="CONFIG1" name="SSID" placeholder="SSID (8~32)" max="32" value="$AP_SSID$" style="width: auto;"></div>
|
||||||
|
@ -10,6 +10,7 @@ $INCLUDE[header.inc]$
|
|||||||
<tbody>$AVAILABLE_AP[<tr><th>#$ROW_NUMBER$</th><td style="cursor:hand;" onclick="document.getElementById('CONFIG1').value='$AP_SSID$';">$AP_SSID$</td><td>$AP_SIGNAL$</td><td>$IS_PROTECTED$</td></tr>]$</tbody>
|
<tbody>$AVAILABLE_AP[<tr><th>#$ROW_NUMBER$</th><td style="cursor:hand;" onclick="document.getElementById('CONFIG1').value='$AP_SSID$';">$AP_SSID$</td><td>$AP_SIGNAL$</td><td>$IS_PROTECTED$</td></tr>]$</tbody>
|
||||||
</table>
|
</table>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
<div class="checkbox"><label class="control-label"><input type="checkbox" name="DEFAULT_MODE" $IS_DEFAULT_MODE$>Default Mode</label></div><br>
|
||||||
<div class="form-group $STA_SSID_STATUS$" ><label class="control-label" for="CONFIG1">SSID: </label><br>
|
<div class="form-group $STA_SSID_STATUS$" ><label class="control-label" for="CONFIG1">SSID: </label><br>
|
||||||
<input type="text" class="form-control" id="CONFIG1" name="SSID" placeholder="SSID (8~32)" value="$STA_SSID$" max="32" style="width: auto;"></div>
|
<input type="text" class="form-control" id="CONFIG1" name="SSID" placeholder="SSID (8~32)" value="$STA_SSID$" max="32" style="width: auto;"></div>
|
||||||
<div class="form-group $STA_PASSWORD_STATUS$"><label class="control-label"for="CONFIG2">Password:</label><br>
|
<div class="form-group $STA_PASSWORD_STATUS$"><label class="control-label"for="CONFIG2">Password:</label><br>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
$INCLUDE[header.inc]$
|
$INCLUDE[header.inc]$
|
||||||
$INCLUDE[css2.inc]$
|
$INCLUDE[css2.inc]$
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="control_expanded = expand_collapse(control_expanded,'pin_control','control')" id="pin_control">▼</div></td><td>Control</td></tr></table></div>
|
<div class="panel-heading" ><div class="btnimg" style="float:left;" onclick="control_expanded = expand_collapse(control_expanded,'pin_control','control')" id="pin_control">▼</div> Control</div>
|
||||||
<div class="panel-body" id="control">
|
<div class="panel-body" id="control">
|
||||||
<table>
|
<table>
|
||||||
<tr><td style="padding:0px;">
|
<tr><td style="padding:0px;">
|
||||||
@ -40,9 +40,20 @@ $INCLUDE[css2.inc]$
|
|||||||
<td>0<input id="rangeinputspeed" type="range" min=0 max=300 onchange="Updatenumber('speed');">300</td>
|
<td>0<input id="rangeinputspeed" type="range" min=0 max=300 onchange="Updatenumber('speed');">300</td>
|
||||||
<td><input class="form-control" id="numberinputspeed" type="number" size="3" min=0 max=300 step=1 value=0 onchange="Updaterange('speed');"></td><td>%
|
<td><input class="form-control" id="numberinputspeed" type="number" size="3" min=0 max=300 step=1 value=0 onchange="Updaterange('speed');"></td><td>%
|
||||||
<input type="button" class="btn btn-primary" class="btn btn-primary" value="Set" onclick="SendValue( 'M220 S', 'speed');"></td>
|
<input type="button" class="btn btn-primary" class="btn btn-primary" value="Set" onclick="SendValue( 'M220 S', 'speed');"></td>
|
||||||
<td> </td><td>Status:</td><td id="status" align="center" valign="middle">
|
<td> </td>
|
||||||
<svg width="20" height="20"><circle cx="10" cy="10" r="8" stroke="black" stroke-width="2" fill="white"></circle></svg></td>
|
<td colspan=3>
|
||||||
<td id="status-text" style="width:100px;"></td><td> </td><td class="btnimg" onclick="OnclickEmergency();">
|
<div id="autostatus">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Status:</td>
|
||||||
|
<td id="status" align="center" valign="middle"><svg width="20" height="20"><circle cx="10" cy="10" r="8" stroke="black" stroke-width="2" fill="white"></circle></svg></td>
|
||||||
|
<td id="status-text" style="width:100px;"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div id="manualstatus"><input type="button" class="btn btn-primary" value="Refresh" onclick="getstatus();" ></div>
|
||||||
|
</td>
|
||||||
|
<td> </td><td class="btnimg" onclick="OnclickEmergency();">
|
||||||
<svg width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" stroke="black" stroke-width="2" fill="red" />
|
<svg width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" stroke="black" stroke-width="2" fill="red" />
|
||||||
<circle cx="20" cy="20" r="10" stroke="black" stroke-width="4" fill="red" /><rect x="15" y="8" width="10" height="10" style="fill:red;stroke-width:1;stroke:red" />
|
<circle cx="20" cy="20" r="10" stroke="black" stroke-width="4" fill="red" /><rect x="15" y="8" width="10" height="10" style="fill:red;stroke-width:1;stroke:red" />
|
||||||
<rect x="18" y="6" rx="1" ry="1" width="4" height="14" style="fill:black;stroke-width:1;stroke:black" /></svg></td>
|
<rect x="18" y="6" rx="1" ry="1" width="4" height="14" style="fill:black;stroke-width:1;stroke:black" /></svg></td>
|
||||||
@ -67,7 +78,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="command_expanded = expand_collapse(command_expanded,'pin_command','command')" id="pin_command">▼</div></td><td>Command</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="command_expanded = expand_collapse(command_expanded,'pin_command','command')" id="pin_command">▼</div> Command</div>
|
||||||
<div class="panel-body" id="command">
|
<div class="panel-body" id="command">
|
||||||
<table width="100%"><tr>
|
<table width="100%"><tr>
|
||||||
<td width="100%"><input class="form-control" id="cmd" type="text" style="width: 100%;"></td>
|
<td width="100%"><input class="form-control" id="cmd" type="text" style="width: 100%;"></td>
|
||||||
@ -76,7 +87,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="information_expanded = expand_collapse(information_expanded,'pin_information','information')" id="pin_information">▼</div></td><td>Information</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="information_expanded = expand_collapse(information_expanded,'pin_information','information')" id="pin_information">▼</div> Information</div>
|
||||||
<div class="panel-body" id="information">
|
<div class="panel-body" id="information">
|
||||||
<table><tr><td>
|
<table><tr><td>
|
||||||
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Info log ?'))Sendcommand('[ESP999]INFO');">
|
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Info log ?'))Sendcommand('[ESP999]INFO');">
|
||||||
@ -88,7 +99,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="error_expanded = expand_collapse(error_expanded,'pin_error','error')" id="pin_error">▼</div></td><td>Error</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="error_expanded = expand_collapse(error_expanded,'pin_error','error')" id="pin_error">▼</div> Error</div>
|
||||||
<div class="panel-body" id="error">
|
<div class="panel-body" id="error">
|
||||||
<table><tr><td>
|
<table><tr><td>
|
||||||
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Error log ?'))Sendcommand('[ESP999]ERROR');">
|
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Error log ?'))Sendcommand('[ESP999]ERROR');">
|
||||||
@ -100,7 +111,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="status_expanded = expand_collapse(status_expanded,'pin_status','statusdisplay')" id="pin_status">▼</div></td><td>Status</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="status_expanded = expand_collapse(status_expanded,'pin_status','statusdisplay')" id="pin_status">▼</div> Status</div>
|
||||||
<div class="panel-body" id="statusdisplay">
|
<div class="panel-body" id="statusdisplay">
|
||||||
<table><tr><td>
|
<table><tr><td>
|
||||||
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Status log ?'))Sendcommand('[ESP999]STATUS');">
|
<center><table><tr><td><div class="btnimg" onclick="if(confirm('Clear Status log ?'))Sendcommand('[ESP999]STATUS');">
|
||||||
@ -112,7 +123,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="printcommands_expanded = expand_collapse(printcommands_expanded,'pin_printcommands','printcommands')" id="pin_printcommands">▼</div></td><td>Print</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="printcommands_expanded = expand_collapse(printcommands_expanded,'pin_printcommands','printcommands')" id="pin_printcommands">▼</div> Print</div>
|
||||||
<div class="panel-body" id="printcommands">
|
<div class="panel-body" id="printcommands">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@ -129,7 +140,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="jog_expanded = expand_collapse(jog_expanded,'pin_jog','jogcommands')" id="pin_jog">▼</div></td><td>Jog</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="jog_expanded = expand_collapse(jog_expanded,'pin_jog','jogcommands')" id="pin_jog">▼</div> Jog</div>
|
||||||
<div class="panel-body" id="jogcommands">
|
<div class="panel-body" id="jogcommands">
|
||||||
<table>
|
<table>
|
||||||
<tr align="center" valign="middle">
|
<tr align="center" valign="middle">
|
||||||
@ -329,7 +340,7 @@ $INCLUDE[css2.inc]$
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-heading"><table><tr><td><div class="btnimg" onclick="filemanager_expanded = expand_collapse(filemanager_expanded,'pin_filemanager','filemanager')" id="pin_filemanager">▼</div></td><td>SD Files</td></tr></table></div>
|
<div class="panel-heading"><div class="btnimg" style="float:left;" onclick="filemanager_expanded = expand_collapse(filemanager_expanded,'pin_filemanager','filemanager')" id="pin_filemanager">▼</div> SD Files</div>
|
||||||
<div class="panel-body" id="filemanager">
|
<div class="panel-body" id="filemanager">
|
||||||
<input type="file" id="file-select" name="myfiles[]" multiple/>
|
<input type="file" id="file-select" name="myfiles[]" multiple/>
|
||||||
<input class="btn btn-primary" type="button" id="upload-button" onclick="Sendfile();" value="Upload"/> <progress style="visibility:hidden;" name='prg' id='prg' max='100'></progress>
|
<input class="btn btn-primary" type="button" id="upload-button" onclick="Sendfile();" value="Upload"/> <progress style="visibility:hidden;" name='prg' id='prg' max='100'></progress>
|
||||||
@ -821,7 +832,13 @@ xmlhttp.send(formData);
|
|||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
refreshSDfiles();
|
refreshSDfiles();
|
||||||
if ($REFRESH_PAGE$)setInterval(function(){getstatus();},$REFRESH_PAGE$);
|
if ($REFRESH_PAGE$){
|
||||||
|
setInterval(function(){getstatus();},$REFRESH_PAGE$);
|
||||||
|
document.getElementById('manualstatus').style.display = "none";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('autostatus').style.display = "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function printfile(filename){
|
function printfile(filename){
|
||||||
|
@ -55,16 +55,18 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
bool breset_config=false;
|
||||||
|
long baud_rate=0;
|
||||||
|
web_interface = NULL;
|
||||||
|
data_server = NULL;
|
||||||
// init:
|
// init:
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
Serial.begin(DEFAULT_BAUD_RATE);
|
Serial.begin(DEFAULT_BAUD_RATE);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
LOG("Debug Serial set\n")
|
LOG("\nDebug Serial set\n")
|
||||||
#endif
|
#endif
|
||||||
web_interface = NULL;
|
//WiFi.disconnect();
|
||||||
data_server = NULL;
|
WiFi.mode(WIFI_OFF);
|
||||||
WiFi.disconnect();
|
|
||||||
bool breset_config=false;
|
|
||||||
#ifdef RECOVERY_FEATURE
|
#ifdef RECOVERY_FEATURE
|
||||||
delay(8000);
|
delay(8000);
|
||||||
//check if reset config is requested
|
//check if reset config is requested
|
||||||
@ -73,54 +75,62 @@ void setup()
|
|||||||
breset_config=true; //if requested =>reset settings
|
breset_config=true; //if requested =>reset settings
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//default baud rate
|
|
||||||
long baud_rate=0;
|
|
||||||
|
|
||||||
//check if EEPROM has value
|
//check if EEPROM has value
|
||||||
if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGTH)) {
|
if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGTH)) {
|
||||||
//check if baud value is one of allowed ones
|
//check if baud value is one of allowed ones
|
||||||
if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) {
|
if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) {
|
||||||
|
LOG("Error for EEPROM baud rate\n")
|
||||||
breset_config=true; //baud rate is incorrect =>reset settings
|
breset_config=true; //baud rate is incorrect =>reset settings
|
||||||
}
|
}
|
||||||
if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001) {
|
if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001) {
|
||||||
breset_config=true; //out of range =>reset settings
|
breset_config=true; //out of range =>reset settings
|
||||||
|
LOG("Error for EEPROM port values\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
breset_config=true; //cannot access to config settings=> reset settings
|
breset_config=true; //cannot access to config settings=> reset settings
|
||||||
|
LOG("Error no EEPROM access\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
SPIFFS.begin();
|
|
||||||
//reset is requested
|
//reset is requested
|
||||||
if(breset_config) {
|
if(breset_config) {
|
||||||
//update EEPROM with default settings
|
//update EEPROM with default settings
|
||||||
Serial.begin(DEFAULT_BAUD_RATE);
|
Serial.begin(DEFAULT_BAUD_RATE);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
Serial.println(F("M117 ESP EEPROM reset"));
|
Serial.println(F("M117 ESP EEPROM reset"));
|
||||||
|
#ifdef DEBUG_ESP3D
|
||||||
|
CONFIG::print_config();
|
||||||
|
delay(1000);
|
||||||
|
#endif
|
||||||
CONFIG::reset_config();
|
CONFIG::reset_config();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
//put some default value to a void some exception at first start
|
//put some default value to a void some exception at first start
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
||||||
Serial.flush();
|
CONFIG::esp_restart();
|
||||||
delay(500);
|
|
||||||
Serial.swap();
|
|
||||||
delay(100);
|
|
||||||
//restart once reset config is done
|
|
||||||
ESP.restart();
|
|
||||||
while (1) {
|
|
||||||
delay(1);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
|
||||||
|
LOG("\n");
|
||||||
|
delay(500);
|
||||||
|
Serial.flush();
|
||||||
|
#endif
|
||||||
//setup serial
|
//setup serial
|
||||||
Serial.begin(baud_rate);
|
Serial.begin(baud_rate);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
LOG("Serial Set\n");
|
LOG("Serial Set\n");
|
||||||
wifi_config.baud_rate=baud_rate;
|
wifi_config.baud_rate=baud_rate;
|
||||||
|
//Update is done if any so should be Ok
|
||||||
|
SPIFFS.begin();
|
||||||
|
|
||||||
//setup wifi according settings
|
//setup wifi according settings
|
||||||
if (!wifi_config.Setup()) {
|
if (!wifi_config.Setup()) {
|
||||||
|
Serial.println(F("M117 Safe mode 1"));
|
||||||
|
//try again in AP mode
|
||||||
|
if (!wifi_config.Setup(true)){
|
||||||
|
Serial.println(F("M117 Safe mode 2"));
|
||||||
wifi_config.Safe_Setup();
|
wifi_config.Safe_Setup();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
delay(1000);
|
delay(1000);
|
||||||
//start web interface
|
//start web interface
|
||||||
web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port);
|
web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port);
|
||||||
@ -242,13 +252,6 @@ void loop()
|
|||||||
COMMAND::read_buffer_serial(sbuf, len);
|
COMMAND::read_buffer_serial(sbuf, len);
|
||||||
}
|
}
|
||||||
if (web_interface->restartmodule) {
|
if (web_interface->restartmodule) {
|
||||||
Serial.flush();
|
CONFIG::esp_restart();
|
||||||
delay(500);
|
|
||||||
Serial.swap();
|
|
||||||
delay(100);
|
|
||||||
ESP.restart();
|
|
||||||
while (1) {
|
|
||||||
delay(1);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,6 @@
|
|||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
extern "C" {
|
|
||||||
#include "user_interface.h"
|
|
||||||
}
|
|
||||||
#include "LinkedList.h"
|
#include "LinkedList.h"
|
||||||
#include "storestrings.h"
|
#include "storestrings.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -210,8 +207,9 @@ const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$";
|
|||||||
const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$";
|
const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$";
|
||||||
const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$";
|
const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$";
|
||||||
const char KEY_LOGIN_ID [] PROGMEM = "$LOGIN_ID$";
|
const char KEY_LOGIN_ID [] PROGMEM = "$LOGIN_ID$";
|
||||||
|
const char KEY_IS_DEFAULT_MODE [] PROGMEM = "$IS_DEFAULT_MODE$";
|
||||||
|
|
||||||
|
|
||||||
//TODO: should be in webserver class
|
|
||||||
bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList )
|
bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList )
|
||||||
{
|
{
|
||||||
if(KeysList.size() != ValuesList.size()) { //Sanity check
|
if(KeysList.size() != ValuesList.size()) { //Sanity check
|
||||||
@ -745,7 +743,7 @@ void handle_web_interface_home()
|
|||||||
//BSSID
|
//BSSID
|
||||||
stmp = "$MAC_CONNECTED["+String(client_counter)+"]$";
|
stmp = "$MAC_CONNECTED["+String(client_counter)+"]$";
|
||||||
KeysList.add(stmp.c_str());
|
KeysList.add(stmp.c_str());
|
||||||
ValuesList.add(wifi_config.mac2str(station->bssid));
|
ValuesList.add(CONFIG::mac2str(station->bssid));
|
||||||
//IP
|
//IP
|
||||||
stmp = "$IP_CONNECTED["+String(client_counter)+"]$";
|
stmp = "$IP_CONNECTED["+String(client_counter)+"]$";
|
||||||
KeysList.add(stmp.c_str());
|
KeysList.add(stmp.c_str());
|
||||||
@ -772,7 +770,7 @@ void handle_web_interface_home()
|
|||||||
}
|
}
|
||||||
//AP mac address
|
//AP mac address
|
||||||
KeysList.add(FPSTR(KEY_AP_MAC));
|
KeysList.add(FPSTR(KEY_AP_MAC));
|
||||||
ValuesList.add(wifi_config.mac2str(WiFi.softAPmacAddress(mac)));
|
ValuesList.add(CONFIG::mac2str(WiFi.softAPmacAddress(mac)));
|
||||||
//AP configuration
|
//AP configuration
|
||||||
if (wifi_softap_get_config(&apconfig)) {
|
if (wifi_softap_get_config(&apconfig)) {
|
||||||
//SSID
|
//SSID
|
||||||
@ -864,7 +862,7 @@ void handle_web_interface_home()
|
|||||||
}
|
}
|
||||||
//STA mac address
|
//STA mac address
|
||||||
KeysList.add(FPSTR(KEY_STA_MAC));
|
KeysList.add(FPSTR(KEY_STA_MAC));
|
||||||
ValuesList.add(wifi_config.mac2str(WiFi.macAddress(mac)));
|
ValuesList.add(CONFIG::mac2str(WiFi.macAddress(mac)));
|
||||||
//SSID used by STA
|
//SSID used by STA
|
||||||
KeysList.add(FPSTR(KEY_STA_SSID));
|
KeysList.add(FPSTR(KEY_STA_SSID));
|
||||||
if (WiFi.SSID().length()==0) {
|
if (WiFi.SSID().length()==0) {
|
||||||
@ -1240,6 +1238,7 @@ void handle_web_interface_configAP()
|
|||||||
bool msg_alert_error=false;
|
bool msg_alert_error=false;
|
||||||
bool msg_alert_success=false;
|
bool msg_alert_success=false;
|
||||||
byte visible_buf;
|
byte visible_buf;
|
||||||
|
byte default_mode;
|
||||||
byte static_ip_buf;
|
byte static_ip_buf;
|
||||||
byte auth_buf;
|
byte auth_buf;
|
||||||
byte channel_buf;
|
byte channel_buf;
|
||||||
@ -1302,6 +1301,15 @@ void handle_web_interface_configAP()
|
|||||||
} else {
|
} else {
|
||||||
visible_buf=0;
|
visible_buf=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Default mode ?
|
||||||
|
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
||||||
|
default_mode=AP_MODE;
|
||||||
|
LOG("Set AP Mode\n")
|
||||||
|
} else {
|
||||||
|
default_mode=CLIENT_MODE;
|
||||||
|
LOG("Set Station mode\n")
|
||||||
|
}
|
||||||
//phy mode
|
//phy mode
|
||||||
phy_mode_buf = byte(web_interface->WebServer.arg("NETWORK").toInt());
|
phy_mode_buf = byte(web_interface->WebServer.arg("NETWORK").toInt());
|
||||||
if (!(phy_mode_buf==WIFI_PHY_MODE_11B||phy_mode_buf==WIFI_PHY_MODE_11G) ) {
|
if (!(phy_mode_buf==WIFI_PHY_MODE_11B||phy_mode_buf==WIFI_PHY_MODE_11G) ) {
|
||||||
@ -1330,8 +1338,10 @@ void handle_web_interface_configAP()
|
|||||||
//Static IP ?
|
//Static IP ?
|
||||||
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
||||||
static_ip_buf=STATIC_IP_MODE;
|
static_ip_buf=STATIC_IP_MODE;
|
||||||
|
LOG("Set Static\n")
|
||||||
} else {
|
} else {
|
||||||
static_ip_buf=DHCP_MODE;
|
static_ip_buf=DHCP_MODE;
|
||||||
|
LOG("Set DHCP\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//IP
|
//IP
|
||||||
@ -1367,20 +1377,20 @@ void handle_web_interface_configAP()
|
|||||||
//if no error apply the change
|
//if no error apply the change
|
||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
//save
|
//save
|
||||||
wifi_config.split_ip(sIP.c_str(),ip_sav);
|
CONFIG::split_ip(sIP.c_str(),ip_sav);
|
||||||
wifi_config.split_ip(sGW.c_str(),gw_sav);
|
CONFIG::split_ip(sGW.c_str(),gw_sav);
|
||||||
wifi_config.split_ip(sMask.c_str(),msk_sav);
|
CONFIG::split_ip(sMask.c_str(),msk_sav);
|
||||||
if((!CONFIG::write_byte(EP_WIFI_MODE,AP_MODE))||
|
if((!CONFIG::write_byte(EP_WIFI_MODE,default_mode))||
|
||||||
(!CONFIG::write_string(EP_SSID,sSSID.c_str()))||
|
(!CONFIG::write_string(EP_AP_SSID,sSSID.c_str()))||
|
||||||
(!CONFIG::write_string(EP_PASSWORD,sPassword.c_str()))||
|
(!CONFIG::write_string(EP_AP_PASSWORD,sPassword.c_str()))||
|
||||||
(!CONFIG::write_byte(EP_SSID_VISIBLE,visible_buf))||
|
(!CONFIG::write_byte(EP_SSID_VISIBLE,visible_buf))||
|
||||||
(!CONFIG::write_byte(EP_PHY_MODE,phy_mode_buf))||
|
(!CONFIG::write_byte(EP_AP_PHY_MODE,phy_mode_buf))||
|
||||||
(!CONFIG::write_byte(EP_CHANNEL,channel_buf)) ||
|
(!CONFIG::write_byte(EP_CHANNEL,channel_buf)) ||
|
||||||
(!CONFIG::write_byte(EP_AUTH_TYPE,auth_buf)) ||
|
(!CONFIG::write_byte(EP_AUTH_TYPE,auth_buf)) ||
|
||||||
(!CONFIG::write_byte(EP_IP_MODE,static_ip_buf)) ||
|
(!CONFIG::write_byte(EP_AP_IP_MODE,static_ip_buf)) ||
|
||||||
(!CONFIG::write_buffer(EP_IP_VALUE,ip_sav,IP_LENGTH))||
|
(!CONFIG::write_buffer(EP_AP_IP_VALUE,ip_sav,IP_LENGTH))||
|
||||||
(!CONFIG::write_buffer(EP_GATEWAY_VALUE,gw_sav,IP_LENGTH))||
|
(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,gw_sav,IP_LENGTH))||
|
||||||
(!CONFIG::write_buffer(EP_MASK_VALUE,msk_sav,IP_LENGTH))) {
|
(!CONFIG::write_buffer(EP_AP_MASK_VALUE,msk_sav,IP_LENGTH))) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg = FPSTR(EEPROM_NOWRITE);
|
smsg = FPSTR(EEPROM_NOWRITE);
|
||||||
} else {
|
} else {
|
||||||
@ -1392,19 +1402,19 @@ void handle_web_interface_configAP()
|
|||||||
|
|
||||||
else { //no submit need to get data from EEPROM
|
else { //no submit need to get data from EEPROM
|
||||||
//ssid
|
//ssid
|
||||||
if (!CONFIG::read_string(EP_SSID, sSSID , MAX_SSID_LENGTH) ) {
|
if (!CONFIG::read_string(EP_AP_SSID, sSSID , MAX_SSID_LENGTH) ) {
|
||||||
sSSID=FPSTR(DEFAULT_SSID);
|
sSSID=FPSTR(DEFAULT_AP_SSID);
|
||||||
}
|
}
|
||||||
//password
|
//password
|
||||||
if (!CONFIG::read_string(EP_PASSWORD, sPassword , MAX_PASSWORD_LENGTH) ) {
|
if (!CONFIG::read_string(EP_AP_PASSWORD, sPassword , MAX_PASSWORD_LENGTH) ) {
|
||||||
sPassword=FPSTR(DEFAULT_PASSWORD);
|
sPassword=FPSTR(DEFAULT_AP_PASSWORD);
|
||||||
}
|
}
|
||||||
//ssid visible ?
|
//ssid visible ?
|
||||||
if (!CONFIG::read_byte(EP_SSID_VISIBLE, &visible_buf )) {
|
if (!CONFIG::read_byte(EP_SSID_VISIBLE, &visible_buf )) {
|
||||||
visible_buf=DEFAULT_SSID_VISIBLE;
|
visible_buf=DEFAULT_SSID_VISIBLE;
|
||||||
}
|
}
|
||||||
//phy mode
|
//phy mode
|
||||||
if (!CONFIG::read_byte(EP_PHY_MODE, &phy_mode_buf )) {
|
if (!CONFIG::read_byte(EP_AP_PHY_MODE, &phy_mode_buf )) {
|
||||||
phy_mode_buf=DEFAULT_PHY_MODE;
|
phy_mode_buf=DEFAULT_PHY_MODE;
|
||||||
}
|
}
|
||||||
//authentification
|
//authentification
|
||||||
@ -1415,26 +1425,30 @@ void handle_web_interface_configAP()
|
|||||||
if (!CONFIG::read_byte(EP_CHANNEL, &channel_buf )) {
|
if (!CONFIG::read_byte(EP_CHANNEL, &channel_buf )) {
|
||||||
channel_buf=DEFAULT_CHANNEL;
|
channel_buf=DEFAULT_CHANNEL;
|
||||||
}
|
}
|
||||||
|
//Default mode ?
|
||||||
|
if (!CONFIG::read_byte(EP_WIFI_MODE, &default_mode )) {
|
||||||
|
default_mode=AP_MODE;
|
||||||
|
}
|
||||||
//static IP ?
|
//static IP ?
|
||||||
if (!CONFIG::read_byte(EP_IP_MODE, &static_ip_buf )) {
|
if (!CONFIG::read_byte(EP_AP_IP_MODE, &static_ip_buf )) {
|
||||||
static_ip_buf=DEFAULT_IP_MODE;
|
static_ip_buf=DEFAULT_AP_IP_MODE;
|
||||||
}
|
}
|
||||||
//IP for static IP
|
//IP for static IP
|
||||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
||||||
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
||||||
}
|
}
|
||||||
//GW for static IP
|
//GW for static IP
|
||||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
||||||
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
||||||
} else {
|
} else {
|
||||||
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Subnet for static IP
|
//Subnet for static IP
|
||||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
||||||
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
||||||
} else {
|
} else {
|
||||||
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
||||||
@ -1458,7 +1472,13 @@ void handle_web_interface_configAP()
|
|||||||
} else {
|
} else {
|
||||||
ValuesList.add("");
|
ValuesList.add("");
|
||||||
}
|
}
|
||||||
|
//Default mode ?
|
||||||
|
KeysList.add(FPSTR(KEY_IS_DEFAULT_MODE));
|
||||||
|
if ( default_mode==AP_MODE) {
|
||||||
|
ValuesList.add(FPSTR(VALUE_CHECKED));
|
||||||
|
} else {
|
||||||
|
ValuesList.add("");
|
||||||
|
}
|
||||||
//network
|
//network
|
||||||
ipos = 0;
|
ipos = 0;
|
||||||
stmp="";
|
stmp="";
|
||||||
@ -1585,6 +1605,7 @@ void handle_web_interface_configSTA()
|
|||||||
String sSSID,sPassword,sIP,sGW,sMask,sHostname;
|
String sSSID,sPassword,sIP,sGW,sMask,sHostname;
|
||||||
bool msg_alert_error=false;
|
bool msg_alert_error=false;
|
||||||
bool msg_alert_success=false;
|
bool msg_alert_success=false;
|
||||||
|
byte default_mode;
|
||||||
byte static_ip_buf;
|
byte static_ip_buf;
|
||||||
byte phy_mode_buf;
|
byte phy_mode_buf;
|
||||||
byte ip_sav[4];
|
byte ip_sav[4];
|
||||||
@ -1655,7 +1676,14 @@ void handle_web_interface_configSTA()
|
|||||||
KeysList.add(FPSTR(KEY_NETWORK_OPTION_LIST_STATUS));
|
KeysList.add(FPSTR(KEY_NETWORK_OPTION_LIST_STATUS));
|
||||||
ValuesList.add(FPSTR(VALUE_HAS_ERROR));
|
ValuesList.add(FPSTR(VALUE_HAS_ERROR));
|
||||||
}
|
}
|
||||||
|
//Default mode ?
|
||||||
|
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
||||||
|
default_mode=CLIENT_MODE;
|
||||||
|
LOG("Set STA mode\n")
|
||||||
|
} else {
|
||||||
|
default_mode=AP_MODE;
|
||||||
|
LOG("Set AP mode\n")
|
||||||
|
}
|
||||||
//Static IP ?
|
//Static IP ?
|
||||||
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
||||||
static_ip_buf=STATIC_IP_MODE;
|
static_ip_buf=STATIC_IP_MODE;
|
||||||
@ -1696,18 +1724,18 @@ void handle_web_interface_configSTA()
|
|||||||
//no error ? then save
|
//no error ? then save
|
||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
//save
|
//save
|
||||||
wifi_config.split_ip(sIP.c_str(),ip_sav);
|
CONFIG::split_ip(sIP.c_str(),ip_sav);
|
||||||
wifi_config.split_ip(sGW.c_str(),gw_sav);
|
CONFIG::split_ip(sGW.c_str(),gw_sav);
|
||||||
wifi_config.split_ip(sMask.c_str(),msk_sav);
|
CONFIG::split_ip(sMask.c_str(),msk_sav);
|
||||||
if((!CONFIG::write_byte(EP_WIFI_MODE,CLIENT_MODE))||
|
if((!CONFIG::write_byte(EP_WIFI_MODE,default_mode))||
|
||||||
(!CONFIG::write_string(EP_SSID,sSSID.c_str()))||
|
(!CONFIG::write_string(EP_STA_SSID,sSSID.c_str()))||
|
||||||
(!CONFIG::write_string(EP_PASSWORD,sPassword.c_str()))||
|
(!CONFIG::write_string(EP_STA_PASSWORD,sPassword.c_str()))||
|
||||||
(!CONFIG::write_string(EP_HOSTNAME,sHostname.c_str()))||
|
(!CONFIG::write_string(EP_HOSTNAME,sHostname.c_str()))||
|
||||||
(!CONFIG::write_byte(EP_PHY_MODE,phy_mode_buf))||
|
(!CONFIG::write_byte(EP_STA_PHY_MODE,phy_mode_buf))||
|
||||||
(!CONFIG::write_byte(EP_IP_MODE,static_ip_buf)) ||
|
(!CONFIG::write_byte(EP_STA_IP_MODE,static_ip_buf)) ||
|
||||||
(!CONFIG::write_buffer(EP_IP_VALUE,ip_sav,IP_LENGTH))||
|
(!CONFIG::write_buffer(EP_STA_IP_VALUE,ip_sav,IP_LENGTH))||
|
||||||
(!CONFIG::write_buffer(EP_GATEWAY_VALUE,gw_sav,IP_LENGTH))||
|
(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,gw_sav,IP_LENGTH))||
|
||||||
(!CONFIG::write_buffer(EP_MASK_VALUE,msk_sav,IP_LENGTH))) {
|
(!CONFIG::write_buffer(EP_STA_MASK_VALUE,msk_sav,IP_LENGTH))) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg = FPSTR(EEPROM_NOWRITE);
|
smsg = FPSTR(EEPROM_NOWRITE);
|
||||||
} else {
|
} else {
|
||||||
@ -1717,39 +1745,43 @@ void handle_web_interface_configSTA()
|
|||||||
}
|
}
|
||||||
} else { //no submit, need to get data from EEPROM
|
} else { //no submit, need to get data from EEPROM
|
||||||
//ssid
|
//ssid
|
||||||
if (!CONFIG::read_string(EP_SSID, sSSID , MAX_SSID_LENGTH) ) {
|
if (!CONFIG::read_string(EP_STA_SSID, sSSID , MAX_SSID_LENGTH) ) {
|
||||||
sSSID=FPSTR(DEFAULT_SSID);
|
sSSID=FPSTR(DEFAULT_STA_SSID);
|
||||||
}
|
}
|
||||||
//password
|
//password
|
||||||
if (!CONFIG::read_string(EP_PASSWORD, sPassword , MAX_PASSWORD_LENGTH) ) {
|
if (!CONFIG::read_string(EP_STA_PASSWORD, sPassword , MAX_PASSWORD_LENGTH) ) {
|
||||||
sPassword=FPSTR(DEFAULT_PASSWORD);
|
sPassword=FPSTR(DEFAULT_STA_PASSWORD);
|
||||||
}
|
}
|
||||||
//hostname
|
//hostname
|
||||||
if (!CONFIG::read_string(EP_HOSTNAME, sHostname , MAX_HOSTNAME_LENGTH) ) {
|
if (!CONFIG::read_string(EP_HOSTNAME, sHostname , MAX_HOSTNAME_LENGTH) ) {
|
||||||
sHostname=wifi_config.get_default_hostname();
|
sHostname=wifi_config.get_default_hostname();
|
||||||
|
}
|
||||||
|
//Default mode ?
|
||||||
|
if (!CONFIG::read_byte(EP_WIFI_MODE, &default_mode )) {
|
||||||
|
default_mode=AP_MODE;
|
||||||
}
|
}
|
||||||
//phy mode
|
//phy mode
|
||||||
if (!CONFIG::read_byte(EP_PHY_MODE, &phy_mode_buf )) {
|
if (!CONFIG::read_byte(EP_STA_PHY_MODE, &phy_mode_buf )) {
|
||||||
phy_mode_buf=DEFAULT_PHY_MODE;
|
phy_mode_buf=DEFAULT_PHY_MODE;
|
||||||
}
|
}
|
||||||
//static IP ?
|
//static IP ?
|
||||||
if (!CONFIG::read_byte(EP_IP_MODE, &static_ip_buf )) {
|
if (!CONFIG::read_byte(EP_STA_IP_MODE, &static_ip_buf )) {
|
||||||
static_ip_buf=DEFAULT_IP_MODE;
|
static_ip_buf=DEFAULT_STA_IP_MODE;
|
||||||
}
|
}
|
||||||
//IP for static IP
|
//IP for static IP
|
||||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
||||||
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
||||||
} else {
|
} else {
|
||||||
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
||||||
}
|
}
|
||||||
//GW for static IP
|
//GW for static IP
|
||||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
||||||
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
||||||
} else {
|
} else {
|
||||||
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
||||||
}
|
}
|
||||||
//Subnet for static IP
|
//Subnet for static IP
|
||||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
||||||
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
||||||
} else {
|
} else {
|
||||||
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
||||||
@ -1768,6 +1800,14 @@ void handle_web_interface_configSTA()
|
|||||||
KeysList.add(FPSTR(KEY_HOSTNAME));
|
KeysList.add(FPSTR(KEY_HOSTNAME));
|
||||||
ValuesList.add(sHostname);
|
ValuesList.add(sHostname);
|
||||||
|
|
||||||
|
//Default mode ?
|
||||||
|
KeysList.add(FPSTR(KEY_IS_DEFAULT_MODE));
|
||||||
|
if ( default_mode==CLIENT_MODE) {
|
||||||
|
ValuesList.add(FPSTR(VALUE_CHECKED));
|
||||||
|
} else {
|
||||||
|
ValuesList.add("");
|
||||||
|
}
|
||||||
|
|
||||||
//network
|
//network
|
||||||
ipos = 0;
|
ipos = 0;
|
||||||
stmp="";
|
stmp="";
|
||||||
@ -2613,6 +2653,8 @@ void SDFileupload()
|
|||||||
#ifdef WEB_UPDATE_FEATURE
|
#ifdef WEB_UPDATE_FEATURE
|
||||||
void WebUpdateUpload()
|
void WebUpdateUpload()
|
||||||
{
|
{
|
||||||
|
static size_t last_upload_update;
|
||||||
|
static uint32_t maxSketchSpace ;
|
||||||
//only admin can update FW
|
//only admin can update FW
|
||||||
if(web_interface->is_authenticated() != LEVEL_ADMIN)
|
if(web_interface->is_authenticated() != LEVEL_ADMIN)
|
||||||
{
|
{
|
||||||
@ -2629,16 +2671,25 @@ void WebUpdateUpload()
|
|||||||
Serial.println(F("M117 Update Firmware"));
|
Serial.println(F("M117 Update Firmware"));
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
WiFiUDP::stopAll();
|
WiFiUDP::stopAll();
|
||||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||||
|
last_upload_update = 0;
|
||||||
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
}
|
}
|
||||||
|
else Serial.println(F("M117 Update 0%"));
|
||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
||||||
//check if no error
|
//check if no error
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
|
||||||
{
|
{
|
||||||
|
//we do not know the total file size yet but we know the available space so let's use it
|
||||||
|
if ( ((100 * upload.totalSize) / maxSketchSpace) !=last_upload_update){
|
||||||
|
last_upload_update = (100 * upload.totalSize) / maxSketchSpace;
|
||||||
|
Serial.print(F("M117 Update "));
|
||||||
|
Serial.print(last_upload_update);
|
||||||
|
Serial.println(F("%"));
|
||||||
|
}
|
||||||
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize)
|
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize)
|
||||||
{
|
{
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
@ -2649,7 +2700,7 @@ void WebUpdateUpload()
|
|||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
} else if(upload.status == UPLOAD_FILE_END) {
|
||||||
if(Update.end(true)) { //true to set the size to the current progress
|
if(Update.end(true)) { //true to set the size to the current progress
|
||||||
//Now Reboot
|
//Now Reboot
|
||||||
Serial.println(F("M117 Update Done"));
|
Serial.println(F("M117 Update 100%"));
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||||
}
|
}
|
||||||
} else if(upload.status == UPLOAD_FILE_ABORTED) {
|
} else if(upload.status == UPLOAD_FILE_ABORTED) {
|
||||||
@ -2917,12 +2968,14 @@ void handleSDFileList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
String jsonfile = "{" ;
|
String jsonfile = "{" ;
|
||||||
//if action is processing do not build list
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
|
//if action is processing do not build list, but no need Serial for Direct SDCard Support
|
||||||
if ((web_interface->blockserial)){
|
if ((web_interface->blockserial)){
|
||||||
LOG("Wait, blocking\n");
|
LOG("Wait, blocking\n");
|
||||||
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
jsonfile+="\"files\":[";
|
jsonfile+="\"files\":[";
|
||||||
LOG("No Blocking \n");
|
LOG("No Blocking \n");
|
||||||
@ -3349,8 +3402,10 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
|||||||
status_msg.setsize(4);
|
status_msg.setsize(4);
|
||||||
status_msg.setlength(50);
|
status_msg.setlength(50);
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
fileslist.setlength(100);//12 for filename + space + size
|
fileslist.setlength(100);//12 for filename + space + size
|
||||||
fileslist.setsize(70); // 70 files to limite to 2K
|
fileslist.setsize(70); // 70 files to limite to 2K
|
||||||
|
#endif
|
||||||
fsUploadFile=(FSFILE)0;
|
fsUploadFile=(FSFILE)0;
|
||||||
_head=NULL;
|
_head=NULL;
|
||||||
_nb_ip=0;
|
_nb_ip=0;
|
||||||
@ -3368,7 +3423,9 @@ WEBINTERFACE_CLASS::~WEBINTERFACE_CLASS()
|
|||||||
#ifdef STATUS_MSG_FEATURE
|
#ifdef STATUS_MSG_FEATURE
|
||||||
status_msg.clear();
|
status_msg.clear();
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
fileslist.clear();
|
fileslist.clear();
|
||||||
|
#endif
|
||||||
while (_head) {
|
while (_head) {
|
||||||
auth_ip * current = _head;
|
auth_ip * current = _head;
|
||||||
_head=_head->_next;
|
_head=_head->_next;
|
||||||
|
@ -24,6 +24,11 @@
|
|||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiServer.h>
|
#include <WiFiServer.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#ifdef SDCARD_FEATURE
|
||||||
|
#ifndef FS_NO_GLOBALS
|
||||||
|
#define FS_NO_GLOBALS
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include "storestrings.h"
|
#include "storestrings.h"
|
||||||
|
|
||||||
@ -63,7 +68,9 @@ public:
|
|||||||
#ifdef FLOW_MONITORING_FEATURE
|
#ifdef FLOW_MONITORING_FEATURE
|
||||||
String answer4M221;
|
String answer4M221;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
STORESTRINGS_CLASS fileslist;
|
STORESTRINGS_CLASS fileslist;
|
||||||
|
#endif
|
||||||
#ifdef ERROR_MSG_FEATURE
|
#ifdef ERROR_MSG_FEATURE
|
||||||
STORESTRINGS_CLASS error_msg;
|
STORESTRINGS_CLASS error_msg;
|
||||||
#endif
|
#endif
|
||||||
|
157
esp3d/wifi.cpp
157
esp3d/wifi.cpp
@ -71,54 +71,6 @@ const char * WIFI_CONFIG::get_default_hostname()
|
|||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
//helper to convert string to IP
|
|
||||||
//do not use IPAddress.fromString() because lack of check point and error result
|
|
||||||
//return number of parts
|
|
||||||
byte WIFI_CONFIG::split_ip (const char * ptr,byte * part)
|
|
||||||
{
|
|
||||||
if (strlen(ptr)>15 || strlen(ptr)< 7) {
|
|
||||||
part[0]=0;
|
|
||||||
part[1]=0;
|
|
||||||
part[2]=0;
|
|
||||||
part[3]=0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char pstart [16];
|
|
||||||
char * ptr2;
|
|
||||||
strcpy(pstart,ptr);
|
|
||||||
ptr2 = pstart;
|
|
||||||
byte i = strlen(pstart);
|
|
||||||
byte pos = 0;
|
|
||||||
for (byte j=0; j<i; j++) {
|
|
||||||
if (pstart[j]=='.') {
|
|
||||||
if (pos==4) {
|
|
||||||
part[0]=0;
|
|
||||||
part[1]=0;
|
|
||||||
part[2]=0;
|
|
||||||
part[3]=0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
pstart[j]=0x0;
|
|
||||||
part[pos]=atoi(ptr2);
|
|
||||||
pos++;
|
|
||||||
ptr2 = &pstart[j+1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
part[pos]=atoi(ptr2);
|
|
||||||
return pos+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//just simple helper to convert mac address to string
|
|
||||||
char * WIFI_CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH])
|
|
||||||
{
|
|
||||||
static char macstr [18];
|
|
||||||
if (0>sprintf(macstr,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) {
|
|
||||||
strcpy (macstr, "00:00:00:00:00:00");
|
|
||||||
}
|
|
||||||
return macstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//safe setup if no connection
|
//safe setup if no connection
|
||||||
void WIFI_CONFIG::Safe_Setup()
|
void WIFI_CONFIG::Safe_Setup()
|
||||||
{
|
{
|
||||||
@ -133,8 +85,8 @@ void WIFI_CONFIG::Safe_Setup()
|
|||||||
IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]);
|
IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]);
|
||||||
IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]);
|
IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]);
|
||||||
IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]);
|
IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]);
|
||||||
String ssid = FPSTR(DEFAULT_SSID);
|
String ssid = FPSTR(DEFAULT_AP_SSID);
|
||||||
String pwd = FPSTR(DEFAULT_PASSWORD);
|
String pwd = FPSTR(DEFAULT_AP_PASSWORD);
|
||||||
WiFi.softAP(ssid.c_str(),pwd.c_str());
|
WiFi.softAP(ssid.c_str(),pwd.c_str());
|
||||||
delay(500);
|
delay(500);
|
||||||
WiFi.softAPConfig( local_ip, gateway, subnet);
|
WiFi.softAPConfig( local_ip, gateway, subnet);
|
||||||
@ -143,7 +95,7 @@ void WIFI_CONFIG::Safe_Setup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Read configuration settings and apply them
|
//Read configuration settings and apply them
|
||||||
bool WIFI_CONFIG::Setup()
|
bool WIFI_CONFIG::Setup(bool force_ap)
|
||||||
{
|
{
|
||||||
char pwd[MAX_PASSWORD_LENGTH+1];
|
char pwd[MAX_PASSWORD_LENGTH+1];
|
||||||
char sbuf[MAX_SSID_LENGTH+1];
|
char sbuf[MAX_SSID_LENGTH+1];
|
||||||
@ -155,56 +107,93 @@ bool WIFI_CONFIG::Setup()
|
|||||||
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||||
//set the sleep mode
|
//set the sleep mode
|
||||||
if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
|
||||||
|
LOG("Error read Sleep mode\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WiFi.setSleepMode ((WiFiSleepType_t)bflag);
|
WiFi.setSleepMode ((WiFiSleepType_t)bflag);
|
||||||
sleep_mode=bflag;
|
sleep_mode=bflag;
|
||||||
|
if (force_ap) {
|
||||||
|
bmode = AP_MODE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
//AP or client ?
|
//AP or client ?
|
||||||
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
|
||||||
|
LOG("Error read wifi mode\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!CONFIG::read_string(EP_HOSTNAME, hostname , MAX_HOSTNAME_LENGTH)) {
|
if (!CONFIG::read_string(EP_HOSTNAME, hostname , MAX_HOSTNAME_LENGTH)) {
|
||||||
strcpy(hostname,get_default_hostname());
|
strcpy(hostname,get_default_hostname());
|
||||||
}
|
}
|
||||||
|
//this is AP mode
|
||||||
|
if (bmode==AP_MODE) {
|
||||||
|
LOG("Set AP mode\n")
|
||||||
|
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
||||||
|
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
||||||
|
Serial.print(FPSTR(M117_));
|
||||||
|
Serial.print(F("SSID "));
|
||||||
|
Serial.println(sbuf);
|
||||||
|
LOG("SSID ")
|
||||||
|
LOG(sbuf)
|
||||||
|
LOG("\n")
|
||||||
//DHCP or Static IP ?
|
//DHCP or Static IP ?
|
||||||
if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_AP_IP_MODE, &bflag )) {
|
||||||
|
LOG("Error IP mode\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
LOG("IP Mode: ")
|
||||||
|
LOG(CONFIG::intTostr(bflag))
|
||||||
|
LOG("\n")
|
||||||
if (bflag==STATIC_IP_MODE) {
|
if (bflag==STATIC_IP_MODE) {
|
||||||
byte ip_buf[4];
|
byte ip_buf[4];
|
||||||
|
LOG("Static mode\n")
|
||||||
//get the IP
|
//get the IP
|
||||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
LOG("IP value:")
|
||||||
|
if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
LOG("Error\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
LOG(local_ip.toString())
|
||||||
|
LOG("\nGW value:")
|
||||||
//get the gateway
|
//get the gateway
|
||||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
LOG("Error\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
LOG(gateway.toString())
|
||||||
|
LOG("\nMask value:")
|
||||||
//get the mask
|
//get the mask
|
||||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
LOG("Error Mask value\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
LOG(subnet.toString())
|
||||||
|
LOG("\n")
|
||||||
//apply according active wifi mode
|
//apply according active wifi mode
|
||||||
if (bmode==AP_MODE) {
|
LOG("Set IP\n")
|
||||||
WiFi.softAPConfig( local_ip, gateway, subnet);
|
WiFi.softAPConfig( local_ip, gateway, subnet);
|
||||||
} else {
|
delay(100);
|
||||||
WiFi.config( local_ip, gateway, subnet);
|
|
||||||
}
|
}
|
||||||
}
|
LOG("Disable STA\n")
|
||||||
//this is AP mode
|
WiFi.enableSTA(false);
|
||||||
if (bmode==AP_MODE) {
|
delay(100);
|
||||||
WiFi.enableSTA(true);
|
LOG("Set AP\n")
|
||||||
//setup Soft AP
|
//setup Soft AP
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
|
delay(50);
|
||||||
WiFi.softAP(sbuf, pwd);
|
WiFi.softAP(sbuf, pwd);
|
||||||
|
delay(100);
|
||||||
|
LOG("Set phy mode\n")
|
||||||
//setup PHY_MODE
|
//setup PHY_MODE
|
||||||
if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bflag )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
||||||
|
delay(100);
|
||||||
|
LOG("Get current config\n")
|
||||||
//get current config
|
//get current config
|
||||||
struct softap_config apconfig;
|
struct softap_config apconfig;
|
||||||
wifi_softap_get_config(&apconfig);
|
wifi_softap_get_config(&apconfig);
|
||||||
@ -232,17 +221,51 @@ bool WIFI_CONFIG::Setup()
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
LOG("Set STA mode\n")
|
||||||
|
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
||||||
|
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
||||||
|
Serial.print(FPSTR(M117_));
|
||||||
|
Serial.print(F("SSID "));
|
||||||
|
Serial.println(sbuf);
|
||||||
|
LOG("SSID ")
|
||||||
|
LOG(sbuf)
|
||||||
|
LOG("\n")
|
||||||
|
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (bflag==STATIC_IP_MODE) {
|
||||||
|
byte ip_buf[4];
|
||||||
|
//get the IP
|
||||||
|
if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
//get the gateway
|
||||||
|
if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
//get the mask
|
||||||
|
if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
|
//apply according active wifi mode
|
||||||
|
WiFi.config( local_ip, gateway, subnet);
|
||||||
|
}
|
||||||
WiFi.enableAP(false);
|
WiFi.enableAP(false);
|
||||||
|
delay(100);
|
||||||
//setup station mode
|
//setup station mode
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
delay(100);
|
||||||
WiFi.begin(sbuf, pwd);
|
WiFi.begin(sbuf, pwd);
|
||||||
delay(500);
|
delay(100);
|
||||||
//setup PHY_MODE
|
//setup PHY_MODE
|
||||||
if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_STA_PHY_MODE, &bflag )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
||||||
delay(500);
|
delay(100);
|
||||||
byte i=0;
|
byte i=0;
|
||||||
//try to connect
|
//try to connect
|
||||||
while (WiFi.status() != WL_CONNECTED && i<40) {
|
while (WiFi.status() != WL_CONNECTED && i<40) {
|
||||||
|
@ -42,10 +42,8 @@ public:
|
|||||||
long baud_rate;
|
long baud_rate;
|
||||||
int sleep_mode;
|
int sleep_mode;
|
||||||
int32_t getSignal(int32_t RSSI);
|
int32_t getSignal(int32_t RSSI);
|
||||||
bool Setup();
|
bool Setup(bool force_ap = false);
|
||||||
void Safe_Setup();
|
void Safe_Setup();
|
||||||
char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]);
|
|
||||||
byte split_ip (const char * ptr,byte * part);
|
|
||||||
const char * get_default_hostname();
|
const char * get_default_hostname();
|
||||||
const char * get_hostname();
|
const char * get_hostname();
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user