mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
add Board esp32_wifirep
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
|
||||
<title>IoT Manager 4.6.0</title>
|
||||
<title>IoT Manager 4.6.2</title>
|
||||
|
||||
<link rel="icon" type="image/png" href="/favicon.ico" />
|
||||
<link rel="stylesheet" href="/build/bundle.css?4550" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
|
||||
<title>IoT Manager 4.6.0</title>
|
||||
<title>IoT Manager 4.6.2</title>
|
||||
|
||||
<link rel="icon" type="image/png" href="/favicon.ico" />
|
||||
<link rel="stylesheet" href="/build/bundle.css?4550" />
|
||||
|
||||
@@ -69,6 +69,9 @@
|
||||
#define FIRMWARE_NAME "esp32c6_8mb"
|
||||
#endif
|
||||
|
||||
#ifdef esp32_wifirep
|
||||
#define FIRMWARE_NAME "esp32_wifirep"
|
||||
#endif
|
||||
// Размер буфера json
|
||||
#define JSON_BUFFER_SIZE 4096 // держим 2 кб не меняем
|
||||
|
||||
@@ -109,7 +112,7 @@ WEB_SOCKETS_FRAME_SIZE создан для того что бы не загру
|
||||
//#define WIFI_ASYNC
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
#if defined(ESP32) && !defined(esp32_wifirep)
|
||||
#define WIFI_ASYNC
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "MqttClient.h"
|
||||
|
||||
void addPortMap(String TCP_UDP, String maddr, u16_t mport, String daddr, u16_t dport);
|
||||
|
||||
boolean isNetworkActive();
|
||||
uint8_t getNumAPClients();
|
||||
bool startAPMode();
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
"name": "IoTmanagerVer4",
|
||||
"apssid": "IoTmanager",
|
||||
"appass": "",
|
||||
"wifirep_apchanel": 7,
|
||||
"wifirep_apip": "192.168.4.1",
|
||||
"wifirep_staip": "192.168.1.160",
|
||||
"wifirep_netmask": "255.255.255.0",
|
||||
"wifirep_gateway": "192.168.4.1",
|
||||
"wifirep_dns": "192.168.4.1",
|
||||
"routerssid": "iot",
|
||||
"routerpass": "hostel3333",
|
||||
"timezone": 2,
|
||||
@@ -27,7 +33,7 @@
|
||||
"projectProp": {
|
||||
"platformio": {
|
||||
"default_envs": "esp32_4mb3f",
|
||||
"comments_default_envs": "choose from: esp8266_4mb, esp32_4mb, esp32_4mb3f, esp8266_16mb, esp32_16mb, esp32cam_4mb, esp32s2_4mb, esp32s3_16mb, esp32c3m_4mb, esp8266_1mb, esp8266_1mb_ota, esp8266_2mb, esp8266_2mb_ota, esp8285_1mb, esp8285_1mb_ota, esp32c6_4mb, esp32c6_8mb, bk7231n",
|
||||
"comments_default_envs": "choose from: esp8266_4mb, esp32_4mb, esp32_4mb3f, esp8266_16mb, esp32_16mb, esp32cam_4mb, esp32s2_4mb, esp32s3_16mb, esp32c3m_4mb, esp8266_1mb, esp8266_1mb_ota, esp8266_2mb, esp8266_2mb_ota, esp8285_1mb, esp8285_1mb_ota, esp32c6_4mb, esp32c6_8mb, bk7231n, esp32_wifirep",
|
||||
"envs": [
|
||||
{
|
||||
"name": "esp8266_4mb",
|
||||
@@ -55,6 +61,14 @@
|
||||
"partitions": "0x8000",
|
||||
"littlefs": "0x310000"
|
||||
},
|
||||
{
|
||||
"name": "esp32_wifirep",
|
||||
"boot_app0": "0xe000",
|
||||
"bootloader_qio_80m": "0x1000",
|
||||
"firmware": "0x10000",
|
||||
"partitions": "0x8000",
|
||||
"littlefs": "0x310000"
|
||||
},
|
||||
{
|
||||
"name": "esp32cam_4mb",
|
||||
"boot_app0": "0xe000",
|
||||
|
||||
@@ -375,6 +375,30 @@ build_src_filter =
|
||||
+<modules/*.cpp>
|
||||
${env:esp32_16mb_fromitems.build_src_filter}
|
||||
|
||||
[env:esp32_wifirep]
|
||||
lib_deps =
|
||||
${common_env_data.lib_deps_external}
|
||||
${env:esp32_wifirep_fromitems.lib_deps}
|
||||
lib_ignore = LT_WebSockets
|
||||
build_flags =
|
||||
-Desp32_wifirep="esp32_wifirep"
|
||||
-Wl,--wrap=esp_panic_handler
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.5.3/platform-espressif32-2.0.5.3.zip
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
debug_tool = esp-prog
|
||||
board_build.partitions = tools/partitions_custom.csv
|
||||
board_build.filesystem = littlefs
|
||||
build_src_filter =
|
||||
+<*.cpp>
|
||||
+<classes/*.cpp>
|
||||
+<utils/*.cpp>
|
||||
+<modules/*.cpp>
|
||||
${env:esp32_wifirep_fromitems.build_src_filter}
|
||||
|
||||
[env:esp32c6_4mb]
|
||||
extra_scripts = pre:tools/patch32c6.py
|
||||
lib_deps =
|
||||
@@ -894,6 +918,47 @@ build_src_filter =
|
||||
+<modules/virtual/VariableColor>
|
||||
+<modules/virtual/VButton>
|
||||
|
||||
[env:esp32_wifirep_fromitems]
|
||||
lib_deps =
|
||||
https://github.com/enjoyneering/AHTxx.git
|
||||
adafruit/Adafruit BME280 Library
|
||||
adafruit/Adafruit BMP280 Library
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||
plerup/EspSoftwareSerial
|
||||
gyverlibs/EncButton @ ^2.0
|
||||
build_src_filter =
|
||||
+<modules/virtual/Cron>
|
||||
+<modules/virtual/Loging>
|
||||
+<modules/virtual/LogingDaily>
|
||||
+<modules/virtual/LogingHourly>
|
||||
+<modules/virtual/Math>
|
||||
+<modules/virtual/owmWeather>
|
||||
+<modules/virtual/Ping>
|
||||
+<modules/virtual/Timer>
|
||||
+<modules/virtual/UpdateServer>
|
||||
+<modules/virtual/Variable>
|
||||
+<modules/virtual/VButton>
|
||||
+<modules/sensors/AhtXX>
|
||||
+<modules/sensors/AnalogAdc>
|
||||
+<modules/sensors/Bme280>
|
||||
+<modules/sensors/Bmp280>
|
||||
+<modules/sensors/Dht1122>
|
||||
+<modules/sensors/Ds18b20>
|
||||
+<modules/sensors/Impulse>
|
||||
+<modules/sensors/Ntc>
|
||||
+<modules/sensors/RTC>
|
||||
+<modules/sensors/UART>
|
||||
+<modules/exec/AnalogBtn>
|
||||
+<modules/exec/ButtonIn>
|
||||
+<modules/exec/ButtonOut>
|
||||
+<modules/exec/Buzzer>
|
||||
+<modules/exec/Enconder>
|
||||
+<modules/exec/Multitouch>
|
||||
+<modules/exec/Pwm32>
|
||||
+<modules/exec/TelegramLT>
|
||||
+<modules/exec/Thermostat>
|
||||
|
||||
[env:esp32c6_4mb_fromitems]
|
||||
lib_deps =
|
||||
https://github.com/enjoyneering/AHTxx.git
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "classes/IoTItem.h"
|
||||
#include "classes/IoTScenario.h"
|
||||
#include "utils/FileUtils.h"
|
||||
#include "utils/WiFiUtils.h"
|
||||
#include "NTP.h"
|
||||
|
||||
|
||||
@@ -343,7 +344,8 @@ enum SysOp {
|
||||
sysop_mqttPub,
|
||||
sysop_getUptime,
|
||||
sysop_mqttIsConnect,
|
||||
sysop_wifiIsConnect
|
||||
sysop_wifiIsConnect,
|
||||
sysop_addPortMap
|
||||
};
|
||||
|
||||
IoTValue sysExecute(SysOp command, std::vector<IoTValue> ¶m) {
|
||||
@@ -450,6 +452,11 @@ IoTValue sysExecute(SysOp command, std::vector<IoTValue> ¶m) {
|
||||
case sysop_wifiIsConnect:
|
||||
value.valD = isNetworkActive();
|
||||
break;
|
||||
case sysop_addPortMap:
|
||||
if (param.size() == 5) {
|
||||
addPortMap(param[0].valS, param[1].valS, param[2].valD, param[3].valS, param[4].valD);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -508,6 +515,8 @@ class SysCallExprAST : public ExprAST {
|
||||
operation = sysop_mqttIsConnect;
|
||||
else if (Callee == F("wifiIsConnect"))
|
||||
operation = sysop_wifiIsConnect;
|
||||
else if (Callee == F("addPortMap"))
|
||||
operation = sysop_addPortMap;
|
||||
else
|
||||
operation = sysop_notfound;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,39 @@
|
||||
#define TRIESONE 20 // количество секунд ожидания подключения к одной сети из несколких
|
||||
#define TRIES 30 // количество секунд ожидания подключения сети если она одна
|
||||
|
||||
#if defined(esp32_wifirep)
|
||||
#include "lwip/lwip_napt.h"
|
||||
// #include "lwip/ip_route.h"
|
||||
#define PROTO_TCP 6
|
||||
#define PROTO_UDP 17
|
||||
|
||||
IPAddress stringToIp(String strIp)
|
||||
{
|
||||
IPAddress ip;
|
||||
ip.fromString(strIp);
|
||||
return ip;
|
||||
}
|
||||
#endif
|
||||
void addPortMap(String TCP_UDP, String maddr, u16_t mport, String daddr, u16_t dport)
|
||||
{
|
||||
#if defined(esp32_wifirep)
|
||||
uint8_t tcp_udp;
|
||||
if (TCP_UDP == "TCP")
|
||||
tcp_udp = PROTO_TCP;
|
||||
else if (TCP_UDP == "UDP")
|
||||
tcp_udp = PROTO_UDP;
|
||||
else
|
||||
SerialPrint("E", "WIFI", "Add port map: ERROR, Must be 'TCP' or 'UDP'");
|
||||
|
||||
ip_portmap_add(tcp_udp, stringToIp(maddr), mport, stringToIp(daddr), dport);
|
||||
SerialPrint("i", "WIFI", "Add port map: " + String(tcp_udp) + ", " + maddr + ":" + String(mport) + " -> " + daddr + ":" + String(dport));
|
||||
#else
|
||||
SerialPrint("E", "WIFI", "Add port map: ERROR, change board to esp32_wifirep");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef WIFI_ASYNC
|
||||
std::vector<String> _ssidList;
|
||||
std::vector<String> _passwordList;
|
||||
@@ -286,10 +319,65 @@ void ScanAsync()
|
||||
WiFi.scanNetworks(true, false);
|
||||
}
|
||||
}
|
||||
#else
|
||||
// ESP8266
|
||||
#else //WIFI_ASYNC
|
||||
|
||||
void routerConnect()
|
||||
{
|
||||
#if defined(esp32_wifirep)
|
||||
// Set custom dns server address for dhcp server
|
||||
#define MY_DNS_IP_ADDR 0xC0A80401 // 192.168.4.1 // 0x08080808 // 8.8.8.8
|
||||
ip_addr_t dnsserver;
|
||||
|
||||
String _ssidAP = jsonReadStr(settingsFlashJson, "apssid");
|
||||
String _passwordAP = jsonReadStr(settingsFlashJson, "appass");
|
||||
int _chanelAP = 0;
|
||||
jsonRead(settingsFlashJson, "wifirep_apchanel", _chanelAP);
|
||||
if (_chanelAP == 0)
|
||||
_chanelAP = 7;
|
||||
|
||||
// WiFi.begin(ssid, password);
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
|
||||
String s_apip = "";
|
||||
bool ap_ip = jsonRead(settingsFlashJson, "wifirep_apip", s_apip);
|
||||
if (ap_ip && s_apip != "")
|
||||
{
|
||||
WiFi.softAPConfig(stringToIp(s_apip), stringToIp(s_apip), stringToIp("255.255.255.0"));
|
||||
// bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);
|
||||
dnsserver.u_addr.ip4.addr = stringToIp(s_apip);
|
||||
}
|
||||
else
|
||||
dnsserver.u_addr.ip4.addr = htonl(MY_DNS_IP_ADDR);
|
||||
|
||||
dnsserver.type = IPADDR_TYPE_V4;
|
||||
dhcps_dns_setserver(&dnsserver);
|
||||
|
||||
WiFi.softAP(_ssidAP.c_str(), _passwordAP.c_str(), _chanelAP, 0, 5);
|
||||
jsonWriteStr(settingsFlashJson, "ip", WiFi.softAPIP().toString());
|
||||
SerialPrint("i", "WIFI", "AP SSID: " + WiFi.softAPSSID());
|
||||
SerialPrint("i", "WIFI", "AP IP: " + WiFi.softAPIP().toString());
|
||||
SerialPrint("i", "WIFI", "AP pass: " + _passwordAP);
|
||||
|
||||
String s_staip = "";
|
||||
bool static_ip = jsonRead(settingsFlashJson, "wifirep_staip", s_staip);
|
||||
String s_gateway = jsonReadStr(settingsFlashJson, "wifirep_gateway");
|
||||
String s_netmask = jsonReadStr(settingsFlashJson, "wifirep_netmask");
|
||||
String s_dns = jsonReadStr(settingsFlashJson, "wifirep_dns");
|
||||
|
||||
if (static_ip == true && s_staip != "")
|
||||
{
|
||||
SerialPrint("i", "WIFI", "Use static IP");
|
||||
WiFi.config(stringToIp(s_staip), stringToIp(s_gateway), stringToIp(s_netmask), stringToIp(s_dns));
|
||||
// bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
|
||||
SerialPrint("i", "WIFI", "Static IP: " + s_staip);
|
||||
SerialPrint("i", "WIFI", "Gateway: " + s_gateway);
|
||||
SerialPrint("i", "WIFI", "Netmask: " + s_netmask);
|
||||
SerialPrint("i", "WIFI", "DNS: " + s_dns);
|
||||
}
|
||||
#else
|
||||
WiFi.mode(WIFI_STA);
|
||||
#endif
|
||||
|
||||
#if !defined LIBRETINY
|
||||
#if defined(esp32c6_4mb) || defined(esp32c6_8mb)
|
||||
WiFi.setAutoReconnect(false);
|
||||
@@ -309,7 +397,7 @@ void routerConnect()
|
||||
SerialPrint("i", "WIFI", "Gateway: " + s_gateway);
|
||||
SerialPrint("i", "WIFI", "Netmask: " + s_netmask);
|
||||
SerialPrint("i", "WIFI", "DNS: " + s_dns); */
|
||||
WiFi.mode(WIFI_STA);
|
||||
//WiFi.mode(WIFI_STA);
|
||||
byte triesOne = TRIESONE;
|
||||
|
||||
std::vector<String> _ssidList;
|
||||
@@ -396,6 +484,25 @@ void routerConnect()
|
||||
jsonWriteStr(settingsFlashJson, "ip", WiFi.localIP().toString());
|
||||
#endif
|
||||
createItemFromNet("onWifi", "1", 1);
|
||||
|
||||
#if defined(esp32_wifirep)
|
||||
// Enable DNS (offer) for dhcp server
|
||||
dhcps_offer_t dhcps_dns_value = OFFER_DNS;
|
||||
dhcps_set_option_info(6, &dhcps_dns_value, sizeof(dhcps_dns_value));
|
||||
u32_t napt_netif_ip;
|
||||
if (ap_ip && s_apip != "")
|
||||
napt_netif_ip = stringToIp(s_apip);
|
||||
else
|
||||
{
|
||||
napt_netif_ip = 0xC0A80401; // Set to ip address of softAP netif (Default is 192.168.4.1)
|
||||
napt_netif_ip = htonl(napt_netif_ip);
|
||||
}
|
||||
// get_esp_interface_netif(ESP_IF_WIFI_AP)
|
||||
ip_napt_enable(napt_netif_ip, 1);
|
||||
// ip_napt_enable_no(ESP_IF_WIFI_AP, 1);
|
||||
|
||||
#endif
|
||||
|
||||
mqttInit();
|
||||
}
|
||||
SerialPrint("i", F("WIFI"), F("Network Init"));
|
||||
|
||||
Reference in New Issue
Block a user