mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Fix ошибок и под esp8266
This commit is contained in:
@@ -26,33 +26,6 @@
|
|||||||
#define DEBUG_SERIAL_ENABLE
|
#define DEBUG_SERIAL_ENABLE
|
||||||
#include "ESPNexUpload.h"
|
#include "ESPNexUpload.h"
|
||||||
|
|
||||||
#if defined ESP8266
|
|
||||||
|
|
||||||
#include <SoftwareSerial.h>
|
|
||||||
|
|
||||||
#ifndef NEXT_RX
|
|
||||||
#define NEXT_RX 14 // Nextion RX pin | Default 14 / D5
|
|
||||||
#define NEXT_TX 12 // Nextion TX pin | Default 12 / D6
|
|
||||||
#endif
|
|
||||||
#ifndef nexSerial
|
|
||||||
//SoftwareSerial softSerial(NEXT_RX, NEXT_TX);
|
|
||||||
#define nexSerial softSerial
|
|
||||||
#define nexSerialBegin(a, b, c) nexSerial.begin(a)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined ESP32
|
|
||||||
|
|
||||||
#ifndef NEXT_RX
|
|
||||||
#define NEXT_RX 17 // Nextion RX pin | Default 16
|
|
||||||
#define NEXT_TX 16 // Nextion TX pin | Default 17
|
|
||||||
#endif
|
|
||||||
#ifndef nexSerial
|
|
||||||
#define nexSerial Serial2
|
|
||||||
#define nexSerialBegin(a, rx, tx) nexSerial.begin(a, SERIAL_8N1, rx, tx)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL_ENABLE
|
#ifdef DEBUG_SERIAL_ENABLE
|
||||||
#define dbSerialPrint(a) Serial.print(a)
|
#define dbSerialPrint(a) Serial.print(a)
|
||||||
#define dbSerialPrintHex(a) Serial.print(a, HEX)
|
#define dbSerialPrintHex(a) Serial.print(a, HEX)
|
||||||
@@ -77,23 +50,40 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESPNexUpload::ESPNexUpload(uint32_t upload_baudrate, uint8_t rx, uint8_t tx)
|
ESPNexUpload::ESPNexUpload(uint32_t upload_baudrate, int line, int rx, int tx)
|
||||||
{
|
{
|
||||||
_upload_baudrate = upload_baudrate;
|
_upload_baudrate = upload_baudrate;
|
||||||
if (rx == 0 || tx == 0)
|
_rx = rx;
|
||||||
{
|
_tx = tx;
|
||||||
_rx = NEXT_RX;
|
_line = line;
|
||||||
_tx = NEXT_TX;
|
|
||||||
}else{
|
|
||||||
_rx = rx;
|
|
||||||
_tx = tx;
|
|
||||||
}
|
|
||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
SoftwareSerial softSerial(_rx, _tx);
|
nexSerial = new SoftwareSerial(_rx, _tx);
|
||||||
|
#else
|
||||||
|
if (line >= 0) {
|
||||||
|
nexSerial = new HardwareSerial(line);
|
||||||
|
// ((HardwareSerial*)nexSerial)->begin(_upload_baudrate, SERIAL_8N1, _rx, _tx);
|
||||||
|
} else {
|
||||||
|
nexSerial = new SoftwareSerial(_rx, _tx);
|
||||||
|
// ((SoftwareSerial*)nexSerial)->begin(_upload_baudrate);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESPNexUpload::nexSerialBegin(uint32_t _speed, int _line, int _rx, int _tx)
|
||||||
|
{
|
||||||
|
#if defined ESP8266
|
||||||
|
nexSerial->begin(_speed);
|
||||||
|
#else
|
||||||
|
if (_line >= 0) {
|
||||||
|
((HardwareSerial*)nexSerial)->begin(_speed, SERIAL_8N1, _rx, _tx);
|
||||||
|
} else {
|
||||||
|
((SoftwareSerial*)nexSerial)->begin(_speed);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool ESPNexUpload::connect()
|
bool ESPNexUpload::connect()
|
||||||
{
|
{
|
||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
@@ -172,7 +162,7 @@ bool ESPNexUpload::_searchBaudrate(uint32_t baudrate)
|
|||||||
dbSerialPrint(F("init nextion serial interface on baudrate: "));
|
dbSerialPrint(F("init nextion serial interface on baudrate: "));
|
||||||
dbSerialPrintln(baudrate);
|
dbSerialPrintln(baudrate);
|
||||||
|
|
||||||
nexSerialBegin(baudrate, _rx, _tx);
|
nexSerialBegin(baudrate, _line, _rx, _tx);
|
||||||
_printInfoLine(F("ESP baudrate established, try to connect to display"));
|
_printInfoLine(F("ESP baudrate established, try to connect to display"));
|
||||||
const char _nextion_FF_FF[3] = {0xFF, 0xFF, 0x00};
|
const char _nextion_FF_FF[3] = {0xFF, 0xFF, 0x00};
|
||||||
|
|
||||||
@@ -231,20 +221,20 @@ void ESPNexUpload::sendCommand(const char *cmd, bool tail, bool null_head)
|
|||||||
|
|
||||||
if (null_head)
|
if (null_head)
|
||||||
{
|
{
|
||||||
nexSerial.write(0x00);
|
((HardwareSerial*)nexSerial)->write(0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nexSerial.available())
|
while (nexSerial->available())
|
||||||
{
|
{
|
||||||
nexSerial.read();
|
nexSerial->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
nexSerial.print(cmd);
|
nexSerial->print(cmd);
|
||||||
if (tail)
|
if (tail)
|
||||||
{
|
{
|
||||||
nexSerial.write(0xFF);
|
nexSerial->write(0xFF);
|
||||||
nexSerial.write(0xFF);
|
nexSerial->write(0xFF);
|
||||||
nexSerial.write(0xFF);
|
nexSerial->write(0xFF);
|
||||||
}
|
}
|
||||||
_printSerialData(true, cmd);
|
_printSerialData(true, cmd);
|
||||||
}
|
}
|
||||||
@@ -270,10 +260,10 @@ uint16_t ESPNexUpload::recvRetString(String &response, uint32_t timeout, bool re
|
|||||||
while (millis() - start <= timeout)
|
while (millis() - start <= timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
while (nexSerial.available())
|
while (nexSerial->available())
|
||||||
{
|
{
|
||||||
|
|
||||||
c = nexSerial.read();
|
c = nexSerial->read();
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -344,9 +334,9 @@ bool ESPNexUpload::_setPrepareForFirmwareUpdate(uint32_t upload_baudrate)
|
|||||||
// because switching to another baudrate (nexSerialBegin command) has an higher prio.
|
// because switching to another baudrate (nexSerialBegin command) has an higher prio.
|
||||||
// The ESP will first jump to the new 'upload_baudrate' and than process the serial 'transmit buffer'
|
// The ESP will first jump to the new 'upload_baudrate' and than process the serial 'transmit buffer'
|
||||||
// The flush command forced the ESP to wait until the 'transmit buffer' is empty
|
// The flush command forced the ESP to wait until the 'transmit buffer' is empty
|
||||||
nexSerial.flush();
|
nexSerial->flush();
|
||||||
|
|
||||||
nexSerialBegin(upload_baudrate, _rx, _tx);
|
nexSerialBegin(upload_baudrate, _line, _rx, _tx);
|
||||||
_printInfoLine(F("changing upload baudrate..."));
|
_printInfoLine(F("changing upload baudrate..."));
|
||||||
_printInfoLine(String(upload_baudrate));
|
_printInfoLine(String(upload_baudrate));
|
||||||
|
|
||||||
@@ -421,7 +411,7 @@ bool ESPNexUpload::upload(const uint8_t *file_buf, size_t buf_size)
|
|||||||
c = file_buf[i];
|
c = file_buf[i];
|
||||||
|
|
||||||
// write byte to nextion over serial
|
// write byte to nextion over serial
|
||||||
nexSerial.write(c);
|
nexSerial->write(c);
|
||||||
|
|
||||||
// update sent packets counter
|
// update sent packets counter
|
||||||
_sent_packets++;
|
_sent_packets++;
|
||||||
@@ -438,7 +428,7 @@ bool ESPNexUpload::upload(Stream &myFile)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// create buffer for read
|
// create buffer for read
|
||||||
uint8_t buff[2048] = {0};
|
uint8_t buff[4096] = {0};
|
||||||
|
|
||||||
// read all data from server
|
// read all data from server
|
||||||
while (_undownloadByte > 0 || _undownloadByte == -1)
|
while (_undownloadByte > 0 || _undownloadByte == -1)
|
||||||
@@ -492,7 +482,7 @@ void ESPNexUpload::end()
|
|||||||
this->softReset();
|
this->softReset();
|
||||||
|
|
||||||
// end Serial connection
|
// end Serial connection
|
||||||
nexSerial.end();
|
((HardwareSerial*)nexSerial)->end();
|
||||||
|
|
||||||
// reset sent packets counter
|
// reset sent packets counter
|
||||||
_sent_packets = 0;
|
_sent_packets = 0;
|
||||||
|
|||||||
@@ -56,6 +56,13 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <StreamString.h>
|
#include <StreamString.h>
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
#else
|
||||||
|
#include <HardwareSerial.h>
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup CoreAPI
|
* @addtogroup CoreAPI
|
||||||
* @{
|
* @{
|
||||||
@@ -79,7 +86,7 @@ public: /* methods */
|
|||||||
*
|
*
|
||||||
* @param uint32_t upload_baudrate - set upload baudrate.
|
* @param uint32_t upload_baudrate - set upload baudrate.
|
||||||
*/
|
*/
|
||||||
ESPNexUpload(uint32_t upload_baudrate, uint8_t rx=0, uint8_t tx=0);
|
ESPNexUpload(uint32_t upload_baudrate, int line, int rx, int tx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destructor.
|
* destructor.
|
||||||
@@ -256,6 +263,8 @@ private: /* methods */
|
|||||||
*/
|
*/
|
||||||
uint32_t calculateTransmissionTimeMs(String message);
|
uint32_t calculateTransmissionTimeMs(String message);
|
||||||
|
|
||||||
|
void nexSerialBegin(uint32_t upload_baudrate, int line, int rx, int tx);
|
||||||
|
|
||||||
private: /* data */
|
private: /* data */
|
||||||
uint32_t _baudrate; /* nextion serail baudrate */
|
uint32_t _baudrate; /* nextion serail baudrate */
|
||||||
uint32_t _undownloadByte; /* undownload byte of tft file */
|
uint32_t _undownloadByte; /* undownload byte of tft file */
|
||||||
@@ -263,8 +272,14 @@ private: /* data */
|
|||||||
uint16_t _sent_packets = 0; /* upload baudrate */
|
uint16_t _sent_packets = 0; /* upload baudrate */
|
||||||
uint8_t _rx;
|
uint8_t _rx;
|
||||||
uint8_t _tx;
|
uint8_t _tx;
|
||||||
|
uint8_t _line;
|
||||||
THandlerFunction _updateProgressCallback;
|
THandlerFunction _updateProgressCallback;
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
SoftwareSerial* nexSerial;
|
||||||
|
#else
|
||||||
|
Stream* nexSerial;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -213,7 +213,8 @@ public:
|
|||||||
SerialPrint("I", F("NextionUpdate"), "connecting to " + (String)_host);
|
SerialPrint("I", F("NextionUpdate"), "connecting to " + (String)_host);
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
if (!http.begin(_host, 80, _url))
|
WiFiClient client;
|
||||||
|
if (!http.begin(client, _host, 80, _url))
|
||||||
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
||||||
#elif defined ESP32
|
#elif defined ESP32
|
||||||
if (!http.begin(String("http://") + _host + _url))
|
if (!http.begin(String("http://") + _host + _url))
|
||||||
|
|||||||
@@ -87,12 +87,7 @@
|
|||||||
},
|
},
|
||||||
"defActive": false,
|
"defActive": false,
|
||||||
"usedLibs": {
|
"usedLibs": {
|
||||||
"esp32_4mb": [],
|
"esp32*": [],
|
||||||
"esp32_4mb3f": [],
|
"esp82*": []
|
||||||
"esp8266_4mb": [],
|
|
||||||
"esp8266_1mb": [],
|
|
||||||
"esp8266_1mb_ota": [],
|
|
||||||
"esp8285_1mb": [],
|
|
||||||
"esp8285_1mb_ota": []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,8 @@ public:
|
|||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
if (!http.begin(_host, 80, _url))
|
WiFiClient client;
|
||||||
|
if (!http.begin(client, _host, 80, _url))
|
||||||
{
|
{
|
||||||
// Serial.println("connection failed");
|
// Serial.println("connection failed");
|
||||||
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
||||||
@@ -118,7 +119,13 @@ public:
|
|||||||
int contentLength = http.getSize();
|
int contentLength = http.getSize();
|
||||||
SerialPrint("I", F("NextionUpdate"), "File received. Update Nextion... ");
|
SerialPrint("I", F("NextionUpdate"), "File received. Update Nextion... ");
|
||||||
bool result;
|
bool result;
|
||||||
ESPNexUpload nextion(115200, _NEXT_RX, _NEXT_TX);
|
#ifdef ESP8266
|
||||||
|
ESPNexUpload nextion(115200, -1, _NEXT_RX, _NEXT_TX);
|
||||||
|
#elif defined(esp32c3m_4mb) || defined(esp32s2_4mb)
|
||||||
|
ESPNexUpload nextion(115200, 1, _NEXT_RX, _NEXT_TX);
|
||||||
|
#else
|
||||||
|
ESPNexUpload nextion(115200, 2, _NEXT_RX, _NEXT_TX);
|
||||||
|
#endif
|
||||||
nextion.setUpdateProgressCallback([]()
|
nextion.setUpdateProgressCallback([]()
|
||||||
{ SerialPrint("I", F("NextionUpdate"), "... "); });
|
{ SerialPrint("I", F("NextionUpdate"), "... "); });
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <TM1637.h>
|
#include <TM1637.h>
|
||||||
#include <TM1638.h>
|
#include <TM1638.h>
|
||||||
#include <TM16xxDisplay.h>
|
#include <TM16xxDisplay.h>
|
||||||
#include <TM16xxbuttons.h>
|
#include <TM16xxButtons.h>
|
||||||
|
|
||||||
|
|
||||||
TM16xxButtons* buttons = nullptr; // указатель на объект управления кнопками для TM1638 иначе nullptr
|
TM16xxButtons* buttons = nullptr; // указатель на объект управления кнопками для TM1638 иначе nullptr
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
// #include <GyverGFX.h>
|
// #include <GyverGFX.h>
|
||||||
// #include <CharPlot.h>
|
// #include <CharPlot.h>
|
||||||
// #include "esp_camera.h"
|
// #include "esp_camera.h"
|
||||||
|
#ifdef ESP8266
|
||||||
|
#define FB_DYNAMIC
|
||||||
|
#endif
|
||||||
#include <FastBot.h>
|
#include <FastBot.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@@ -93,6 +95,7 @@ public:
|
|||||||
if (fl_rollback)
|
if (fl_rollback)
|
||||||
{
|
{
|
||||||
_myBot->tickManual(); // Чтобы отметить сообщение прочитанным
|
_myBot->tickManual(); // Чтобы отметить сообщение прочитанным
|
||||||
|
#ifdef ESP32
|
||||||
if (Update.rollBack())
|
if (Update.rollBack())
|
||||||
{
|
{
|
||||||
SerialPrint("I", F("Update"), F("Откат OTA успешно выполнен"));
|
SerialPrint("I", F("Update"), F("Откат OTA успешно выполнен"));
|
||||||
@@ -104,6 +107,7 @@ public:
|
|||||||
SerialPrint("E", F("Update"), F("Откат OTA не выполнен!"));
|
SerialPrint("E", F("Update"), F("Откат OTA не выполнен!"));
|
||||||
_myBot->sendMessage("Откат OTA не выполнен!", _chatID);
|
_myBot->sendMessage("Откат OTA не выполнен!", _chatID);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// была попытка OTA обновления. Обновляемся после ответа серверу!
|
// была попытка OTA обновления. Обновляемся после ответа серверу!
|
||||||
if (_OTAstate >= 0)
|
if (_OTAstate >= 0)
|
||||||
@@ -369,10 +373,16 @@ public:
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
if (msg.text.indexOf("/rollback") != -1 && msg.chatID == _chatID)
|
if (msg.text.indexOf("/rollback") != -1 && msg.chatID == _chatID)
|
||||||
{
|
{
|
||||||
|
#ifdef ESP32
|
||||||
_myBot->inlineMenu("Вы уверены, что хотите откатить прошивку? " + jsonReadStr(settingsFlashJson, F("name")) + " \n OTA_roll", F("Rollback \t Cancel"));
|
_myBot->inlineMenu("Вы уверены, что хотите откатить прошивку? " + jsonReadStr(settingsFlashJson, F("name")) + " \n OTA_roll", F("Rollback \t Cancel"));
|
||||||
|
#elif ESP8266
|
||||||
|
SerialPrint("E", F("Update"), F("Откат OTA не поддерживается на esp8266!"));
|
||||||
|
_myBot->sendMessage("Откат OTA не поддерживается на esp8266!", _chatID);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (msg.text.indexOf("OTA_roll") != -1)
|
else if (msg.text.indexOf("OTA_roll") != -1)
|
||||||
{
|
{
|
||||||
|
#ifdef ESP32
|
||||||
// удаляем последнее сообщение от бота
|
// удаляем последнее сообщение от бота
|
||||||
_myBot->deleteMessage(_myBot->lastBotMsg());
|
_myBot->deleteMessage(_myBot->lastBotMsg());
|
||||||
if (msg.data.indexOf("Rollback") != -1)
|
if (msg.data.indexOf("Rollback") != -1)
|
||||||
@@ -387,6 +397,7 @@ public:
|
|||||||
_myBot->sendMessage("Откат OTA не возможен!", _chatID);
|
_myBot->sendMessage("Откат OTA не возможен!", _chatID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// -------------- Обработка файлов *.bin для прошивки по OTA --------------
|
// -------------- Обработка файлов *.bin для прошивки по OTA --------------
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user