mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-23 13:56:10 +02:00
* fixed erase settings
* fixed behavior if no MQTT IP is set (the system was nearly unusable because of delayed responses) * fixed Station / AP WiFi on startup -> more information will be printed to the serial console * added new ticker for serial value dump
This commit is contained in:
parent
539d4f73c1
commit
4c3852cde4
9 changed files with 81 additions and 39 deletions
|
@ -7,10 +7,13 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
app::app() : Main() {
|
app::app() : Main() {
|
||||||
mSendTicker = 0xffffffff;
|
mSendTicker = 0xffffffff;
|
||||||
mSendInterval = 0;
|
mSendInterval = 0;
|
||||||
mMqttTicker = 0xffffffff;
|
mMqttTicker = 0xffffffff;
|
||||||
mMqttInterval = 0;
|
mMqttInterval = 0;
|
||||||
|
mSerialTicker = 0xffffffff;
|
||||||
|
mSerialInterval = 0;
|
||||||
|
mMqttActive = false;
|
||||||
|
|
||||||
mShowRebootRequest = false;
|
mShowRebootRequest = false;
|
||||||
|
|
||||||
|
@ -86,12 +89,17 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
|
||||||
|
|
||||||
char addr[16] = {0};
|
char addr[16] = {0};
|
||||||
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
|
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
|
||||||
|
mMqttActive = (mqttAddr[0] > 0);
|
||||||
|
|
||||||
|
|
||||||
if(mMqttInterval < 1000)
|
if(mMqttInterval < 1000)
|
||||||
mMqttInterval = 1000;
|
mMqttInterval = 1000;
|
||||||
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
|
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
|
|
||||||
|
mSerialTicker = 0;
|
||||||
|
mSerialInterval = mMqttInterval; // TODO: add extra setting for this!
|
||||||
|
|
||||||
mMqtt.sendMsg("version", mVersion);
|
mMqtt.sendMsg("version", mVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,25 +174,31 @@ void app::loop(void) {
|
||||||
|
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
mMqtt.loop();
|
if(mMqttActive) {
|
||||||
if(checkTicker(&mMqttTicker, mMqttInterval)) {
|
mMqtt.loop();
|
||||||
mMqtt.isConnected(true);
|
if(checkTicker(&mMqttTicker, mMqttInterval)) {
|
||||||
char topic[30], val[10];
|
mMqtt.isConnected(true);
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
char topic[30], val[10];
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
if(NULL != iv) {
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
for(uint8_t i = 0; i < iv->listLen; i++) {
|
if(NULL != iv) {
|
||||||
if(0.0f != iv->getValue(i)) {
|
for(uint8_t i = 0; i < iv->listLen; i++) {
|
||||||
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
|
if(0.0f != iv->getValue(i)) {
|
||||||
snprintf(val, 10, "%.3f", iv->getValue(i));
|
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
|
||||||
mMqtt.sendMsg(topic, val);
|
snprintf(val, 10, "%.3f", iv->getValue(i));
|
||||||
yield();
|
mMqtt.sendMsg(topic, val);
|
||||||
|
yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Serial debug
|
|
||||||
|
// Serial debug
|
||||||
|
if(checkTicker(&mSerialTicker, mSerialInterval)) {
|
||||||
|
char topic[30], val[10];
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
|
@ -230,6 +244,10 @@ void app::showSetup(void) {
|
||||||
|
|
||||||
html.replace("{DEVICE}", String(mDeviceName));
|
html.replace("{DEVICE}", String(mDeviceName));
|
||||||
html.replace("{VERSION}", String(mVersion));
|
html.replace("{VERSION}", String(mVersion));
|
||||||
|
if(mApActive)
|
||||||
|
html.replace("{IP}", String("http://192.168.1.1"));
|
||||||
|
else
|
||||||
|
html.replace("{IP}", ("http://" + String(WiFi.localIP().toString())));
|
||||||
|
|
||||||
String inv;
|
String inv;
|
||||||
uint64_t invSerial;
|
uint64_t invSerial;
|
||||||
|
|
|
@ -81,6 +81,9 @@ class app : public Main {
|
||||||
mqtt mMqtt;
|
mqtt mMqtt;
|
||||||
uint32_t mMqttTicker;
|
uint32_t mMqttTicker;
|
||||||
uint16_t mMqttInterval;
|
uint16_t mMqttInterval;
|
||||||
|
bool mMqttActive;
|
||||||
|
uint32_t mSerialTicker;
|
||||||
|
uint16_t mSerialInterval;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__APP_H__*/
|
#endif /*__APP_H__*/
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 3
|
||||||
#define VERSION_PATCH 4
|
#define VERSION_PATCH 5
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __INDEX_H__
|
#ifndef __INDEX_H__
|
||||||
#define __INDEX_H__
|
#define __INDEX_H__
|
||||||
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">window.setInterval(\"getAjax('/uptime', 'uptime')\", 1000);window.setInterval(\"getAjax('/time', 'time')\", 1000);window.setInterval(\"getAjax('/cmdstat', 'cmds')\", 2000);function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/hoymiles\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this (Mikrocontroller.net)</a>discussion.<br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by Github. </div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p></div></body></html>";
|
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">window.setInterval(\"getAjax('/uptime', 'uptime')\", 1000);window.setInterval(\"getAjax('/time', 'time')\", 1000);window.setInterval(\"getAjax('/cmdstat', 'cmds')\", 2000);function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/hoymiles\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this discussion. (Mikrocontroller.net)</a><br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by Github. </div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p></div></body></html>";
|
||||||
#endif /*__INDEX_H__*/
|
#endif /*__INDEX_H__*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __SETUP_H__
|
#ifndef __SETUP_H__
|
||||||
#define __SETUP_H__
|
#define __SETUP_H__
|
||||||
const char setup_html[] PROGMEM = "<!doctype html><html><head><title>Setup - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body><h1>Setup</h1><div id=\"setup\" class=\"content\"><div id=\"content\"><p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information. </p><form method=\"post\" action=\"/save\"><p class=\"des\">WiFi</p><label for=\"ssid\">SSID</label><input type=\"text\" class=\"text\" name=\"ssid\" value=\"{SSID}\"/><label for=\"pwd\">Password</label><input type=\"password\" class=\"text\" name=\"pwd\" value=\"{PWD}\"/><p class=\"des\">Device Host Name</p><label for=\"device\">Device Name</label><input type=\"text\" class=\"text\" name=\"device\" value=\"{DEVICE}\"/><a class=\"erase\" href=\"/erase\">ERASE SETTINGS (not WiFi)</a><p class=\"des\">Inverter</p>{INVERTERS}<br/><p class=\"subdes\">General</p><label for=\"invInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"invInterval\" value=\"{INV_INTERVAL}\"/><p class=\"des\">Pinout (Wemos)</p>{PINOUT}<p class=\"des\">Radio (NRF24L01+)</p><label for=\"rf24Power\">Amplifier Power Level</label><select name=\"rf24Power\">{RF24}</select><p class=\"des\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><label for=\"mqttPort\">Port</label><input type=\"text\" class=\"text\" name=\"mqttPort\" value=\"{MQTT_PORT}\"/><label for=\"mqttUser\">Username (optional)</label><input type=\"text\" class=\"text\" name=\"mqttUser\" value=\"{MQTT_USER}\"/><label for=\"mqttPwd\">Password (optional)</label><input type=\"text\" class=\"text\" name=\"mqttPwd\" value=\"{MQTT_PWD}\"/><label for=\"mqttTopic\">Topic</label><input type=\"text\" class=\"text\" name=\"mqttTopic\" value=\"{MQTT_TOPIC}\"/><label for=\"mqttInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"mqttInterval\" value=\"{MQTT_INTERVAL}\"/><p class=\"des\"> </p><input type=\"checkbox\" class=\"cb\" name=\"reboot\"/><label for=\"reboot\">Reboot device after successful save</label><input type=\"submit\" value=\"save\" class=\"btn\" /></form></div></div><div id=\"footer\"><p class=\"left\"><a href=\"/\">Home</a></p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY - {VERSION}</p><p class=\"right\"><a href=\"/factory\">Factory Reset</a></p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p></div></body></html>";
|
const char setup_html[] PROGMEM = "<!doctype html><html><head><title>Setup - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body><h1>Setup</h1><div id=\"setup\" class=\"content\"><div id=\"content\"><p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information. </p><form method=\"post\" action=\"{IP}/save\"><p class=\"des\">WiFi</p><label for=\"ssid\">SSID</label><input type=\"text\" class=\"text\" name=\"ssid\" value=\"{SSID}\"/><label for=\"pwd\">Password</label><input type=\"password\" class=\"text\" name=\"pwd\" value=\"{PWD}\"/><p class=\"des\">Device Host Name</p><label for=\"device\">Device Name</label><input type=\"text\" class=\"text\" name=\"device\" value=\"{DEVICE}\"/><a class=\"erase\" href=\"/erase\">ERASE SETTINGS (not WiFi)</a><p class=\"des\">Inverter</p>{INVERTERS}<br/><p class=\"subdes\">General</p><label for=\"invInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"invInterval\" value=\"{INV_INTERVAL}\"/><p class=\"des\">Pinout (Wemos)</p>{PINOUT}<p class=\"des\">Radio (NRF24L01+)</p><label for=\"rf24Power\">Amplifier Power Level</label><select name=\"rf24Power\">{RF24}</select><p class=\"des\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><label for=\"mqttPort\">Port</label><input type=\"text\" class=\"text\" name=\"mqttPort\" value=\"{MQTT_PORT}\"/><label for=\"mqttUser\">Username (optional)</label><input type=\"text\" class=\"text\" name=\"mqttUser\" value=\"{MQTT_USER}\"/><label for=\"mqttPwd\">Password (optional)</label><input type=\"text\" class=\"text\" name=\"mqttPwd\" value=\"{MQTT_PWD}\"/><label for=\"mqttTopic\">Topic</label><input type=\"text\" class=\"text\" name=\"mqttTopic\" value=\"{MQTT_TOPIC}\"/><label for=\"mqttInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"mqttInterval\" value=\"{MQTT_INTERVAL}\"/><p class=\"des\"> </p><input type=\"checkbox\" class=\"cb\" name=\"reboot\"/><label for=\"reboot\">Reboot device after successful save</label><input type=\"submit\" value=\"save\" class=\"btn\" /></form></div></div><div id=\"footer\"><p class=\"left\"><a href=\"{IP}/\">Home</a></p><p class=\"left\"><a href=\"{IP}/update\">Update Firmware</a></p><p class=\"right\">AHOY - {VERSION}</p><p class=\"right\"><a href=\"{IP}/factory\">Factory Reset</a></p><p class=\"right\"><a href=\"{IP}/reboot\">Reboot</a></p></div></body></html>";
|
||||||
#endif /*__SETUP_H__*/
|
#endif /*__SETUP_H__*/
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<p><span class="des">Statistics: </span><pre id="cmds"></pre></p>
|
<p><span class="des">Statistics: </span><pre id="cmds"></pre></p>
|
||||||
|
|
||||||
<div id="note">
|
<div id="note">
|
||||||
This project was started from <a href="https://www.mikrocontroller.net/topic/525778" target="_blank">this (Mikrocontroller.net)</a> discussion.<br/>
|
This project was started from <a href="https://www.mikrocontroller.net/topic/525778" target="_blank">this discussion. (Mikrocontroller.net)</a><br/>
|
||||||
New updates can be found on Github: <a href="https://github.com/grindylow/ahoy" target="_blank">https://github.com/grindylow/ahoy</a><br/>
|
New updates can be found on Github: <a href="https://github.com/grindylow/ahoy" target="_blank">https://github.com/grindylow/ahoy</a><br/>
|
||||||
<br/>
|
<br/>
|
||||||
Please report issues using the feature provided by Github.
|
Please report issues using the feature provided by Github.
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<p>
|
<p>
|
||||||
Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.
|
Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.
|
||||||
</p>
|
</p>
|
||||||
<form method="post" action="/save">
|
<form method="post" action="{IP}/save">
|
||||||
<p class="des">WiFi</p>
|
<p class="des">WiFi</p>
|
||||||
<label for="ssid">SSID</label>
|
<label for="ssid">SSID</label>
|
||||||
<input type="text" class="text" name="ssid" value="{SSID}"/>
|
<input type="text" class="text" name="ssid" value="{SSID}"/>
|
||||||
|
@ -61,11 +61,11 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<p class="left"><a href="/">Home</a></p>
|
<p class="left"><a href="{IP}/">Home</a></p>
|
||||||
<p class="left"><a href="/update">Update Firmware</a></p>
|
<p class="left"><a href="{IP}/update">Update Firmware</a></p>
|
||||||
<p class="right">AHOY - {VERSION}</p>
|
<p class="right">AHOY - {VERSION}</p>
|
||||||
<p class="right"><a href="/factory">Factory Reset</a></p>
|
<p class="right"><a href="{IP}/factory">Factory Reset</a></p>
|
||||||
<p class="right"><a href="/reboot">Reboot</a></p>
|
<p class="right"><a href="{IP}/reboot">Reboot</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -18,6 +18,7 @@ Main::Main(void) {
|
||||||
|
|
||||||
mLimit = 10;
|
mLimit = 10;
|
||||||
mNextTryTs = 0;
|
mNextTryTs = 0;
|
||||||
|
mApLastTick = 0;
|
||||||
|
|
||||||
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||||
|
|
||||||
|
@ -53,16 +54,16 @@ void Main::setup(const char *ssid, const char *pwd, uint32_t timeout) {
|
||||||
|
|
||||||
if(true == startAp) {
|
if(true == startAp) {
|
||||||
if(strlen(pwd) < 8)
|
if(strlen(pwd) < 8)
|
||||||
Serial.println("password must be at least 8 characters long");
|
DPRINTLN("ERROR: password must be at least 8 characters long");
|
||||||
setupAp(ssid, pwd);
|
}
|
||||||
|
else {
|
||||||
|
mTimestamp = getNtpTime();
|
||||||
|
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mUpdater->setup(mWeb);
|
mUpdater->setup(mWeb);
|
||||||
|
|
||||||
mApActive = startAp;
|
mApActive = startAp;
|
||||||
|
|
||||||
mTimestamp = getNtpTime();
|
|
||||||
//Serial.println("[NTP]: " + getDateTimeStr(getNtpTime()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,10 +72,17 @@ void Main::loop(void) {
|
||||||
if(mApActive) {
|
if(mApActive) {
|
||||||
mDns->processNextRequest();
|
mDns->processNextRequest();
|
||||||
if(checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
|
if(checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
|
||||||
|
mApLastTick = millis();
|
||||||
mApActive = setupStation(mLimit);
|
mApActive = setupStation(mLimit);
|
||||||
if(mApActive)
|
if(mApActive)
|
||||||
setupAp(WIFI_AP_SSID, WIFI_AP_PWD);
|
setupAp(WIFI_AP_SSID, WIFI_AP_PWD);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if(millis() - mApLastTick > 10000) {
|
||||||
|
mApLastTick = millis();
|
||||||
|
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mWeb->handleClient();
|
mWeb->handleClient();
|
||||||
|
|
||||||
|
@ -118,7 +126,12 @@ bool Main::getConfig(void) {
|
||||||
void Main::setupAp(const char *ssid, const char *pwd) {
|
void Main::setupAp(const char *ssid, const char *pwd) {
|
||||||
IPAddress apIp(192, 168, 1, 1);
|
IPAddress apIp(192, 168, 1, 1);
|
||||||
|
|
||||||
Serial.println("\n---------\nAP MODE\nSSDI: "+ String(ssid) + "\nPWD: " + String(pwd) + "\n---------\n");
|
DPRINTLN("\n---------\nAP MODE\nSSDI: "
|
||||||
|
+ String(ssid) + "\nPWD: "
|
||||||
|
+ String(pwd) + "\nActive for: "
|
||||||
|
+ String(WIFI_AP_ACTIVE_TIME) + " seconds"
|
||||||
|
+ "\n---------\n");
|
||||||
|
DPRINTLN("DBG: " + String(mNextTryTs));
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
||||||
|
@ -153,7 +166,7 @@ bool Main::setupStation(uint32_t timeout) {
|
||||||
WiFi.hostname(mDeviceName);
|
WiFi.hostname(mDeviceName);
|
||||||
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
Serial.println("wait for network");
|
DPRINTLN("connect to network '" + String(mStationSsid) + "' ...");
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(100);
|
delay(100);
|
||||||
if(cnt % 100 == 0)
|
if(cnt % 100 == 0)
|
||||||
|
@ -192,6 +205,10 @@ void Main::showSetup(void) {
|
||||||
// -> the PWD will only be changed if it does not match the default "{PWD}"
|
// -> the PWD will only be changed if it does not match the default "{PWD}"
|
||||||
html.replace("{DEVICE}", String(mDeviceName));
|
html.replace("{DEVICE}", String(mDeviceName));
|
||||||
html.replace("{VERSION}", String(mVersion));
|
html.replace("{VERSION}", String(mVersion));
|
||||||
|
if(mApActive)
|
||||||
|
html.replace("{IP}", String("http://192.168.1.1"));
|
||||||
|
else
|
||||||
|
html.replace("{IP}", ("http://" + String(WiFi.localIP().toString())));
|
||||||
|
|
||||||
mWeb->send(200, "text/html", html);
|
mWeb->send(200, "text/html", html);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +250,7 @@ void Main::saveValues(bool webSend = true) {
|
||||||
if(webSend) {
|
if(webSend) {
|
||||||
if(mWeb->arg("reboot") == "on")
|
if(mWeb->arg("reboot") == "on")
|
||||||
showReboot();
|
showReboot();
|
||||||
else
|
else // TODO: add device name as redirect in AP-mode
|
||||||
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
|
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
|
||||||
"<p>saved</p></body></html>");
|
"<p>saved</p></body></html>");
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "eep.h"
|
#include "eep.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
const byte mDnsPort = 53;
|
const byte mDnsPort = 53;
|
||||||
|
@ -57,11 +58,13 @@ class Main {
|
||||||
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
|
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
|
||||||
uint16_t end;
|
uint16_t end;
|
||||||
do {
|
do {
|
||||||
end = addr += 64;
|
end = addr + 64;
|
||||||
if(end > (ADDR_SETTINGS_CRC + 2))
|
if(end > (ADDR_SETTINGS_CRC + 2))
|
||||||
end = (ADDR_SETTINGS_CRC + 2 - addr);
|
end = (ADDR_SETTINGS_CRC + 2);
|
||||||
mEep->write(ADDR_START_SETTINGS, buf, (ADDR_NEXT-ADDR_START_SETTINGS));
|
DPRINTLN("erase: 0x" + String(addr, HEX) + " - 0x" + String(end, HEX));
|
||||||
} while(addr < ADDR_START_SETTINGS);
|
mEep->write(addr, buf, (end-addr));
|
||||||
|
addr = end;
|
||||||
|
} while(addr < (ADDR_SETTINGS_CRC + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
|
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
|
||||||
|
@ -90,6 +93,7 @@ class Main {
|
||||||
uint32_t mTimestamp;
|
uint32_t mTimestamp;
|
||||||
uint32_t mLimit;
|
uint32_t mLimit;
|
||||||
uint32_t mNextTryTs;
|
uint32_t mNextTryTs;
|
||||||
|
uint32_t mApLastTick;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getConfig(void);
|
bool getConfig(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue