1
0
Fork 0
mirror of https://github.com/lumapu/ahoy.git synced 2025-06-14 16:41:38 +02:00

* renamed .ino (must be identical to parent folder name)

* build CRC over settings, only if the CRC matches settings are applied
* send command 0x80 (set time was wrong)
* improved crc16 routine
* added statistics for received commands and send statistics (channels are not correct for now!)
* receive of commands 0x01, 0x02, 0x03, 0x81 and 0x84 working
This commit is contained in:
lumapu 2022-04-20 08:58:23 +02:00
parent 5f927ad8c5
commit a7add69719
11 changed files with 226 additions and 123 deletions
tools/esp8266

View file

@ -4,6 +4,8 @@
#include "html/h/style_css.h"
#include "html/h/setup_html.h"
//-----------------------------------------------------------------------------
Main::Main(void) {
mDns = new DNSServer();
mWeb = new ESP8266WebServer(80);
@ -11,6 +13,7 @@ Main::Main(void) {
mUdp = new WiFiUDP();
mApActive = true;
mSettingsValid = false;
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
@ -22,6 +25,7 @@ Main::Main(void) {
mUptimeSecs = 0;
mUptimeTicker = new Ticker();
mUptimeTicker->attach(1, std::bind(&Main::uptimeTicker, this));
}
@ -70,19 +74,31 @@ void Main::loop(void) {
//-----------------------------------------------------------------------------
bool Main::getConfig(void) {
bool mApActive = false;
uint16_t crcRd, crcCheck;
uint8_t buf[ADDR_NEXT-ADDR_START];
mEep->read(ADDR_SSID, mStationSsid, SSID_LEN);
mEep->read(ADDR_PWD, mStationPwd, PWD_LEN);
mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
// 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);
if(mStationSsid[0] == 0xff) { // empty memory
if(crcCheck == crcRd)
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_PWD, mStationPwd, PWD_LEN);
mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
}
else {
mApActive = true;
memset(mStationSsid, 0, SSID_LEN);
}
if(mStationPwd[0] == 0xff)
memset(mStationPwd, 0, PWD_LEN);
if(mDeviceName[0] == 0xff)
memset(mDeviceName, 0, DEVNAME_LEN);
}
return mApActive;
}
@ -92,6 +108,8 @@ bool Main::getConfig(void) {
void Main::setupAp(const char *ssid, const char *pwd) {
IPAddress apIp(192, 168, 1, 1);
Serial.println("\n---------\nAP MODE\nSSDI: "+ String(ssid) + "\nPWD: " + String(pwd) + "\n---------\n");
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid, pwd);
@ -190,6 +208,7 @@ void Main::saveValues(bool webSend = true) {
mEep->write(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN);
updateCrc();
if(webSend) {
if(mWeb->arg("reboot") == "on")
showReboot();
@ -201,6 +220,18 @@ 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));
//Serial.println("new CRC: " + String(crc, HEX));
mEep->write(ADDR_SETTINGS_CRC, crc);
}
//-----------------------------------------------------------------------------
void Main::showUptime(void) {
char time[20] = {0};