Название говорит само за себя, но я постараюсь объяснить проблему здесь, чтобы быть более точным. Мой код работает на ESP8266-01, подключенном к вентилятору, и используется для управления им через Telegram (со своим собственным ботом) и Adafruit MQTT, от которых он получает команду (не одновременно, просто чтобы иметь несколько способы управления вентилятором на случай, если у меня нет телефона с собой).
В любом случае, здесь возникают проблемы: через неопределенное время (может быть 5 минут, а также это может быть более 4 часов, как это было, когда я тестировал его на Serial), ESP01 перезагружается, вызывая это исключение
Exception (28):
epc1=0x40222dc2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x040c102c depc=0x00000000
>>>stack>>>
ctx: bearssl
sp: 3fff1008 end: 3fff1478 offset: 0190
3fff1198: 0000000a 3fff8900 000009e6 4022270d
3fff11a8: f0ccf003 3cc30f3c 0f3cff03 03c3330f
3fff11b8: f0fc33c2 03c0330f 3c0c300c c000300c
3fff11c8: cfc3cfff f33ffc0c fc0c3300 ffc00ffc
3fff11d8: cf330f3f ffc00f03 0cfc0f03 c0ff0ffc
3fff11e8: c3c03ccc cff3ccfc ccfcf000 cc3ffccc
3fff11f8: c3f0fc0c 333ffcff 033303ff 3fcc03cc
3fff1208: 3fc0f33c 3ccfc3cc c3cccfff 3cf333c3
3fff1218: 3fcf3303 0f0ccccc ff0fffcc 0c3c00c3
3fff1228: f3c0300c f3c33f3c 3f3cc3cc 0c30f0c0
3fff1238: 0cc3f0ff fcfcc33c 3303ccc3 03f3003f
3fff1248: cf3ff003 cf3ff3f3 f30cc03c 03f0cfc0
3fff1258: fc3fcfcc 33cc3ff3 f0ffc33f ffcffff3
3fff1268: c3f3cf00 c3f33030 cf03c0f3 ff30c3c0
3fff1278: 33f3c3c3 f03c0c30 cfcc3f0c ccc333cf
3fff1288: c0303cff 3fcf0f0f c300c030 33f0c03f
3fff1298: 057eb259 f0f6483c 0bb168c6 8e042ad6
3fff12a8: ef0e748c fb4720fa 610a5e5a 7ef262ea
3fff12b8: e4bf1c4a 9a4d7ea0 ae0d41a4 7640345a
3fff12c8: 68451f77 1d707387 9195f4c3 15642cab
3fff12d8: 3c0fdaf5 16b9dbff 0000ef82 00000000
3fff12e8: 00000000 00000000 00000000 00000030
3fff12f8: 4010372b 00040000 00000000 00040000
3fff1308: 53000000 40103728 00040000 3a2a3de0
3fff1318: 3ffed480 4010268f 8c352dcf 11402259
3fff1328: a89def83 53c2e59f 04f73e23 7d24a14f
3fff1338: 61289e0b 2c9f0300 4000050c 3fffc278
3fff1348: 401024e0 3fffc200 00000022 7d24a14f
3fff1358: 4022117c 00000030 00000008 ffffffff
3fff1368: 402068dc 3fff1d04 00000303 00000003
3fff1378: 3fff1d09 0000006c 000006b4 00000003
3fff1388: 00000000 3fffc6fc 00000001 3fff7e1c
3fff1398: 00000000 00003a98 3ffeefd4 00000030
3fff13a8: 0004f73e 3fff7e6c 008c352d 10000000
3fff13b8: 00000000 02000000 00030315 00000002
3fff13c8: 3fff1418 40257303 3fff7e5c 40223cc9
3fff13d8: 3fff8620 3fff86a4 b6cb9a6a 3fff8600
3fff13e8: 3fff1d11 3fff7e1c 3fff8620 00000000
3fff13f8: deadbeef 0000000a 3fff7e00 3fff1d09
3fff1408: 3fff1458 00000002 3fff1d11 3fff881c
3fff1418: 3fff891c 00000000 3fff7e1c 40220dbc
3fff1428: 3fff8600 000001d2 deadbeef deadbeef
3fff1438: 00000250 00000005 deadbeef 3ffeefd4
3fff1448: 00003a98 0000002e 3fff7e1c 402212a1
3fff1458: 000000dd deadbeef deadbeef 40221090
3fff1468: deadbeef 00000000 3ffeee30 402068dc
ctx: cont
sp: 3ffffe30 end: 3fffffc0 offset: 0000
3ffffe30: 00003a98 00000000 00000010 402062ce
3ffffe40: 00000200 3ffeee30 3fff1694 402052dc
3ffffe50: 00000000 00e41e9f 00000000 3ffffef0
3ffffe60: 000001bb 3ffeee30 3ffe8ab0 3ffffef0
3ffffe70: 3ffe8d96 00000000 3ffeee30 4020647d
3ffffe80: 4020b810 3fffff00 3ffeee30 40205992
3ffffe90: 3ffe8d96 3fffff00 3ffeed7c 40201e5b
3ffffea0: 3fffff0c 00000053 3ffffef0 40208840
3ffffeb0: 3fff7ca4 3fffff18 3ffffef0 40208a24
3ffffec0: 3fffff0c 3fffff0c 3ffffef0 40208a54
3ffffed0: 3fffff18 3ffffef0 3ffeed7c 3ffef028
3ffffee0: 3fffff0c 3fffff0c 3ffeed7c 40203bb5
3ffffef0: 3fff73b4 0053005f 001cac08 00000003
3fffff00: 39313700 33383838 80c6a700 3fff7300
3fffff10: 0053005f 80000000 3fff7ca4 0053005f
3fffff20: 00000000 3ffeec80 3ffeec80 402053b4
3fffff30: 241b8b42 3ffeec80 3ffeec80 4020b20c
3fffff40: 3ffeef3c 3ffeec80 3ffeec80 3ffef028
3fffff50: 3ffeef3c 00000000 3ffeed7c 4020188c
3fffff60: 007a1200 23030291 3ffeef00 40208240
3fffff70: 00000000 3ffeef68 3ffeefa0 402082b4
3fffff80: 00000000 00000000 00000001 40100154
3fffff90: 3fffdad0 00000000 3ffeefe8 3ffef028
3fffffa0: 3fffdad0 00000000 3ffeefe8 4020906c
3fffffb0: feefeffe feefeffe 3ffe8548 40100bed
<<<stack<<<
, которое появляется после декодирования с помощью ESP8266 Exception Decoder:
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x40222dc2: br_ssl_hs_client_run at src/ssl/ssl_hs_client.c line 1805
EXCVADDR: 0x040c102c
Decoding stack results
0x4022270d: br_ssl_hs_client_run at src/ssl/ssl_hs_client.c line 1379
0x4022117c: br_ssl_engine_set_buffers_bidi at src/ssl/ssl_engine.c line 449
0x402068dc: BearSSL::WiFiClientSecure::_connectSSL(char const*) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 1098
0x40223cc9: gen_chapol_process at src/ssl/ssl_rec_chapol.c line 54
0x40220dbc: cc_do_sign at src/ssl/ssl_ccert_single_rsa.c line 131
0x402212a1: br_ssl_engine_flush_record at src/ssl/ssl_engine.c line 1108
0x40221090: rng_init at src/ssl/ssl_engine.c line 470
0x402068dc: BearSSL::WiFiClientSecure::_connectSSL(char const*) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 1098
0x402062ce: BearSSL::WiFiClientSecure::WiFiClientSecure() at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 107
0x402052dc: WiFiClient::write_P(char const*, unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src/include/DataSource.h line 135
0x4020647d: BearSSL::WiFiClientSecure::_run_until(unsigned int, bool) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266/PolledTimeout.h line 66
0x40205992: BearSSL::br_ssl_client_base_init(br_ssl_client_context*, uint16_t const*, int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 948
0x40208840: Stream::readBytes(char*, unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266\Stream.cpp line 222
0x40208a24: String::changeBuffer(unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266\WString.cpp line 200
0x40208a54: String::reserve(unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266\WString.cpp line 144
0x40203bb5: UniversalTelegramBot::processResult(ArduinoJson::JsonObject&, int) at C:\Users\window\Documents\Arduino\libraries\UniversalTelegramBot\src\UniversalTelegramBot.cpp line 467
0x402053b4: WiFiClient::read(unsigned char*, unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\WiFiClient.cpp line 278
0x4020b20c: BearSSL::PublicKey::getEC() const at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\libraries\ESP8266WiFi\src\BearSSLHelpers.cpp line 695
0x4020188c: checkUpdates(int) at H:\Programming\Arduino\Fan_remote_control\Versions\V 2.0\Fan_remote_control/Fan_remote_control.ino line 119
0x40208240: HardwareSerial::readBytes(char*, unsigned int) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266/PolledTimeout.h line 186
0x402082b4: _GLOBAL__sub_D__ZN14HardwareSerialC2Ei() at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266/HardwareSerial.h line 72
0x40100154: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\window\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.2\cores\esp8266\core_esp8266_main.cpp line 177
Я подозреваю, что проблема может быть вызвана подключением к двум различным типам клиентов Wi-Fi, хотя Telegram или Adafruit MQTT не будут работать, если они оба не используются (насколько я могу судить по моим тестам ). Мы будем очень благодарны за любую помощь или предложение, не стесняйтесь спрашивать дополнительную информацию, если это необходимо.
Код здесь (конфиденциальная информация заменена словом «частный»):
#include "UniversalTelegramBot.h"
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_Client.h>
#define BOTtoken "private"
#define ledPin 2
#define myChatId "private"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "private"
#define AIO_KEY "private"
char ssid[] = "private";
char password[] = "private";
bool fanState;
unsigned long lastTimeBotRan = 0;
unsigned long checkTime = 1000;
int numNewMessages;
unsigned long timerStartPoint = 0;
bool timerStart;
String chat_id;
String text;
int messagesNumber;
String timerString;
String Request;
const unsigned long rst = 300000;
boolean MQTT_connect();
WiFiClientSecure secureClient;
WiFiClient client;
UniversalTelegramBot bot(BOTtoken, secureClient);
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
Adafruit_MQTT_Subscribe private = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/private");
void checkUpdates(int numNewMessages) {
for (int i = 0; i < numNewMessages; i++) {
chat_id = String(bot.messages[i].chat_id);
text = bot.messages[i].text;
String from_name = bot.messages[i].from_name;
if (chat_id != myChatId) {
bot.sendMessage(chat_id, "Unauthorized user, please refrain from texting this bot again.", "");
continue;
}
if (text == "/start") {
String welcome = "Welcome " + from_name + "!\n";
welcome += "Control your fan remotely!\n\n";
welcome += "/fanon : to switch the fan ON\n";
welcome += "/fanoff : to switch the fan OFF\n";
welcome += "/state : returns current state of the fan\n";
welcome += "/timer15 : runs fan for 15 minutes\n";
welcome += "/timer30 : runs fan for 30 minutes\n";
welcome += "/timer60 : runs fan for 1 hour\n";
welcome += "/timer : runs fan for specified amount of time\n";
bot.sendMessage(chat_id, welcome, "Markdown");
}
if (text == "/fanon") {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
fanState = true;
bot.sendMessage(chat_id, "Your fan is ON", "");
}
if (text == "/fanoff") {
fanState = false;
timerStart = false;
digitalWrite(ledPin, LOW); // turn the LED off (LOW is the voltage level)
bot.sendMessage(chat_id, "Your fan is OFF", "");
}
if (text == "/state") {
if (fanState) {
bot.sendMessage(chat_id, "Your fan is ON", "");
} else {
bot.sendMessage(chat_id, "Your fan is OFF", "");
}
}
if (text == "/timer15") {
timerStartPoint = millis();
digitalWrite(ledPin, HIGH);
timerStart = true;
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(chat_id, "Your fan will run for 15 minutes", "");
launchTimer(15);
}
if (text == "/timer30") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(chat_id, "Your fan will run for 30 minutes", "");
launchTimer(30);
}
if (text == "/timer60") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(chat_id, "Your fan will run for 1 hour", "");
launchTimer(60);
}
if (text == "/timer") {
messagesNumber = bot.last_message_received + 1;
bot.sendMessage(chat_id, "How long do you want the fan to run for? (in minutes)", "");
Serial.println(messagesNumber);
while (messagesNumber == (bot.last_message_received + 1)) {
checkUpdates(bot.getUpdates(bot.last_message_received + 1));
timerString = bot.messages[i].text;
yield();
}
if (messagesNumber < (bot.last_message_received + 1)) {
unsigned long timer = timerString.toInt();
Serial.println(timer);
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(chat_id, "Your fan will run for " + timerString + " minutes", "");
launchTimer(timer);
}
}
text = "";
}
}
void launchTimer(unsigned long timeInMinutes) {
unsigned long timeInMillis = timeInMinutes * 60 * 1000;
while (timerStart) {
checkUpdates(bot.getUpdates(bot.last_message_received + 1));
if (MQTT_connect()) {
Adafruit_MQTT_Subscribe *subscription_name;
while ((subscription_name = mqtt.readSubscription(4000))) {
if (subscription_name == &private) {
Request = ((char *)private.lastread);
if (Request == "fanon") {
digitalWrite(ledPin, HIGH);
fanState = true;
bot.sendMessage(myChatId, "Fan turned on through Control Panel", "");
}
if (Request == "fanoff") {
fanState = false;
timerStart = false;
digitalWrite(ledPin, LOW);
bot.sendMessage(myChatId, "Fan turned off through Control Panel", "");
}
if (Request == "timer15") {
timerStartPoint = millis();
digitalWrite(ledPin, HIGH);
timerStart = true;
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 15 minutes through Control Panel", "");
launchTimer(15);
}
if (Request == "timer30") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 30 minutes through Control Panel", "");
launchTimer(30);
}
if (Request == "timer60") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 1 hour through Control Panel", "");
launchTimer(60);
}
}
}
}
if (millis() - timerStartPoint > timeInMillis) {
digitalWrite(ledPin, LOW);
timerStart = false;
Serial.print("Fan off at ");
Serial.println(millis());
bot.sendMessage(myChatId, "Fan turned off because timer ran out", "");
}
yield();
}
}
boolean MQTT_connect() {
int8_t ret;
if (mqtt.connected()) {
return true;
} uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) {
mqtt.disconnect();
delay(2000);
retries--;
if (retries == 0) {
return false;
}
} return true;
}
void setup() {
Serial.begin(115200);
secureClient.setInsecure();
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
pinMode(ledPin, OUTPUT);
delay(10);
digitalWrite(ledPin, LOW);
Request = "";
mqtt.subscribe(&private);
if (MQTT_connect()) {
Serial.println("mqtt connected");
}
else {
Serial.println("mqtt connection failed");
}
}
void loop() {
if (millis() - lastTimeBotRan > checkTime) {
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages) {
checkUpdates(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
lastTimeBotRan = millis();
}
delay(1000);
if (MQTT_connect()) {
Adafruit_MQTT_Subscribe *subscription_name;
while ((subscription_name = mqtt.readSubscription(4000))) {
if (subscription_name == &private) {
Request = ((char *)private.lastread);
if (Request == "fanon") {
digitalWrite(ledPin, HIGH);
fanState = true;
bot.sendMessage(myChatId, "Fan turned on through Control Panel", "");
}
if (Request == "fanoff") {
fanState = false;
timerStart = false;
digitalWrite(ledPin, LOW);
bot.sendMessage(myChatId, "Fan turned off through Control Panel", "");
}
if (Request == "timer15") {
timerStartPoint = millis();
digitalWrite(ledPin, HIGH);
timerStart = true;
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 15 minutes through Control Panel", "");
launchTimer(15);
}
if (Request == "timer30") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 30 minutes through Control Panel", "");
launchTimer(30);
}
if (Request == "timer60") {
digitalWrite(ledPin, HIGH);
timerStart = true;
timerStartPoint = millis();
Serial.print("Fan on at ");
Serial.println(timerStartPoint);
bot.sendMessage(myChatId, "Fan turned on for 1 hour through Control Panel", "");
launchTimer(60);
}
}
}
}
if (!mqtt.ping()) {
mqtt.disconnect();
}
}
Также , в случае, если здесь показаны какие-либо из моих личных / неприемлемых для показа данных, предложите отредактировать или любезно сообщите мне, поскольку я новичок в мире StackOverflow. Заранее спасибо всем, кто захочет мне помочь.