Oprava demo prikladu. Funkcni i ve verzi core 2.4.2
This commit is contained in:
parent
3172bb0d17
commit
f45d742435
@ -4,6 +4,7 @@
|
|||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <ESP8266NetBIOS.h>
|
#include <ESP8266NetBIOS.h>
|
||||||
#include <WiFiConfig.h>
|
#include <WiFiConfig.h>
|
||||||
|
#include <encipheredEEPROMStrings.h>
|
||||||
|
|
||||||
// Plati pro desticku Witty s modulem ESP-12E
|
// Plati pro desticku Witty s modulem ESP-12E
|
||||||
#define PIN_FORCE_CONFIG 4
|
#define PIN_FORCE_CONFIG 4
|
||||||
@ -14,6 +15,19 @@
|
|||||||
//#define DEBUG_OUT(a) {}
|
//#define DEBUG_OUT(a) {}
|
||||||
#define DEBUG_OUT(a) Serial.print(a)
|
#define DEBUG_OUT(a) Serial.print(a)
|
||||||
|
|
||||||
|
// Definice obsazeni EEPROM
|
||||||
|
#define elementSize(type, element) sizeof(((type *)0)->element)
|
||||||
|
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char devname[32 + 2]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
||||||
|
} eepromconfig_t;
|
||||||
|
|
||||||
|
#define EEPROM_SIZE (sizeof(wificonfigarea_t) + sizeof(eepromconfig_t) + 10) // velikost EEPROM oblasti (POZOR!!! zbytecnym zvetsovanim se zaroven zmensuje velikost RAM kvuli zrcadlu!!!)
|
||||||
|
#define EEPROM_WIFICONFIG_ORIGIN (EEPROM_SIZE - sizeof(wificonfigarea_t)) // pocatek oblasti, pouzivane WiFiConfig (alokovano odzadu)
|
||||||
|
#define EEPROM_CONFIG_ORIGIN (0)
|
||||||
|
|
||||||
|
char WiFiDeviceName[elementSize(eepromconfig_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
||||||
ESP8266WebServer wwwserver(80); // webovy server
|
ESP8266WebServer wwwserver(80); // webovy server
|
||||||
String content;
|
String content;
|
||||||
|
|
||||||
@ -52,23 +66,27 @@ void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveServer(const char *param)
|
void ICACHE_FLASH_ATTR saveDevname(const char *param)
|
||||||
{
|
{
|
||||||
|
String p = param;
|
||||||
|
|
||||||
DEBUG_OUT(param);
|
EES_storeString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR setup()
|
void ICACHE_FLASH_ATTR setup()
|
||||||
{
|
{
|
||||||
WiFiConfig wifi; // konfigurace ESP modulu
|
WiFiConfig wifi; // konfigurace ESP modulu
|
||||||
WiFiConfigUsrParameter testOnly("server", "adresa serveru", "Default server", 32, saveServer);
|
WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname);
|
||||||
|
|
||||||
EEPROM.begin(512); // zahajujeme praci s EEPROM
|
EEPROM.begin(EEPROM_SIZE); // zahajujeme praci s EEPROM
|
||||||
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
||||||
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
wifi.addParameter(&testOnly);
|
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
||||||
if (WCR_OK != wifi.begin(0, fc, wcb)) // startujeme pripojeni
|
strcpy(WiFiDeviceName, dn.c_str());
|
||||||
|
wifi.addParameter(&devname);
|
||||||
|
|
||||||
|
if (WCR_OK != wifi.begin(EEPROM_WIFICONFIG_ORIGIN, fc, wcb)) // startujeme pripojeni
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|
||||||
wwwserver.on("/", handleRoot);
|
wwwserver.on("/", handleRoot);
|
||||||
|
Loading…
Reference in New Issue
Block a user