mirror of
https://github.com/FYSETC/ESPWebDAV.git
synced 2026-03-19 07:06:57 +01:00
Generate ip.gcode after wifi connected
This commit is contained in:
39
config.cpp
39
config.cpp
@@ -99,6 +99,10 @@ unsigned char Config::load() {
|
||||
}
|
||||
EEPROM.commit();
|
||||
|
||||
if(data.flag) {
|
||||
SERIAL_ECHOLN("Going to use the old config to connect the network");
|
||||
}
|
||||
SERIAL_ECHOLN("We didn't connect the network before");
|
||||
return data.flag;
|
||||
}
|
||||
|
||||
@@ -150,4 +154,39 @@ void Config::save() {
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
// Save to ip address to sdcard
|
||||
int Config::save_ip(const char *ip) {
|
||||
SdFat sdfat;
|
||||
|
||||
SERIAL_ECHOLN("Going to save config to ip.gcode file");
|
||||
|
||||
if(!sdcontrol.canWeTakeBus()) {
|
||||
SERIAL_ECHOLN("Marlin is controling the bus");
|
||||
return -1;
|
||||
}
|
||||
sdcontrol.takeBusControl();
|
||||
|
||||
if(!sdfat.begin(SD_CS, SPI_FULL_SPEED)) {
|
||||
SERIAL_ECHOLN("Initial SD failed");
|
||||
sdcontrol.relinquishBusControl();
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Remove the old file
|
||||
sdfat.remove("ip.gcode");
|
||||
|
||||
File file = sdfat.open("ip.gcode", FILE_WRITE);
|
||||
if (!file) {
|
||||
SERIAL_ECHOLN("Open ip file failed");
|
||||
sdcontrol.relinquishBusControl();
|
||||
return -3;
|
||||
}
|
||||
|
||||
// Get SSID and PASSWORD from file
|
||||
char buf[21] = "M117 ";
|
||||
strncat(buf,ip,15);
|
||||
file.write(buf, 21);
|
||||
file.close();
|
||||
}
|
||||
|
||||
Config config;
|
||||
|
||||
3
config.h
3
config.h
@@ -26,7 +26,8 @@ public:
|
||||
void password(char* password);
|
||||
void save(const char*ssid,const char*password);
|
||||
void save();
|
||||
|
||||
int save_ip(const char *ip);
|
||||
|
||||
protected:
|
||||
CONFIG_TYPE data;
|
||||
};
|
||||
|
||||
10
network.cpp
10
network.cpp
@@ -6,6 +6,14 @@
|
||||
#include "ESPWebDAV.h"
|
||||
#include "sdControl.h"
|
||||
|
||||
String IpAddress2String(const IPAddress& ipAddress)
|
||||
{
|
||||
return String(ipAddress[0]) + String(".") +\
|
||||
String(ipAddress[1]) + String(".") +\
|
||||
String(ipAddress[2]) + String(".") +\
|
||||
String(ipAddress[3]) ;
|
||||
}
|
||||
|
||||
bool Network::start() {
|
||||
wifiConnected = false;
|
||||
|
||||
@@ -41,6 +49,8 @@ bool Network::start() {
|
||||
wifiConnected = true;
|
||||
|
||||
config.save();
|
||||
String sIp = IpAddress2String(WiFi.localIP());
|
||||
config.save_ip(sIp.c_str());
|
||||
|
||||
SERIAL_ECHOLN("Going to start DAV server");
|
||||
if(startDAVServer() < 0) return false;
|
||||
|
||||
Reference in New Issue
Block a user