mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Версия для esp32
This commit is contained in:
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
//===========Firmware=============================================================================================================================================
|
//===========Firmware=============================================================================================================================================
|
||||||
#define FIRMWARE_VERSION 274
|
#define FIRMWARE_VERSION 274
|
||||||
#define ESP8266_FLASH_SIZE_1MB true
|
#define ESP8266_FLASH_SIZE_1MB false
|
||||||
//===========FileSystem==============================================================================================================================================
|
//===========FileSystem==============================================================================================================================================
|
||||||
#define USE_LITTLEFS false
|
#define USE_LITTLEFS true
|
||||||
//==================================================================================================================================================================
|
//==================================================================================================================================================================
|
||||||
#define NUM_BUTTONS 6
|
#define NUM_BUTTONS 6
|
||||||
|
#ifndef LED_BUILTIN
|
||||||
|
#define LED_BUILTIN 2
|
||||||
|
#endif
|
||||||
#define LED_PIN LED_BUILTIN
|
#define LED_PIN LED_BUILTIN
|
||||||
//===========MQTT=================================================================================================================================================
|
//===========MQTT=================================================================================================================================================
|
||||||
#define MQTT_RECONNECT_INTERVAL 20000
|
#define MQTT_RECONNECT_INTERVAL 20000
|
||||||
|
|||||||
@@ -8,8 +8,16 @@
|
|||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <SPIFFS.h>
|
||||||
|
extern FS* filesystem;
|
||||||
|
#define FileFS SPIFFS
|
||||||
|
#define FS_NAME "SPIFFS"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
#if USE_LITTLEFS
|
#if USE_LITTLEFS
|
||||||
#include <LittleFS.h>
|
#include "LittleFS.h"
|
||||||
extern FS LittleFS;
|
extern FS LittleFS;
|
||||||
using littlefs_impl::LittleFSConfig;
|
using littlefs_impl::LittleFSConfig;
|
||||||
extern FS* filesystem;
|
extern FS* filesystem;
|
||||||
@@ -20,7 +28,9 @@ extern FS* filesystem;
|
|||||||
#define FileFS SPIFFS
|
#define FileFS SPIFFS
|
||||||
#define FS_NAME "SPIFFS"
|
#define FS_NAME "SPIFFS"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void getFSInfo();
|
extern void getFSInfo();
|
||||||
extern bool getInfo(FSInfo& info);
|
#ifdef ESP8266
|
||||||
|
extern bool getInfo(FSInfo& info);
|
||||||
|
#endif
|
||||||
@@ -3,7 +3,14 @@
|
|||||||
#ifdef uartEnable
|
#ifdef uartEnable
|
||||||
#include "SoftwareSerial.h"
|
#include "SoftwareSerial.h"
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
extern SoftwareSerial* myUART;
|
extern SoftwareSerial* myUART;
|
||||||
|
#else
|
||||||
|
#include <HardwareSerial.h>
|
||||||
|
extern HardwareSerial* myUART;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern void uartInit();
|
extern void uartInit();
|
||||||
extern void uartHandle();
|
extern void uartHandle();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp8266_01_1m
|
default_envs = esp32
|
||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
lib_deps_external =
|
lib_deps_external =
|
||||||
@@ -28,6 +28,7 @@ lib_deps_internal =
|
|||||||
[env:esp32]
|
[env:esp32]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
|
;board_build.ldscript = eagle.flash.4m2m.ld
|
||||||
platform = https://github.com/platformio/platform-espressif32.git
|
platform = https://github.com/platformio/platform-espressif32.git
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
@@ -36,11 +37,12 @@ lib_deps =
|
|||||||
madhephaestus/ESP32Servo
|
madhephaestus/ESP32Servo
|
||||||
luc-github/ESP32SSDP
|
luc-github/ESP32SSDP
|
||||||
CTBot
|
CTBot
|
||||||
|
EspSoftwareSerial
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
board_build.filesystem = littlefs
|
;board_build.filesystem = littlefs
|
||||||
extra_scripts = ./tools/littlefsbuilder.py
|
;extra_scripts = ./tools/littlefsbuilder.py
|
||||||
|
|
||||||
[env:esp8266_01_1m]
|
[env:esp8266_01_1m]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#ifdef ESP8266
|
||||||
|
bool getInfo(FSInfo& info) {
|
||||||
|
return FileFS.info(info);
|
||||||
|
}
|
||||||
|
|
||||||
// Информация о ФС
|
// Информация о ФС
|
||||||
void getFSInfo() {
|
void getFSInfo() {
|
||||||
FSInfo buf;
|
FSInfo buf;
|
||||||
if (getInfo(buf)) {
|
if (getInfo(buf)) {
|
||||||
SerialPrint("I", F("FS"), F("Get FS info completed"));
|
SerialPrint("I", F("FS"), F("Get FS info completed"));
|
||||||
|
|
||||||
size_t totalBytes = buf.totalBytes; // всего
|
size_t totalBytes = buf.totalBytes; // всего
|
||||||
size_t usedBytes = buf.usedBytes; // использовано
|
size_t usedBytes = buf.usedBytes; // использовано
|
||||||
size_t maxOpenFiles = buf.maxOpenFiles; // лимит на открые файлы
|
size_t maxOpenFiles = buf.maxOpenFiles; // лимит на открые файлы
|
||||||
size_t blockSize = buf.blockSize;
|
size_t blockSize = buf.blockSize;
|
||||||
size_t pageSize = buf.pageSize;
|
size_t pageSize = buf.pageSize;
|
||||||
size_t maxPathLength = buf.maxPathLength; // лимит на пути и имена файлов
|
size_t maxPathLength = buf.maxPathLength; // лимит на пути и имена файлов
|
||||||
|
|
||||||
size_t freeBytes = totalBytes - usedBytes;
|
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) + ")");
|
jsonWriteStr(configSetupJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
|
||||||
|
|
||||||
//SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes));
|
//SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes));
|
||||||
@@ -26,12 +32,8 @@ void getFSInfo() {
|
|||||||
//SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength));
|
//SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength));
|
||||||
//SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes));
|
//SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes));
|
||||||
//SerialPrint("I", F("FS"), "freePer=" + String(freePer));
|
//SerialPrint("I", F("FS"), "freePer=" + String(freePer));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
SerialPrint("E", F("FS"), F("FS info error"));
|
SerialPrint("E", F("FS"), F("FS info error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
bool getInfo(FSInfo& info) {
|
|
||||||
return FileFS.info(info);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "Utils/WiFiUtils.h"
|
#include "Utils/WiFiUtils.h"
|
||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
void routerConnect() {
|
void routerConnect() {
|
||||||
|
|
||||||
WiFi.setAutoConnect(false);
|
WiFi.setAutoConnect(false);
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
setLedStatus(LED_SLOW);
|
setLedStatus(LED_SLOW);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
byte tries = 20;
|
byte tries = 20;
|
||||||
@@ -15,10 +15,13 @@ void routerConnect() {
|
|||||||
|
|
||||||
if (_ssid == "" && _password == "") {
|
if (_ssid == "" && _password == "") {
|
||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
WiFi.begin(_ssid.c_str(), _password.c_str());
|
WiFi.begin(_ssid.c_str(), _password.c_str());
|
||||||
|
#ifdef ESP32
|
||||||
|
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
||||||
|
#else
|
||||||
WiFi.setOutputPower(20.5);
|
WiFi.setOutputPower(20.5);
|
||||||
|
#endif
|
||||||
SerialPrint("I", "WIFI", "ssid: " + _ssid);
|
SerialPrint("I", "WIFI", "ssid: " + _ssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +38,7 @@ void routerConnect() {
|
|||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
startAPMode();
|
startAPMode();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
SerialPrint("I", "WIFI", "http://" + WiFi.localIP().toString());
|
SerialPrint("I", "WIFI", "http://" + WiFi.localIP().toString());
|
||||||
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
|
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
|
||||||
@@ -80,7 +82,6 @@ bool startAPMode() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean RouterFind(String ssid) {
|
boolean RouterFind(String ssid) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
int n = WiFi.scanComplete();
|
int n = WiFi.scanComplete();
|
||||||
@@ -121,24 +122,19 @@ uint8_t RSSIquality() {
|
|||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
int rssi = WiFi.RSSI();
|
int rssi = WiFi.RSSI();
|
||||||
if (rssi >= -50) {
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,33 +142,32 @@ void wifiSignalInit() {
|
|||||||
ts.add(
|
ts.add(
|
||||||
SYGNAL, 1000 * 60, [&](void*) {
|
SYGNAL, 1000 * 60, [&](void*) {
|
||||||
SerialPrint("I", "System", printMemoryStatus());
|
SerialPrint("I", "System", printMemoryStatus());
|
||||||
|
#ifdef ESP8266
|
||||||
getFSInfo();
|
getFSInfo();
|
||||||
|
#endif
|
||||||
switch (RSSIquality()) {
|
switch (RSSIquality()) {
|
||||||
case 0:
|
case 0:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
|
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ void SensorAnalog::loop() {
|
|||||||
void SensorAnalog::readAnalog() {
|
void SensorAnalog::readAnalog() {
|
||||||
int value;
|
int value;
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
int pinInt = pin.toInt();
|
value = analogRead(_adcPin);
|
||||||
value = analogRead(pinInt);
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
value = analogRead(A0);
|
value = analogRead(A0);
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
#include "items/vSensorAnalog.h"
|
#include "items/vSensorAnalog.h"
|
||||||
|
#include "items/vSensorBme280.h"
|
||||||
|
#include "items/vSensorBmp280.h"
|
||||||
#include "items/vSensorDallas.h"
|
#include "items/vSensorDallas.h"
|
||||||
#include "items/vSensorDht.h"
|
#include "items/vSensorDht.h"
|
||||||
#include "items/vSensorUltrasonic.h"
|
#include "items/vSensorUltrasonic.h"
|
||||||
#include "items/vSensorBme280.h"
|
|
||||||
#include "items/vSensorBmp280.h"
|
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -71,7 +71,9 @@ void setup() {
|
|||||||
#ifdef SSDP_ENABLED
|
#ifdef SSDP_ENABLED
|
||||||
SsdpInit();
|
SsdpInit();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ESP8266
|
||||||
getFSInfo();
|
getFSInfo();
|
||||||
|
#endif
|
||||||
|
|
||||||
testsPerform();
|
testsPerform();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user