Версия для esp32

This commit is contained in:
Dmitry Borisenko
2020-12-30 13:48:29 +01:00
parent e0bb6d58e8
commit dad08c1686
8 changed files with 92 additions and 72 deletions

View File

@@ -2,11 +2,14 @@
//===========Firmware=============================================================================================================================================
#define FIRMWARE_VERSION 274
#define ESP8266_FLASH_SIZE_1MB true
#define ESP8266_FLASH_SIZE_1MB false
//===========FileSystem==============================================================================================================================================
#define USE_LITTLEFS false
#define USE_LITTLEFS true
//==================================================================================================================================================================
#define NUM_BUTTONS 6
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
#define LED_PIN LED_BUILTIN
//===========MQTT=================================================================================================================================================
#define MQTT_RECONNECT_INTERVAL 20000

View File

@@ -8,8 +8,16 @@
#include <FS.h>
#ifdef ESP32
#include <SPIFFS.h>
extern FS* filesystem;
#define FileFS SPIFFS
#define FS_NAME "SPIFFS"
#endif
#ifdef ESP8266
#if USE_LITTLEFS
#include <LittleFS.h>
#include "LittleFS.h"
extern FS LittleFS;
using littlefs_impl::LittleFSConfig;
extern FS* filesystem;
@@ -20,7 +28,9 @@ extern FS* filesystem;
#define FileFS SPIFFS
#define FS_NAME "SPIFFS"
#endif
#endif
extern void getFSInfo();
extern bool getInfo(FSInfo& info);
#ifdef ESP8266
extern bool getInfo(FSInfo& info);
#endif

View File

@@ -3,7 +3,14 @@
#ifdef uartEnable
#include "SoftwareSerial.h"
#ifdef ESP8266
#include <SoftwareSerial.h>
extern SoftwareSerial* myUART;
#else
#include <HardwareSerial.h>
extern HardwareSerial* myUART;
#endif
extern void uartInit();
extern void uartHandle();

View File

@@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = esp8266_01_1m
default_envs = esp32
[common_env_data]
lib_deps_external =
@@ -28,6 +28,7 @@ lib_deps_internal =
[env:esp32]
framework = arduino
board = esp32dev
;board_build.ldscript = eagle.flash.4m2m.ld
platform = https://github.com/platformio/platform-espressif32.git
lib_deps =
${common_env_data.lib_deps_external}
@@ -36,11 +37,12 @@ lib_deps =
madhephaestus/ESP32Servo
luc-github/ESP32SSDP
CTBot
EspSoftwareSerial
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200
board_build.filesystem = littlefs
extra_scripts = ./tools/littlefsbuilder.py
;board_build.filesystem = littlefs
;extra_scripts = ./tools/littlefsbuilder.py
[env:esp8266_01_1m]
framework = arduino

View File

