mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
* set default pinout to Wemos D1mini
* pinout will be saved in eeprom, but changes not applied for now
This commit is contained in:
parent
9e6cae26a7
commit
a95069e65c
10 changed files with 107 additions and 35 deletions
|
@ -64,6 +64,12 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
|
||||||
mSendTicker->attach_ms(interval, std::bind(&app::sendTicker, this));
|
mSendTicker->attach_ms(interval, std::bind(&app::sendTicker, this));
|
||||||
|
|
||||||
|
|
||||||
|
// pinout
|
||||||
|
mEep->read(ADDR_PINOUT, &mSys->Radio.pinCs);
|
||||||
|
mEep->read(ADDR_PINOUT+1, &mSys->Radio.pinCe);
|
||||||
|
mEep->read(ADDR_PINOUT+2, &mSys->Radio.pinIrq);
|
||||||
|
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
uint8_t mqttAddr[MQTT_ADDR_LEN];
|
uint8_t mqttAddr[MQTT_ADDR_LEN];
|
||||||
char mqttUser[MQTT_USER_LEN];
|
char mqttUser[MQTT_USER_LEN];
|
||||||
|
@ -372,6 +378,26 @@ void app::showSetup(void) {
|
||||||
}
|
}
|
||||||
html.replace("{INVERTERS}", String(inv));
|
html.replace("{INVERTERS}", String(inv));
|
||||||
|
|
||||||
|
|
||||||
|
// pinout
|
||||||
|
String pinout;
|
||||||
|
for(uint8_t i = 0; i < 3; i++) {
|
||||||
|
pinout += "<label for=\"" + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + "</label>";
|
||||||
|
pinout += "<select name=\"" + String(pinArgNames[i]) + "\">";
|
||||||
|
for(uint8_t j = 0; j <= 16; j++) {
|
||||||
|
pinout += "<option value=\"" + String(j) + "\"";
|
||||||
|
switch(i) {
|
||||||
|
default: if(j == mSys->Radio.pinCs) pinout += " selected"; break;
|
||||||
|
case 1: if(j == mSys->Radio.pinCe) pinout += " selected"; break;
|
||||||
|
case 2: if(j == mSys->Radio.pinIrq) pinout += " selected"; break;
|
||||||
|
}
|
||||||
|
pinout += ">" + String(wemosPins[j]) + "</option>";
|
||||||
|
}
|
||||||
|
pinout += "</select>";
|
||||||
|
}
|
||||||
|
html.replace("{PINOUT}", String(pinout));
|
||||||
|
|
||||||
|
|
||||||
if(mSettingsValid) {
|
if(mSettingsValid) {
|
||||||
mEep->read(ADDR_INV_INTERVAL, &interval);
|
mEep->read(ADDR_INV_INTERVAL, &interval);
|
||||||
html.replace("{INV_INTERVAL}", String(interval));
|
html.replace("{INV_INTERVAL}", String(interval));
|
||||||
|
@ -530,6 +556,13 @@ void app::saveValues(bool webSend = true) {
|
||||||
mEep->write(ADDR_INV_INTERVAL, interval);
|
mEep->write(ADDR_INV_INTERVAL, interval);
|
||||||
|
|
||||||
|
|
||||||
|
// pinout
|
||||||
|
for(uint8_t i = 0; i < 3; i ++) {
|
||||||
|
uint8_t pin = mWeb->arg(String(pinArgNames[i])).toInt();
|
||||||
|
mEep->write(ADDR_PINOUT + i, pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
|
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
|
||||||
char mqttUser[MQTT_USER_LEN];
|
char mqttUser[MQTT_USER_LEN];
|
||||||
|
@ -565,3 +598,14 @@ void app::saveValues(bool webSend = true) {
|
||||||
"<p>Error while saving</p></body></html>");
|
"<p>Error while saving</p></body></html>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void app::updateCrc(void) {
|
||||||
|
Main::updateCrc();
|
||||||
|
|
||||||
|
uint16_t crc;
|
||||||
|
crc = buildEEpCrc(ADDR_START_SETTINGS, (ADDR_NEXT - ADDR_START_SETTINGS));
|
||||||
|
//Serial.println("new CRC: " + String(crc, HEX));
|
||||||
|
mEep->write(ADDR_SETTINGS_CRC, crc);
|
||||||
|
}
|
||||||
|
|
|
@ -9,14 +9,19 @@
|
||||||
|
|
||||||
#include "CircularBuffer.h"
|
#include "CircularBuffer.h"
|
||||||
#include "hmSystem.h"
|
#include "hmSystem.h"
|
||||||
|
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
|
||||||
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN> RadioType;
|
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN> RadioType;
|
||||||
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
||||||
typedef HmSystem<RadioType, BufferType, MAX_NUM_INVERTERS, float> HmSystemType;
|
typedef HmSystem<RadioType, BufferType, MAX_NUM_INVERTERS, float> HmSystemType;
|
||||||
|
|
||||||
|
const char* const wemosPins[] = {"D3 (GPIO0)", "TX (GPIO1)", "D4 (GPIO2)", "RX (GPIO3)",
|
||||||
|
"D2 (GPIO4)", "D1 (GPIO5)", "GPIO6", "GPIO7", "GPIO8",
|
||||||
|
"GPIO9", "GPIO10", "GPIO11", "D6 (GPIO12)", "D7 (GPIO13)",
|
||||||
|
"D5 (GPIO14)", "D8 (GPIO15)", "D0 (GPIO16)"};
|
||||||
|
const char* const pinNames[] = {"CS", "CE", "IRQ"};
|
||||||
|
const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq"};
|
||||||
|
|
||||||
class app : public Main {
|
class app : public Main {
|
||||||
public:
|
public:
|
||||||
app();
|
app();
|
||||||
|
@ -42,6 +47,7 @@ class app : public Main {
|
||||||
void showMqtt(void);
|
void showMqtt(void);
|
||||||
|
|
||||||
void saveValues(bool webSend);
|
void saveValues(bool webSend);
|
||||||
|
void updateCrc(void);
|
||||||
|
|
||||||
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
||||||
Serial.print(String(info));
|
Serial.print(String(info));
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
// PINOUT
|
// PINOUT
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define RF24_IRQ_PIN 4
|
|
||||||
#define RF24_CE_PIN 5
|
|
||||||
#define RF24_CS_PIN 15
|
#define RF24_CS_PIN 15
|
||||||
|
#define RF24_CE_PIN 2 //5
|
||||||
|
#define RF24_IRQ_PIN 0 //4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 3
|
#define VERSION_PATCH 4
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -34,13 +34,14 @@
|
||||||
#define SSID_LEN 32
|
#define SSID_LEN 32
|
||||||
#define PWD_LEN 32
|
#define PWD_LEN 32
|
||||||
#define DEVNAME_LEN 16
|
#define DEVNAME_LEN 16
|
||||||
#define CRC_LEN 2
|
#define CRC_LEN 2 // uint16_t
|
||||||
|
|
||||||
#define INV_ADDR_LEN MAX_NUM_INVERTERS * 8 // uint64_t
|
#define INV_ADDR_LEN MAX_NUM_INVERTERS * 8 // uint64_t
|
||||||
#define INV_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[]
|
#define INV_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[]
|
||||||
#define INV_TYPE_LEN MAX_NUM_INVERTERS * 1 // uint8_t
|
#define INV_TYPE_LEN MAX_NUM_INVERTERS * 1 // uint8_t
|
||||||
#define INV_INTERVAL_LEN 2 // uint16_t
|
#define INV_INTERVAL_LEN 2 // uint16_t
|
||||||
|
|
||||||
|
#define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ
|
||||||
|
|
||||||
#define MQTT_ADDR_LEN 4 // IP
|
#define MQTT_ADDR_LEN 4 // IP
|
||||||
#define MQTT_USER_LEN 16
|
#define MQTT_USER_LEN 16
|
||||||
|
@ -53,7 +54,12 @@
|
||||||
#define ADDR_SSID ADDR_START
|
#define ADDR_SSID ADDR_START
|
||||||
#define ADDR_PWD ADDR_SSID + SSID_LEN
|
#define ADDR_PWD ADDR_SSID + SSID_LEN
|
||||||
#define ADDR_DEVNAME ADDR_PWD + PWD_LEN
|
#define ADDR_DEVNAME ADDR_PWD + PWD_LEN
|
||||||
#define ADDR_INV_ADDR ADDR_DEVNAME + DEVNAME_LEN
|
#define ADDR_WIFI_CRC ADDR_DEVNAME + DEVNAME_LEN
|
||||||
|
#define ADDR_START_SETTINGS ADDR_WIFI_CRC + CRC_LEN
|
||||||
|
|
||||||
|
#define ADDR_PINOUT ADDR_START_SETTINGS
|
||||||
|
|
||||||
|
#define ADDR_INV_ADDR ADDR_PINOUT + PINOUT_LEN
|
||||||
#define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN
|
#define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN
|
||||||
#define ADDR_INV_TYPE ADDR_INV_NAME + INV_NAME_LEN
|
#define ADDR_INV_TYPE ADDR_INV_NAME + INV_NAME_LEN
|
||||||
#define ADDR_INV_INTERVAL ADDR_INV_TYPE + INV_TYPE_LEN
|
#define ADDR_INV_INTERVAL ADDR_INV_TYPE + INV_TYPE_LEN
|
||||||
|
|
|
@ -52,6 +52,10 @@ class HmRadio {
|
||||||
mChanIdx = 1;
|
mChanIdx = 1;
|
||||||
|
|
||||||
calcDtuCrc();
|
calcDtuCrc();
|
||||||
|
|
||||||
|
pinCs = CS_PIN;
|
||||||
|
pinCe = CE_PIN;
|
||||||
|
pinIrq = IRQ_PIN;
|
||||||
}
|
}
|
||||||
~HmRadio() {}
|
~HmRadio() {}
|
||||||
|
|
||||||
|
@ -117,7 +121,11 @@ class HmRadio {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
uint8_t pinCs;
|
||||||
|
uint8_t pinCe;
|
||||||
|
uint8_t pinIrq;
|
||||||
|
|
||||||
|
private:
|
||||||
void calcDtuCrc(void) {
|
void calcDtuCrc(void) {
|
||||||
uint64_t addr = DTU_RADIO_ID;
|
uint64_t addr = DTU_RADIO_ID;
|
||||||
uint8_t tmp[5];
|
uint8_t tmp[5];
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
String setup_html = "<!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}\"/><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\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><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 (seconds)</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=\"button\" /></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></div></body></html>";
|
String setup_html = "<!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}\"/><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</p> {PINOUT} <p class=\"des\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><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 (seconds)</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></div></body></html>";
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
String style_css = "h1 { margin: 0; padding: 20pt; font-size: 22pt; color: #fff; background-color: #006ec0; display: block; text-transform: uppercase; } html, body { font-family: Arial; margin: 0; padding: 0; } p { text-align: justify; font-size: 13pt; } .des { margin-top: 35px; font-size: 14pt; color: #006ec0; } .subdes { font-size: 13pt; color: #006ec0; margin-left: 7px; } .fw { width: 60px; display: block; float: left; } .color { width: 50px; height: 50px; border: 1px solid #ccc; } .range { width: 300px; } a:link, a:visited { text-decoration: none; font-size: 13pt; color: #006ec0; } a:hover, a:focus { color: #f00; } #content { padding: 15px 15px 60px 15px; } #footer { position: fixed; bottom: 0px; height: 45px; background-color: #006ec0; width: 100%; } #footer p { color: #fff; padding-left: 20px; padding-right: 20px; font-size: 10pt !important; } #footer a { color: #fff; } div.content { background-color: #fff; padding-bottom: 65px; overflow: hidden; } input { padding: 7px; font-size: 13pt; } input.text, input.password { width: 70%; box-sizing: border-box; margin-bottom: 10px; /*float: right;*/ border: 1px solid #ccc; } input.button { background-color: #006ec0; color: #fff; border: 0px; float: right; text-transform: uppercase; } input.cb { margin-bottom: 20px; } label { width: 20%; display: inline-block; font-size: 12pt; padding-right: 10px; margin-left: 10px; } .left { float: left; } .right { float: right; } div.ch { width: 250px; height: 410px; background-color: #006ec0; display: inline-block; margin-right: 20px; margin-bottom: 20px; } div.ch .value, div.ch .info, div.ch .head { color: #fff; display: block; width: 100%; text-align: center; } div.ch .unit { font-size: 19px; margin-left: 10px; } div.ch .value { margin-top: 20px; font-size: 30px; } div.ch .info { margin-top: 3px; font-size: 10px; } div.ch .head { background-color: #003c80; padding: 10px 0 10px 0; } ";
|
String style_css = "h1 { margin: 0; padding: 20pt; font-size: 22pt; color: #fff; background-color: #006ec0; display: block; text-transform: uppercase; } html, body { font-family: Arial; margin: 0; padding: 0; } p { text-align: justify; font-size: 13pt; } .des { margin-top: 35px; font-size: 14pt; color: #006ec0; } .subdes { font-size: 13pt; color: #006ec0; margin-left: 7px; } .fw { width: 60px; display: block; float: left; } .color { width: 50px; height: 50px; border: 1px solid #ccc; } .range { width: 300px; } a:link, a:visited { text-decoration: none; font-size: 13pt; color: #006ec0; } a:hover, a:focus { color: #f00; } #content { padding: 15px 15px 60px 15px; } #footer { position: fixed; bottom: 0px; height: 45px; background-color: #006ec0; width: 100%; } #footer p { color: #fff; padding-left: 20px; padding-right: 20px; font-size: 10pt !important; } #footer a { color: #fff; } div.content { background-color: #fff; padding-bottom: 65px; overflow: hidden; } input, select { padding: 7px; font-size: 13pt; } input.text, select { width: 70%; box-sizing: border-box; margin-bottom: 10px; border: 1px solid #ccc; } input.btn { background-color: #006ec0; color: #fff; border: 0px; float: right; text-transform: uppercase; } input.cb { margin-bottom: 20px; } label { width: 20%; display: inline-block; font-size: 12pt; padding-right: 10px; margin-left: 10px; } .left { float: left; } .right { float: right; } div.ch { width: 250px; height: 410px; background-color: #006ec0; display: inline-block; margin-right: 20px; margin-bottom: 20px; } div.ch .value, div.ch .info, div.ch .head { color: #fff; display: block; width: 100%; text-align: center; } div.ch .unit { font-size: 19px; margin-left: 10px; } div.ch .value { margin-top: 20px; font-size: 30px; } div.ch .info { margin-top: 3px; font-size: 10px; } div.ch .head { background-color: #003c80; padding: 10px 0 10px 0; } ";
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
<label for="invInterval">Interval (ms)</label>
|
<label for="invInterval">Interval (ms)</label>
|
||||||
<input type="text" class="text" name="invInterval" value="{INV_INTERVAL}"/>
|
<input type="text" class="text" name="invInterval" value="{INV_INTERVAL}"/>
|
||||||
|
|
||||||
|
<p class="des">Pinout (Wemos)</p>
|
||||||
|
{PINOUT}
|
||||||
|
|
||||||
<p class="des">MQTT</p>
|
<p class="des">MQTT</p>
|
||||||
<label for="mqttAddr">Broker / Server IP</label>
|
<label for="mqttAddr">Broker / Server IP</label>
|
||||||
<input type="text" class="text" name="mqttAddr" value="{MQTT_ADDR}"/>
|
<input type="text" class="text" name="mqttAddr" value="{MQTT_ADDR}"/>
|
||||||
|
@ -43,7 +46,7 @@
|
||||||
<p class="des"> </p>
|
<p class="des"> </p>
|
||||||
<input type="checkbox" class="cb" name="reboot"/>
|
<input type="checkbox" class="cb" name="reboot"/>
|
||||||
<label for="reboot">Reboot device after successful save</label>
|
<label for="reboot">Reboot device after successful save</label>
|
||||||
<input type="submit" value="save" class="button" />
|
<input type="submit" value="save" class="btn" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -86,20 +86,19 @@ div.content {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input, select {
|
||||||
padding: 7px;
|
padding: 7px;
|
||||||
font-size: 13pt;
|
font-size: 13pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.text, input.password {
|
input.text, select {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
/*float: right;*/
|
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.button {
|
input.btn {
|
||||||
background-color: #006ec0;
|
background-color: #006ec0;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
|
|
|
@ -13,6 +13,7 @@ Main::Main(void) {
|
||||||
mUdp = new WiFiUDP();
|
mUdp = new WiFiUDP();
|
||||||
|
|
||||||
mApActive = true;
|
mApActive = true;
|
||||||
|
mWifiSettingsValid = false;
|
||||||
mSettingsValid = false;
|
mSettingsValid = false;
|
||||||
|
|
||||||
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||||
|
@ -74,21 +75,11 @@ void Main::loop(void) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool Main::getConfig(void) {
|
bool Main::getConfig(void) {
|
||||||
bool mApActive = false;
|
bool mApActive = false;
|
||||||
uint16_t crcRd, crcCheck;
|
|
||||||
uint8_t buf[ADDR_NEXT-ADDR_START];
|
|
||||||
|
|
||||||
// check settings crc
|
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
||||||
mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START));
|
mSettingsValid = checkEEpCrc(ADDR_START_SETTINGS, (ADDR_NEXT-ADDR_START_SETTINGS), ADDR_SETTINGS_CRC);
|
||||||
crcCheck = crc16(buf, (ADDR_NEXT-ADDR_START));
|
|
||||||
mEep->read(ADDR_SETTINGS_CRC, &crcRd);
|
|
||||||
|
|
||||||
if(crcCheck == crcRd)
|
if(mWifiSettingsValid) {
|
||||||
mSettingsValid = true;
|
|
||||||
//else
|
|
||||||
// Serial.println("CRC RD: " + String(crcRd, HEX) + " CRC CHECK: " + String(crcCheck, HEX));
|
|
||||||
|
|
||||||
|
|
||||||
if(mSettingsValid) {
|
|
||||||
mEep->read(ADDR_SSID, mStationSsid, SSID_LEN);
|
mEep->read(ADDR_SSID, mStationSsid, SSID_LEN);
|
||||||
mEep->read(ADDR_PWD, mStationPwd, PWD_LEN);
|
mEep->read(ADDR_PWD, mStationPwd, PWD_LEN);
|
||||||
mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
|
mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
|
||||||
|
@ -98,6 +89,10 @@ bool Main::getConfig(void) {
|
||||||
memset(mStationSsid, 0, SSID_LEN);
|
memset(mStationSsid, 0, SSID_LEN);
|
||||||
memset(mStationPwd, 0, PWD_LEN);
|
memset(mStationPwd, 0, PWD_LEN);
|
||||||
memset(mDeviceName, 0, DEVNAME_LEN);
|
memset(mDeviceName, 0, DEVNAME_LEN);
|
||||||
|
|
||||||
|
// erase eeprom
|
||||||
|
uint8_t buf[ADDR_NEXT-ADDR_START_SETTINGS] = {0};
|
||||||
|
mEep->write(ADDR_START_SETTINGS, buf, (ADDR_NEXT-ADDR_START_SETTINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mApActive;
|
return mApActive;
|
||||||
|
@ -223,12 +218,9 @@ void Main::saveValues(bool webSend = true) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::updateCrc(void) {
|
void Main::updateCrc(void) {
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint8_t buf[ADDR_NEXT-ADDR_START];
|
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
|
||||||
|
|
||||||
mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START));
|
|
||||||
crc = crc16(buf, (ADDR_NEXT-ADDR_START));
|
|
||||||
//Serial.println("new CRC: " + String(crc, HEX));
|
//Serial.println("new CRC: " + String(crc, HEX));
|
||||||
mEep->write(ADDR_SETTINGS_CRC, crc);
|
mEep->write(ADDR_WIFI_CRC, crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,22 @@ class Main {
|
||||||
virtual void saveValues(bool webSend);
|
virtual void saveValues(bool webSend);
|
||||||
virtual void updateCrc(void);
|
virtual void updateCrc(void);
|
||||||
|
|
||||||
|
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
|
||||||
|
uint8_t buf[length];
|
||||||
|
mEep->read(start, buf, length);
|
||||||
|
return crc16(buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
|
||||||
|
uint16_t crcRd, crcCheck;
|
||||||
|
crcCheck = buildEEpCrc(start, length);
|
||||||
|
mEep->read(crcPos, &crcRd);
|
||||||
|
return (crcCheck == crcRd);
|
||||||
|
}
|
||||||
|
|
||||||
char mStationSsid[SSID_LEN];
|
char mStationSsid[SSID_LEN];
|
||||||
char mStationPwd[PWD_LEN];
|
char mStationPwd[PWD_LEN];
|
||||||
|
bool mWifiSettingsValid;
|
||||||
bool mSettingsValid;
|
bool mSettingsValid;
|
||||||
bool mApActive;
|
bool mApActive;
|
||||||
ESP8266WebServer *mWeb;
|
ESP8266WebServer *mWeb;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue