Skip to content

Commit

Permalink
更新版本
Browse files Browse the repository at this point in the history
  • Loading branch information
qlwz committed Jul 10, 2020
1 parent f11e2c5 commit bea1364
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/DC1.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DC1 : public Module
void init();
String getModuleName() { return F("dc1"); }
String getModuleCNName() { return F("DC1插线板"); }
String getModuleVersion() { return F("2020.02.19.1500"); }
String getModuleVersion() { return F("2020.07.10.2300"); }
String getModuleAuthor() { return F("情留メ蚊子"); }
bool moduleLed();

Expand Down
6 changes: 5 additions & 1 deletion lib/esp_framework/include/Wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "Arduino.h"

//#define ConnectTimeOut 300
#ifndef ConfigPortalTimeOut
#define ConfigPortalTimeOut 120
#endif
#define MinimumWifiSignalQuality 8

class Wifi
Expand All @@ -20,7 +22,9 @@ class Wifi
static String _pass;

static DNSServer *dnsServer;
//static unsigned long connectStart;
#ifdef ConnectTimeOut
static unsigned long connectStart;
#endif

public:
static unsigned long configPortalStart;
Expand Down
21 changes: 16 additions & 5 deletions lib/esp_framework/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ bool Config::saveConfig(bool isEverySecond)
}
}

uint8_t *data = (uint8_t *)malloc(len + 6);
if (spi_flash_erase_sector(EEPROM_PHYS_ADDR / SPI_FLASH_SEC_SIZE) != SPI_FLASH_RESULT_OK)
// 读取原来数据
uint8_t *data = (uint8_t *)malloc(SPI_FLASH_SEC_SIZE);
if (spi_flash_read(EEPROM_PHYS_ADDR, (uint32 *)data, SPI_FLASH_SEC_SIZE) != SPI_FLASH_RESULT_OK)
{
free(data);
Debug::AddError(PSTR("saveConfig . . . Erase Sector Error"));
Debug::AddError(PSTR("saveConfig . . . Read EEPROM Data Error"));
return false;
}

// 拷贝数据
data[0] = GLOBAL_CFG_VERSION >> 8;
data[1] = GLOBAL_CFG_VERSION;

Expand All @@ -184,10 +186,19 @@ bool Config::saveConfig(bool isEverySecond)

memcpy(&data[6], buffer, len);

if (spi_flash_write(EEPROM_PHYS_ADDR, (uint32 *)data, len + 6) != SPI_FLASH_RESULT_OK)
// 擦写扇区
if (spi_flash_erase_sector(EEPROM_PHYS_ADDR / SPI_FLASH_SEC_SIZE) != SPI_FLASH_RESULT_OK)
{
free(data);
Debug::AddError(PSTR("saveConfig . . . Erase Sector Error"));
return false;
}

// 写入数据
if (spi_flash_write(EEPROM_PHYS_ADDR, (uint32 *)data, SPI_FLASH_SEC_SIZE) != SPI_FLASH_RESULT_OK)
{
free(data);
Debug::AddError(PSTR("saveConfig . . . Write Data Error"));
Debug::AddError(PSTR("saveConfig . . . Write EEPROM Data Error"));
return false;
}
free(data);
Expand Down
16 changes: 11 additions & 5 deletions lib/esp_framework/src/Wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ WiFiEventHandler Wifi::STAGotIP;
bool Wifi::isDHCP = true;

unsigned long Wifi::configPortalStart = 0;
//unsigned long Wifi::connectStart = 0;
#ifdef ConnectTimeOut
unsigned long Wifi::connectStart = 0;
#endif
bool Wifi::connect = false;
String Wifi::_ssid = "";
String Wifi::_pass = "";
Expand Down Expand Up @@ -41,7 +43,9 @@ void Wifi::setupWifi()
WiFi.hostname(UID);
Debug::AddInfo(PSTR("Connecting to %s %s Wifi"), globalConfig.wifi.ssid, globalConfig.wifi.pass);
STAGotIP = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP &event) {
//connectStart = 0;
#ifdef ConnectTimeOut
connectStart = 0;
#endif
Debug::AddInfo(PSTR("WiFi1 connected. SSID: %s IP address: %s"), WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
if (globalConfig.wifi.is_static && String(globalConfig.wifi.ip).equals(WiFi.localIP().toString()))
{
Expand Down Expand Up @@ -71,7 +75,9 @@ void Wifi::setupWifi()
WiFi.config(static_ip, static_gw, static_sn);
}

//connectStart = millis();
#ifdef ConnectTimeOut
connectStart = millis();
#endif
WiFi.begin(globalConfig.wifi.ssid, globalConfig.wifi.pass);
}

Expand Down Expand Up @@ -127,7 +133,7 @@ void Wifi::tryConnect(String ssid, String pass)

void Wifi::loop()
{
/*
#ifdef ConnectTimeOut
if (connectStart > 0 && millis() > connectStart + (ConnectTimeOut * 1000))
{
connectStart = 0;
Expand All @@ -137,7 +143,7 @@ void Wifi::loop()
return;
}
}
*/
#endif
if (configPortalStart == 0)
{
return;
Expand Down
8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ board_build.flash_mode = dout
board_build.ldscript = eagle.flash.1m.ld

; *** Esp8266 core for Arduino version 2.6.1
platform = espressif8266@2.3.3
platform = espressif8266@2.4.0
build_flags = -D NDEBUG
-mtarget-align
-Wl,-Map,firmware.map
Expand All @@ -42,7 +42,7 @@ build_flags = -D NDEBUG
build_unflags = -Wall

monitor_speed = 115200
upload_speed = 460800
upload_speed = 921600
; *** Upload Serial reset method for Wemos and NodeMCU
upload_resetmethod = nodemcu
;upload_port = COM5
Expand All @@ -54,5 +54,5 @@ lib_deps =
Nanopb=https://github.com/nanopb/nanopb.git#nanopb-0.3.9.5

[env:dc1]
lib_deps = ${env.lib_deps}
EspSoftwareSerial@5.0.4
lib_deps = ${env.lib_deps}
EspSoftwareSerial=https://github.com/plerup/espsoftwareserial.git#5.0.4
10 changes: 10 additions & 0 deletions src/DC1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "DC1.h"
#include "Rtc.h"
#include "Util.h"
#ifdef USE_HOMEKIT
#include "HomeKit.h"
#endif

#pragma region 继承

Expand Down Expand Up @@ -259,6 +262,9 @@ void DC1::httpAdd(ESP8266WebServer *server)
server->on(F("/dc1_do"), std::bind(&DC1::httpDo, this, server));
server->on(F("/dc1_setting"), std::bind(&DC1::httpSetting, this, server));
server->on(F("/ha"), std::bind(&DC1::httpHa, this, server));
#ifdef USE_HOMEKIT
server->on(F("/homekit"), std::bind(&homekit_http, server));
#endif
}

String DC1::httpGetStatus(ESP8266WebServer *server)
Expand Down Expand Up @@ -358,6 +364,10 @@ void DC1::httpHtml(ESP8266WebServer *server)
"<button type='button' class='btn-danger' style='margin-top:10px' onclick=\"javascript:if(confirm('确定要重置用电量?')){ajaxPost('/dc1_setting', 'c=1');}\">重置用电量</button></td></tr>"
"</tbody></table></form>"));

#ifdef USE_HOMEKIT
homekit_html(server);
#endif

server->sendContent_P(
PSTR("<script type='text/javascript'>"
"function setDataSub(data,key){if(key.substr(0,5)=='power' && key.length==6){var t=id(key);var v=data[key];t.setAttribute('class',v==1?'btn-success':'btn-info');t.innerHTML=v==1?'开':'关';return true}return false}"));
Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@
#include "Framework.h"
#include "DC1.h"

#ifdef USE_HOMEKIT
#include "homekit.h"
#endif

void setup()
{
Framework::one(115200);

module = new DC1();

Framework::setup();

#ifdef USE_HOMEKIT
homekit_init();
#endif
}

void loop()
{
#ifdef USE_HOMEKIT
homekit_loop();
#else
Framework::loop();
#endif
}

0 comments on commit bea1364

Please sign in to comment.