@@ -1,21 +1,27 @@
#include "FileSystem.h"
#include "Global.h"
#ifdef ESP8266
bool getInfo(FSInfo& info) {
return FileFS.info(info);
}
// Информация о ФС
void getFSInfo() {
FSInfo buf;
if (getInfo(buf)) {
SerialPrint("I", F("FS"), F("Get FS info completed"));
size_t totalBytes = buf.totalBytes; // всего
size_t usedBytes = buf.usedBytes; // использовано
size_t maxOpenFiles = buf.maxOpenFiles; // лимит на открые файлы
size_t totalBytes = buf.totalBytes; // всего
size_t usedBytes = buf.usedBytes; // использовано
size_t maxOpenFiles = buf.maxOpenFiles; // лимит на открые файлы
size_t blockSize = buf.blockSize;
size_t pageSize = buf.pageSize;
size_t maxPathLength = buf.maxPathLength; // лимит на пути и имена файлов
size_t maxPathLength = buf.maxPathLength; // лимит на пути и имена файлов
size_t freeBytes = totalBytes - usedBytes;
float freePer = ((float) freeBytes / totalBytes) * 100;
float freePer = ((float)freeBytes / totalBytes) * 100;
jsonWriteStr(configSetupJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
//SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes));
@@ -26,12 +32,8 @@ void getFSInfo() {
//SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength));
//SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes));
//SerialPrint("I", F("FS"), "freePer=" + String(freePer));
}
else {
} else {
SerialPrint("E", F("FS"), F("FS info error"));
}
}
bool getInfo(FSInfo& info) {
return FileFS.info(info);
}
#endif

View File

@@ -1,11 +1,11 @@
#include "Utils/WiFiUtils.h"
#include "FileSystem.h"
void routerConnect() {
WiFi.setAutoConnect(false);
WiFi.persistent(false);
setLedStatus(LED_SLOW);
WiFi.mode(WIFI_STA);
byte tries = 20;
@@ -15,10 +15,13 @@ void routerConnect() {
if (_ssid == "" && _password == "") {
WiFi.begin();
}
else {
} else {
WiFi.begin(_ssid.c_str(), _password.c_str());
#ifdef ESP32
WiFi.setTxPower(WIFI_POWER_19_5dBm);
#else
WiFi.setOutputPower(20.5);
#endif
SerialPrint("I", "WIFI", "ssid: " + _ssid);
}
@@ -35,8 +38,7 @@ void routerConnect() {
if (WiFi.status() != WL_CONNECTED) {
Serial.println("");
startAPMode();
}
else {
} else {
Serial.println("");
SerialPrint("I", "WIFI", "http://" + WiFi.localIP().toString());
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
@@ -80,7 +82,6 @@ bool startAPMode() {
return true;
}
boolean RouterFind(String ssid) {
bool res = false;
int n = WiFi.scanComplete();
@@ -121,24 +122,19 @@ uint8_t RSSIquality() {
if (WiFi.status() == WL_CONNECTED) {
int rssi = WiFi.RSSI();
if (rssi >= -50) {
res = 6; //"Excellent";
res = 6; //"Excellent";
} else if (rssi < -50 && rssi >= -60) {
res = 5; //"Very good";
} else if (rssi < -60 && rssi >= -70) {
res = 4; //"Good";
} else if (rssi < -70 && rssi >= -80) {
res = 3; //"Low";
} else if (rssi < -80 && rssi > -100) {
res = 2; //"Very low";
} else if (rssi <= -100) {
res = 1; //"No signal";
}
else if (rssi < -50 && rssi >= -60) {
res = 5; //"Very good";
}
else if (rssi < -60 && rssi >= -70) {
res = 4; //"Good";
}
else if (rssi < -70 && rssi >= -80) {
res = 3; //"Low";
}
else if (rssi < -80 && rssi > -100) {
res = 2; //"Very low";
}
else if (rssi <= -100) {
res = 1; //"No signal";
}
}
}
return res;
}
@@ -146,33 +142,32 @@ void wifiSignalInit() {
ts.add(
SYGNAL, 1000 * 60, [&](void*) {
SerialPrint("I", "System", printMemoryStatus());
#ifdef ESP8266
getFSInfo();
#endif
switch (RSSIquality()) {
case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
break;
case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
break;
case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
break;
case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
break;
case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
break;
case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
break;
case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
break;
case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
break;
case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
break;
case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
break;
case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
break;
case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
break;
case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
break;
case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
break;
}
},
nullptr, true);
}

View File

@@ -31,8 +31,7 @@ void SensorAnalog::loop() {
void SensorAnalog::readAnalog() {
int value;
#ifdef ESP32
int pinInt = pin.toInt();
value = analogRead(pinInt);
value = analogRead(_adcPin);
#endif
#ifdef ESP8266
value = analogRead(A0);

View File

@@ -23,11 +23,11 @@
#include "items/vImpulsOut.h"
#include "items/vLogging.h"
#include "items/vSensorAnalog.h"
#include "items/vSensorBme280.h"
#include "items/vSensorBmp280.h"
#include "items/vSensorDallas.h"
#include "items/vSensorDht.h"
#include "items/vSensorUltrasonic.h"
#include "items/vSensorBme280.h"
#include "items/vSensorBmp280.h"
void not_async_actions();
@@ -71,7 +71,9 @@ void setup() {
#ifdef SSDP_ENABLED
SsdpInit();
#endif
#ifdef ESP8266
getFSInfo();
#endif
testsPerform();