Skip to content

Commit 65ec16f

Browse files
committed
Add RESET/CONFIG/SAFEMODE to command line
[ESP444]RESET will set default values to EEPROM and restart module [ESP444]CONFIG will display EEPROM but password [ESP444]SAFEMODE will switch to safe mode = default mode but without modifying EEPROM and no restart
1 parent 26ce0ba commit 65ec16f

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

esp8266/command.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "command.h"
2222
#include "config.h"
23+
#include "wifi.h"
2324
#include "webinterface.h"
2425
extern "C" {
2526
#include "user_interface.h"
@@ -49,6 +50,21 @@ void COMMAND::execute_command(int cmd,String cmd_params)
4950
Serial.print("\r\n");
5051
}
5152
break;
53+
case 444:
54+
if (cmd_params=="RESET")
55+
{
56+
CONFIG::reset_config();
57+
web_interface->restartmodule=true;
58+
}
59+
if (cmd_params=="SAFEMODE")
60+
{
61+
wifi_config.Safe_Setup();
62+
}
63+
if (cmd_params=="CONFIG")
64+
{
65+
CONFIG::print_config();
66+
}
67+
break;
5268
case 888:
5369
if (cmd_params=="RESTART")
5470
{

esp8266/config.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ bool CONFIG::reset_config()
159159
if(!CONFIG::write_buffer(EP_XY_FEEDRATE,(const byte *)&DEFAULT_XY_FEEDRATE,INTEGER_LENGTH))return false;
160160
if(!CONFIG::write_buffer(EP_Z_FEEDRATE,(const byte *)&DEFAULT_Z_FEEDRATE,INTEGER_LENGTH))return false;
161161
if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&DEFAULT_E_FEEDRATE,INTEGER_LENGTH))return false;
162-
163162
return true;
164163
}
165164

@@ -171,7 +170,7 @@ void CONFIG::print_config()
171170
int ibuf=0;
172171
if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf ))Serial.println(byte(bbuf));
173172
if (CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH))Serial.println(sbuf);
174-
if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGTH))Serial.println(sbuf);
173+
//if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGTH))Serial.println(sbuf);
175174
if (CONFIG::read_byte(EP_IP_MODE, &bbuf ))Serial.println(byte(bbuf));
176175
if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGTH))Serial.println(wifi_config.ip2str((byte *)sbuf));
177176
if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)sbuf , IP_LENGTH))Serial.println(wifi_config.ip2str((byte *)sbuf));
@@ -189,5 +188,4 @@ void CONFIG::print_config()
189188
if (CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println(ibuf);
190189
if (CONFIG::read_buffer(EP_Z_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println(ibuf);
191190
if (CONFIG::read_buffer(EP_E_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println(ibuf);
192-
193191
}

esp8266/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define SSDP_FEATURE
2828

2929
//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
30-
//#define CAPTIVE_PORTAL_FEATURE
30+
#define CAPTIVE_PORTAL_FEATURE
3131

3232
#ifndef CONFIG_h
3333
#define CONFIG_h

esp8266/esp8266.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
5757

5858
void setup() {
5959
// init :
60+
web_interface = NULL;
61+
data_server = NULL;
6062
// ESP.wdtDisable();
6163
system_update_cpu_freq(SYS_CPU_160MHZ);
6264
delay(8000);

esp8266/wifi.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
extern "C" {
2929
#include "user_interface.h"
3030
}
31+
#ifdef CAPTIVE_PORTAL_FEATURE
32+
#include <DNSServer.h>
33+
extern DNSServer dnsServer;
34+
#endif
3135

3236
const char * WIFI_CONFIG::get_hostname(){
3337
if (WiFi.hostname().length()==0)
@@ -105,20 +109,23 @@ char * WIFI_CONFIG::ip2str(IPAddress Ip )
105109

106110
void WIFI_CONFIG::Safe_Setup()
107111
{
108-
WiFi.disconnect();
109-
//setup Soft AP
110-
WiFi.mode(WIFI_AP);
111-
IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]);
112-
IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]);
113-
IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]);
114-
String ssid = FPSTR(DEFAULT_SSID);
115-
String pwd = FPSTR(DEFAULT_PASSWORD);
116-
WiFi.softAP(ssid.c_str(),pwd.c_str());
117-
delay(500);
118-
wifi_set_phy_mode(PHY_MODE_11B);
119-
WiFi.softAPConfig( local_ip, gateway, subnet);
120-
Serial.println(F("M117 Safe mode started"));
121-
delay(1000);
112+
#ifdef CAPTIVE_PORTAL_FEATURE
113+
dnsServer.stop();
114+
delay(100);
115+
#endif
116+
WiFi.disconnect();
117+
//setup Soft AP
118+
WiFi.mode(WIFI_AP);
119+
IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]);
120+
IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]);
121+
IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]);
122+
String ssid = FPSTR(DEFAULT_SSID);
123+
String pwd = FPSTR(DEFAULT_PASSWORD);
124+
WiFi.softAP(ssid.c_str(),pwd.c_str());
125+
delay(500);
126+
WiFi.softAPConfig( local_ip, gateway, subnet);
127+
delay(1000);
128+
Serial.println(F("M117 Safe mode started"));
122129
}
123130

124131
//Read configuration settings and apply them

0 commit comments

Comments
 (0)