Browse Source

* set default pinout to Wemos D1mini

* pinout will be saved in eeprom, but changes not applied for now
pull/8/head
lumapu 3 years ago
parent
commit
a95069e65c
  1. 44
      tools/esp8266/app.cpp
  2. 10
      tools/esp8266/app.h
  3. 16
      tools/esp8266/defines.h
  4. 10
      tools/esp8266/hmRadio.h
  5. 2
      tools/esp8266/html/h/setup_html.h
  6. 2
      tools/esp8266/html/h/style_css.h
  7. 5
      tools/esp8266/html/setup.html
  8. 7
      tools/esp8266/html/style.css
  9. 32
      tools/esp8266/main.cpp
  10. 14
      tools/esp8266/main.h

44
tools/esp8266/app.cpp

@ -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));
// 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
uint8_t mqttAddr[MQTT_ADDR_LEN];
char mqttUser[MQTT_USER_LEN];
@ -372,6 +378,26 @@ void app::showSetup(void) {
}
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) {
mEep->read(ADDR_INV_INTERVAL, &interval);
html.replace("{INV_INTERVAL}", String(interval));
@ -530,6 +556,13 @@ void app::saveValues(bool webSend = true) {
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
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
char mqttUser[MQTT_USER_LEN];
@ -565,3 +598,14 @@ void app::saveValues(bool webSend = true) {
"<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);
}

10
tools/esp8266/app.h

@ -9,14 +9,19 @@
#include "CircularBuffer.h"
#include "hmSystem.h"
#include "mqtt.h"
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN> RadioType;
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
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 {
public:
app();
@ -42,6 +47,7 @@ class app : public Main {
void showMqtt(void);
void saveValues(bool webSend);
void updateCrc(void);
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
Serial.print(String(info));

16
tools/esp8266/defines.h

@ -5,9 +5,9 @@
//-------------------------------------
// PINOUT
//-------------------------------------
#define RF24_IRQ_PIN 4
#define RF24_CE_PIN 5
#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_MINOR 2
#define VERSION_PATCH 3
#define VERSION_PATCH 4
//-------------------------------------
@ -34,13 +34,14 @@
#define SSID_LEN 32
#define PWD_LEN 32
#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_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[]
#define INV_TYPE_LEN MAX_NUM_INVERTERS * 1 // uint8_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_USER_LEN 16
@ -53,7 +54,12 @@
#define ADDR_SSID ADDR_START
#define ADDR_PWD ADDR_SSID + SSID_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_TYPE ADDR_INV_NAME + INV_NAME_LEN
#define ADDR_INV_INTERVAL ADDR_INV_TYPE + INV_TYPE_LEN

10
tools/esp8266/hmRadio.h

@ -52,6 +52,10 @@ class HmRadio {
mChanIdx = 1;
calcDtuCrc();
pinCs = CS_PIN;
pinCe = CE_PIN;
pinIrq = IRQ_PIN;
}
~HmRadio() {}
@ -117,7 +121,11 @@ class HmRadio {
return valid;
}
protected:
uint8_t pinCs;
uint8_t pinCe;
uint8_t pinIrq;
private:
void calcDtuCrc(void) {
uint64_t addr = DTU_RADIO_ID;
uint8_t tmp[5];

2
tools/esp8266/html/h/setup_html.h

@ -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\">&nbsp;</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\">&nbsp;</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>";

2
tools/esp8266/html/h/style_css.h

@ -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; } ";

5
tools/esp8266/html/setup.html

@ -28,6 +28,9 @@
<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">MQTT</p>
<label for="mqttAddr">Broker / Server IP</label>
<input type="text" class="text" name="mqttAddr" value="{MQTT_ADDR}"/>
@ -43,7 +46,7 @@
<p class="des">&nbsp;</p>
<input type="checkbox" class="cb" name="reboot"/>
<label for="reboot">Reboot device after successful save</label>
<input type="submit" value="save" class="button" />
<input type="submit" value="save" class="btn" />
</form>
</div>
</div>

7
tools/esp8266/html/style.css

@ -86,20 +86,19 @@ div.content {
overflow: hidden;
}
input {
input, select {
padding: 7px;
font-size: 13pt;
}
input.text, input.password {
input.text, select {
width: 70%;
box-sizing: border-box;
margin-bottom: 10px;
/*float: right;*/
border: 1px solid #ccc;
}
input.button {
input.btn {
background-color: #006ec0;
color: #fff;
border: 0px;

32
tools/esp8266/main.cpp

@ -12,8 +12,9 @@ Main::Main(void) {
mUpdater = new ESP8266HTTPUpdateServer();
mUdp = new WiFiUDP();
mApActive = true;
mSettingsValid = false;
mApActive = true;
mWifiSettingsValid = false;
mSettingsValid = false;
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 mApActive = false;
uint16_t crcRd, crcCheck;
uint8_t buf[ADDR_NEXT-ADDR_START];
// check settings crc
mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START));
crcCheck = crc16(buf, (ADDR_NEXT-ADDR_START));
mEep->read(ADDR_SETTINGS_CRC, &crcRd);
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
mSettingsValid = checkEEpCrc(ADDR_START_SETTINGS, (ADDR_NEXT-ADDR_START_SETTINGS), ADDR_SETTINGS_CRC);
if(crcCheck == crcRd)
mSettingsValid = true;
//else
// Serial.println("CRC RD: " + String(crcRd, HEX) + " CRC CHECK: " + String(crcCheck, HEX));
if(mSettingsValid) {
if(mWifiSettingsValid) {
mEep->read(ADDR_SSID, mStationSsid, SSID_LEN);
mEep->read(ADDR_PWD, mStationPwd, PWD_LEN);
mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
@ -98,6 +89,10 @@ bool Main::getConfig(void) {
memset(mStationSsid, 0, SSID_LEN);
memset(mStationPwd, 0, PWD_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;
@ -223,12 +218,9 @@ void Main::saveValues(bool webSend = true) {
//-----------------------------------------------------------------------------
void Main::updateCrc(void) {
uint16_t crc;
uint8_t buf[ADDR_NEXT-ADDR_START];
mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START));
crc = crc16(buf, (ADDR_NEXT-ADDR_START));
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
//Serial.println("new CRC: " + String(crc, HEX));
mEep->write(ADDR_SETTINGS_CRC, crc);
mEep->write(ADDR_WIFI_CRC, crc);
}

14
tools/esp8266/main.h

@ -40,8 +40,22 @@ class Main {
virtual void saveValues(bool webSend);
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 mStationPwd[PWD_LEN];
bool mWifiSettingsValid;
bool mSettingsValid;
bool mApActive;
ESP8266WebServer *mWeb;

Loading…
Cancel
Save