Update EEPROM content for new settings

Modify EEPROM content to reflect the possible settings
Add a buffer format function to query/write EEPROM instead of always
using string function to save space.
Update Reset/Print Configuration with new settings
Code Cleaning
Some settings stay default as no real add value currently to allow to
change them
This commit is contained in:
luc 2015-05-13 21:58:26 +08:00
parent e73b2e372d
commit 364e37f5ba
6 changed files with 161 additions and 97 deletions

View File

@ -20,8 +20,8 @@
#include "config.h" #include "config.h"
#include <EEPROM.h> #include <EEPROM.h>
//read a string or a unique byte/flag //read a string
//a flag is 1 byte, 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(word pos, char byte_buffer[], word size_max) bool CONFIG::read_string(word pos, char byte_buffer[], word size_max)
{ {
//check if parameters are acceptable //check if parameters are acceptable
@ -43,6 +43,22 @@ bool CONFIG::read_string(word pos, char byte_buffer[], word size_max)
if (b!=0)byte_buffer[i-1]=0x00; if (b!=0)byte_buffer[i-1]=0x00;
return true; return true;
} }
//read a buffer of size_buffer
bool CONFIG::read_buffer(word pos, byte byte_buffer[], word size_buffer)
{
//check if parameters are acceptable
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL)return false;
word i=0;
//read until max size is reached
while (i<size_buffer )
{
byte_buffer[i]=EEPROM.read(pos+i);
i++;
}
return true;
}
//read a flag / byte //read a flag / byte
bool CONFIG::read_byte(word pos, byte * value) bool CONFIG::read_byte(word pos, byte * value)
{ {
@ -68,6 +84,19 @@ bool CONFIG::write_string(word pos, const char * byte_buffer, word size_buffer)
return true; return true;
} }
//write a buffer
bool CONFIG::write_buffer(word pos, const byte * byte_buffer, word size_buffer)
{
//check if parameters are acceptable
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL)return false;
//copy the value(s)
for (word i = 0; i < size_buffer; i++) {
EEPROM.write(pos + i, byte_buffer[i]);
}
EEPROM.commit();
return true;
}
//read a flag / byte //read a flag / byte
bool CONFIG::write_byte(word pos, const byte value) bool CONFIG::write_byte(word pos, const byte value)
{ {
@ -84,23 +113,35 @@ bool CONFIG::reset_config()
if(!CONFIG::write_string(EP_SSID,DEFAULT_SSID,strlen(DEFAULT_SSID)))return false; if(!CONFIG::write_string(EP_SSID,DEFAULT_SSID,strlen(DEFAULT_SSID)))return false;
if(!CONFIG::write_string(EP_PASSWORD,DEFAULT_PASSWORD,strlen(DEFAULT_PASSWORD)))return false; if(!CONFIG::write_string(EP_PASSWORD,DEFAULT_PASSWORD,strlen(DEFAULT_PASSWORD)))return false;
if(!CONFIG::write_byte(EP_IP_MODE,DEFAULT_IP_MODE))return false; if(!CONFIG::write_byte(EP_IP_MODE,DEFAULT_IP_MODE))return false;
if(!CONFIG::write_string(EP_IP_VALUE,DEFAULT_IP_VALUE,strlen(DEFAULT_IP_VALUE)))return false; if(!CONFIG::write_buffer(EP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGH))return false;
if(!CONFIG::write_string(EP_MASK_VALUE,DEFAULT_MASK_VALUE,strlen(DEFAULT_MASK_VALUE)))return false; if(!CONFIG::write_buffer(EP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGH))return false;
if(!CONFIG::write_string(EP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,strlen(DEFAULT_GATEWAY_VALUE)))return false; if(!CONFIG::write_buffer(EP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGH))return false;
if(!CONFIG::write_string(EP_BAUD_RATE,DEFAULT_BAUD_RATE,strlen(DEFAULT_BAUD_RATE)))return false; if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,BAUD_LENGH))return false;
if(!CONFIG::write_byte(EP_PHY_MODE,DEFAULT_PHY_MODE))return false;
if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE))return false;
if(!CONFIG::write_byte(EP_CHANNEL,DEFAULT_CHANNEL))return false;
if(!CONFIG::write_byte(EP_AUTH_TYPE,DEFAULT_AUTH_TYPE))return false;
if(!CONFIG::write_byte(EP_SSID_VISIBLE,DEFAULT_SSID_VISIBLE))return false;
return true; return true;
} }
void CONFIG::print_config() void CONFIG::print_config()
{ {
char sbuf[70]; //use bigest size for buffer
char sbuf[MAX_PASSWORD_LENGH+1];
byte bbuf=0; byte bbuf=0;
int ibuf=0;
if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH))Serial.println(sbuf); if (CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH))Serial.println(sbuf);
if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGH))Serial.println(sbuf); if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGH))Serial.println(sbuf);
if (CONFIG::read_byte(EP_IP_MODE, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_IP_MODE, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_string(EP_IP_VALUE, sbuf , MAX_IP_LENGH))Serial.println(sbuf); if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf));
if (CONFIG::read_string(EP_MASK_VALUE, sbuf , MAX_IP_LENGH))Serial.println(sbuf); if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf));
if (CONFIG::read_string(EP_GATEWAY_VALUE, sbuf , MAX_IP_LENGH))Serial.println(sbuf); if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf));
if (CONFIG::read_string(EP_BAUD_RATE, sbuf , MAX_BAUD_LENGH))Serial.println(sbuf); if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , BAUD_LENGH))Serial.println(ibuf);
if (CONFIG::read_byte(EP_PHY_MODE, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_byte(EP_CHANNEL, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_byte(EP_AUTH_TYPE, &bbuf ))Serial.println(byte(bbuf));
if (CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf ))Serial.println(byte(bbuf));
} }

View File

@ -18,61 +18,83 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
//comment to disable
#define MDNS_FEATURE
#ifndef CONFIG_h #ifndef CONFIG_h
#define CONFIG_h #define CONFIG_h
#include <Arduino.h> #include <Arduino.h>
#include "wifi.h"
extern "C" {
#include "user_interface.h"
}
//version and sources location //version and sources location
#define FW_VERSION "V0.1" #define FW_VERSION "V0.1"
#define REPOSITORY "https://github.com/luc-github/ESP8266" #define REPOSITORY "https://github.com/luc-github/ESP8266"
#define MDNS_FEATURE 1
//pin used to reset setting //pin used to reset setting
#define RESET_CONFIG_PIN 2 #define RESET_CONFIG_PIN 2
//flags //flags
#define AP_MODE 1 #define AP_MODE 1
#define CLIENT_MODE 2 #define CLIENT_MODE 2
#define DHCP_MODE 1 #define DHCP_MODE 1
#define STATIC_IP_MODE 2 #define STATIC_IP_MODE 2
//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_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_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_IP_MODE 99 //1 byte = flag
#define EP_IP_VALUE 100 //16 bytes xxx.xxx.xxx\0 = string #define EP_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx
#define EP_MASK_VALUE 116 //16 bytes xxx.xxx.xxx\0 = string #define EP_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
#define EP_GATEWAY_VALUE 132 //16 bytes xxx.xxx.xxx\0 = string #define EP_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
#define EP_BAUD_RATE 151 //7 bytes = string (if integer value => save 4 bytes but need to create new integer function for eeprom that will take more than 4 bytes) #define EP_BAUD_RATE 112 //4 bytes = int
#define EP_PHY_MODE 116 //1 byte = flag
#define EP_SLEEP_MODE 117 //1 byte = flag
#define EP_CHANNEL 118 //1 byte = flag
#define EP_AUTH_TYPE 119 //1 byte = flag
#define EP_SSID_VISIBLE 120 //1 byte = flag
//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_SSID [] PROGMEM = "ESP8266";
const char DEFAULT_PASSWORD [] PROGMEM = "12345678"; const char DEFAULT_PASSWORD [] PROGMEM = "12345678";
#define DEFAULT_IP_MODE STATIC_IP_MODE #define DEFAULT_IP_MODE STATIC_IP_MODE
const char DEFAULT_IP_VALUE[] PROGMEM = "192.168.0.1"; const byte DEFAULT_IP_VALUE[] PROGMEM = {192,168,0,1};
const char DEFAULT_MASK_VALUE[] PROGMEM = "255.255.255.0"; const byte DEFAULT_MASK_VALUE[] PROGMEM = {255,255,255,0};
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE #define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
const char DEFAULT_BAUD_RATE[] PROGMEM = "9600"; const int DEFAULT_BAUD_RATE = 9600;
#if MDNS_FEATURE #ifdef MDNS_FEATURE
const char LOCAL_NAME[] PROGMEM = "esp8266"; const char LOCAL_NAME[] PROGMEM = "esp8266";
#endif #endif
#define DEFAULT_PHY_MODE PHY_MODE_11G
#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T
#define DEFAULT_CHANNEL 11
#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK
#define DEFAULT_SSID_VISIBLE 1
#define DEFAULT_MAX_CONNECTIONS 4
#define DEFAULT_BEACON_INTERVAL 100
#define EEPROM_SIZE 256 //max is 512 //sizes
#define MAX_SSID_LENGH 32 #define EEPROM_SIZE 256 //max is 512
#define MAX_PASSWORD_LENGH 64 #define MAX_SSID_LENGH 32
#define MAX_IP_LENGH 17 #define MAX_PASSWORD_LENGH 64
#define MAX_BAUD_LENGH 6 #define IP_LENGH 4
#define BAUD_LENGH 4
class CONFIG class CONFIG
{ {
public: public:
static bool read_string(word pos, char byte_buffer[], word size_max); static bool read_string(word pos, char byte_buffer[], word size_max);
static bool read_buffer(word pos, byte byte_buffer[], word size_buffer);
static bool read_byte(word pos, byte * value); static bool read_byte(word pos, byte * value);
static bool write_string(word pos, const char * byte_buffer, word size_buffer); static bool write_string(word pos, const char * byte_buffer, word size_buffer);
static bool write_buffer(word pos, const byte * byte_buffer, word size_buffer);
static bool write_byte(word pos, const byte value); static bool write_byte(word pos, const byte value);
static bool reset_config(); static bool reset_config();
static void print_config(); static void print_config();

View File

@ -37,7 +37,7 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#if MDNS_FEATURE #ifdef MDNS_FEATURE
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#endif #endif
extern "C" { extern "C" {
@ -53,24 +53,21 @@ void setup() {
pinMode(RESET_CONFIG_PIN, INPUT); pinMode(RESET_CONFIG_PIN, INPUT);
if (digitalRead(RESET_CONFIG_PIN)==0)breset_config=true;//if requested =>reset settings if (digitalRead(RESET_CONFIG_PIN)==0)breset_config=true;//if requested =>reset settings
//default baud rate //default baud rate
word baud_rate; int baud_rate=0;
char sbuf[7];
//check if EEPROM has value //check if EEPROM has value
if ( CONFIG::read_string(EP_BAUD_RATE, sbuf , MAX_BAUD_LENGH)) if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , BAUD_LENGH))
{ {
word baud_tmp = atoi(sbuf);
//check if baud value is one of allowed ones //check if baud value is one of allowed ones
if (baud_tmp==9600 || baud_tmp==19200 ||baud_tmp==38400 ||baud_tmp==57600 ||baud_tmp==115200 ||baud_tmp==230400) baud_rate=baud_tmp; if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400) )breset_config=true;//baud rate is incorrect =>reset settings
else breset_config=true;//baud rate is incorrect =>reset settings
} }
else breset_config=true;//cannot access to config settings=> reset settings else breset_config=true;//cannot access to config settings=> reset settings
//reset is requested //reset is requested
if(breset_config) if(breset_config)
{ {
//update EEPROM with default settings //update EEPROM with default settings
CONFIG::reset_config(); CONFIG::reset_config();
//use default baud rate //use default baud rate
baud_rate=atol(DEFAULT_BAUD_RATE); baud_rate=DEFAULT_BAUD_RATE;
} }
//setup serial //setup serial
Serial.begin(baud_rate); Serial.begin(baud_rate);
@ -85,14 +82,12 @@ void setup() {
//main loop //main loop
void loop() { void loop() {
#if MDNS_FEATURE #ifdef MDNS_FEATURE
// Check for any mDNS queries and send responses // Check for any mDNS queries and send responses
wifi_config.mdns.update(); wifi_config.mdns.update();
#endif #endif
//web requests //web requests
web_interface.WebServer.handleClient(); web_interface.WebServer.handleClient();
//TODO use a method to handle serial also in class and call it instead of this one //TODO use a method to handle serial also in class and call it instead of this one
data_interface.WebServer.handleClient(); data_interface.WebServer.handleClient();
} }

View File

@ -92,7 +92,7 @@ void handle_web_interface_root()
LABEL_UNITS(sbuf,F("CPU Frequency: "),system_get_cpu_freq(),F("Hz")) LABEL_UNITS(sbuf,F("CPU Frequency: "),system_get_cpu_freq(),F("Hz"))
LABEL_UNITS(sbuf,F("Free Memory: "),String(system_get_free_heap_size()),F(" octets")) LABEL_UNITS(sbuf,F("Free Memory: "),String(system_get_free_heap_size()),F(" octets"))
LABEL(sbuf,F("SDK Version: "),system_get_sdk_version()) LABEL(sbuf,F("SDK Version: "),system_get_sdk_version())
#if MDNS_FEATURE #ifdef MDNS_FEATURE
sstatus = F("http://"); sstatus = F("http://");
sstatus+=LOCAL_NAME; sstatus+=LOCAL_NAME;
LABEL_UNITS(sbuf,F("mDNS name: "),sstatus,F(".local")) LABEL_UNITS(sbuf,F("mDNS name: "),sstatus,F(".local"))

View File

@ -22,7 +22,7 @@
#include "config.h" #include "config.h"
#include "ESP8266WiFi.h" #include "ESP8266WiFi.h"
#include "IPAddress.h" #include "IPAddress.h"
#if MDNS_FEATURE #ifdef MDNS_FEATURE
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#endif #endif
extern "C" { extern "C" {
@ -71,42 +71,54 @@ char * WIFI_CONFIG::ip2str(IPAddress Ip )
//Read configuration settings and apply them //Read configuration settings and apply them
bool WIFI_CONFIG::Setup() bool WIFI_CONFIG::Setup()
{ {
byte bbuf; char pwd[MAX_PASSWORD_LENGH+1];
char pwd[65]; char sbuf[MAX_SSID_LENGH+1];
char sbuf[35];
int wstatus; int wstatus;
byte ip[4]={0,0,0,0}; IPAddress currentIP;
IPAddress currentIP; byte bflag=0;
//AP or client ? //AP or client ?
if (!CONFIG::read_byte(EP_WIFI_MODE, &bbuf ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGH)) return false; if (!CONFIG::read_byte(EP_WIFI_MODE, &bflag ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGH)) return false;
//disconnect if connected //disconnect if connected
WiFi.disconnect(); WiFi.disconnect();
bbuf=AP_MODE;
//this is AP mode //this is AP mode
if (bbuf==AP_MODE) if (bflag==AP_MODE)
{ {
//setup Soft AP
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.softAP(sbuf, pwd); WiFi.softAP(sbuf, pwd);
//setup PHY_MODE
struct softap_config apconfig; if (!CONFIG::read_byte(EP_PHY_MODE, &bflag ))return false;
wifi_set_phy_mode((phy_mode)bflag);
//get current config
struct softap_config apconfig;
wifi_softap_get_config(&apconfig); wifi_softap_get_config(&apconfig);
apconfig.channel=11; //set the chanel
//apconfig.authmode=AUTH_OPEN; if (!CONFIG::read_byte(EP_CHANNEL, &bflag ))return false;
apconfig.ssid_hidden=0; apconfig.channel=bflag;
apconfig.max_connection=4; //set Authentification type
apconfig.beacon_interval=100; if (!CONFIG::read_byte(EP_AUTH_TYPE, &bflag ))return false;
wifi_set_phy_mode(PHY_MODE_11G); apconfig.authmode=(AUTH_MODE)bflag;
//set the visibility of SSID
if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bflag ))return false;
apconfig.ssid_hidden=!bflag;
//no need to add these settings to configuration just use default ones
apconfig.max_connection=DEFAULT_MAX_CONNECTIONS;
apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL;
//apply settings to current and to default
if (!wifi_softap_set_config(&apconfig))Serial.println(F("Error Wifi AP")); if (!wifi_softap_set_config(&apconfig))Serial.println(F("Error Wifi AP"));
if (!wifi_softap_set_config_current(&apconfig))Serial.println(F("Error Wifi AP")); if (!wifi_softap_set_config_current(&apconfig))Serial.println(F("Error Wifi AP"));
wifi_softap_dhcps_start(); wifi_softap_dhcps_start();
wifi_set_phy_mode(PHY_MODE_11G);
} }
else else
{ {//setup station mode
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(sbuf, pwd); WiFi.begin(sbuf, pwd);
//setup PHY_MODE
if (!CONFIG::read_byte(EP_PHY_MODE, &bflag ))return false;
wifi_set_phy_mode((phy_mode)bflag);
byte i=0; byte i=0;
//try to connect
while (WiFi.status() != WL_CONNECTED && i<40) { while (WiFi.status() != WL_CONNECTED && i<40) {
delay(500); delay(500);
Serial.println(WiFi.status()); Serial.println(WiFi.status());
@ -114,43 +126,36 @@ bool WIFI_CONFIG::Setup()
} }
} }
//DHCP or Static IP ? //DHCP or Static IP ?
if (!CONFIG::read_byte(EP_IP_MODE, &bbuf )) return false; if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) return false;
if (bbuf==STATIC_IP_MODE) if (bflag==STATIC_IP_MODE)
{ {
//get the IP //get the IP
if (!CONFIG::read_string(EP_IP_VALUE, sbuf , MAX_IP_LENGH))return false; if (!CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGH))return false;
//split in 4 parts IPAddress local_ip (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
split_ip (sbuf,ip);
IPAddress local_ip (ip[0],ip[1],ip[2],ip[3]);
//get the gateway //get the gateway
if (!CONFIG::read_string(EP_GATEWAY_VALUE, sbuf , MAX_IP_LENGH))return false; if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,(byte *)sbuf , IP_LENGH))return false;
//split in 4 parts IPAddress gateway (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
split_ip (sbuf,ip);
IPAddress gateway (ip[0],ip[1],ip[2],ip[3]);
//get the mask //get the mask
if (!CONFIG::read_string(EP_MASK_VALUE, sbuf , MAX_IP_LENGH))return false; if (!CONFIG::read_buffer(EP_MASK_VALUE,(byte *)sbuf , IP_LENGH))return false;
//split in 4 parts IPAddress subnet (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
split_ip (sbuf,ip);
IPAddress subnet (ip[0],ip[1],ip[2],ip[3]);
//apply according active wifi mode //apply according active wifi mode
if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) WiFi.softAPConfig( local_ip, gateway, subnet); if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) WiFi.softAPConfig( local_ip, gateway, subnet);
else WiFi.config( local_ip, gateway, subnet); else WiFi.config( local_ip, gateway, subnet);
} }
#if MDNS_FEATURE #ifdef MDNS_FEATURE
//Get IP //Get IP
if (wifi_get_opmode()==WIFI_STA)currentIP=WiFi.localIP(); if (wifi_get_opmode()==WIFI_STA)currentIP=WiFi.localIP();
else currentIP=WiFi.softAPIP(); else currentIP=WiFi.softAPIP();
// Set up mDNS responder: // Set up mDNS responder:
// - first argument is the domain name, in this example // - first argument is the domain name, in this example
// the fully-qualified domain name is "esp8266.local" // the fully-qualified domain name is "esp8266.local"
// - second argument is the IP address to advertise // - second argument is the IP address to advertise
// we send our IP address on the WiFi network // we send our IP address on the WiFi network
// Note: for AP mode we would use WiFi.softAPIP()! // Note: for AP mode we would use WiFi.softAPIP()!
if (!mdns.begin(LOCAL_NAME, currentIP)) { if (!mdns.begin(LOCAL_NAME, currentIP)) {
Serial.println(F("Error setting up MDNS responder!")); Serial.println(F("Error setting up MDNS responder!"));
} }
#endif #endif
CONFIG::print_config();
return true; return true;
} }

View File

@ -24,7 +24,8 @@
#include "config.h" #include "config.h"
#include "IPAddress.h" #include "IPAddress.h"
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#if MDNS_FEATURE
#ifdef MDNS_FEATURE
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#endif #endif
@ -32,8 +33,8 @@ class WIFI_CONFIG
{ {
public: public:
// multicast DNS responder feature // multicast DNS responder feature
#if MDNS_FEATURE #ifdef MDNS_FEATURE
MDNSResponder mdns; MDNSResponder mdns;
#endif #endif
bool Setup(); bool Setup();
char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]); char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]);