From 84a13e06e007b4c2a57d213d44c072a3dc11294a Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Wed, 23 Sep 2020 12:51:35 +0200 Subject: [PATCH 1/4] scripter 3 string arrays --- tasmota/xdrv_10_scripter.ino | 329 +++++++++++++++++++++++++++-------- 1 file changed, 252 insertions(+), 77 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 32a8c2a3e..42c634ac3 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -65,6 +65,7 @@ keywords if then else endif, or, and are better readable for beginners (others m #define SCRIPT_MAXPERM (PMEM_SIZE)-4/sizeof(float) #define MAX_SCRIPT_SIZE MAX_RULE_SIZE*MAX_RULE_SETS +#define MAX_SARRAY_NUM 32 uint32_t EncodeLightId(uint8_t relay_id); uint32_t DecodeLightId(uint32_t hue_id); @@ -395,14 +396,16 @@ struct SCRIPT_MEM { void *script_mem; uint16_t script_mem_size; uint8_t script_dprec; + uint8_t script_lzero; uint8_t var_not_found; uint8_t glob_error; uint8_t max_ssize; uint8_t script_loglevel; uint8_t flags; - uint8_t si_num; - uint8_t siro_num; - char *last_index_string; + uint8_t si_num[3]; + uint8_t siro_num[3]; + uint8_t sind_num; + char *last_index_string[3]; #ifdef USE_SCRIPT_FATFS File files[SFS_MAX]; @@ -438,6 +441,30 @@ uint8_t fast_script=0; uint8_t glob_script=0; uint32_t script_lastmillis; +void flt2char(float num, char *nbuff) { + dtostrfd(num, glob_script_mem.script_dprec, nbuff); +} +// convert float to char with leading zeros +void f2char(float num, uint32_t dprec, uint32_t lzeros, char *nbuff) { + dtostrfd(num, dprec, nbuff); + if (lzeros>1) { + // check leading zeros + uint32_t nd = num; + nd/=10; + nd+=1; + if (lzeros>nd) { + // insert zeros + char cpbuf[24]; + char *cp = cpbuf; + for (uint32_t cnt = 0; cnt < lzeros - nd; cnt++) { + *cp++='0'; + } + *cp=0; + strcat(cpbuf,nbuff); + strcpy(nbuff,cpbuf); + } + } +} #ifdef USE_BUTTON_EVENT int8_t script_button[MAX_KEYS]; @@ -801,6 +828,7 @@ char *script; glob_script_mem.numvars = vars; glob_script_mem.script_dprec = SCRIPT_FLOAT_PRECISION; + glob_script_mem.script_lzero = 0; glob_script_mem.script_loglevel = LOG_LEVEL_INFO; @@ -811,7 +839,7 @@ char *script; } else { char string[32]; - dtostrfd(glob_script_mem.fvars[dvtp[count].index], glob_script_mem.script_dprec, string); + f2char(glob_script_mem.fvars[dvtp[count].index], glob_script_mem.script_dprec, glob_script_mem.script_lzero, string); toLog(string); } } @@ -1127,6 +1155,23 @@ float *Get_MFAddr(uint8_t index, uint16_t *len, uint16_t *ipos) { return 0; } +char *isvar(char *lp, uint8_t *vtype, struct T_INDEX *tind, float *fp, char *sp, JsonObject *jo); + + +float *get_array_by_name(char *name, uint16_t *alen) { + struct T_INDEX ind; + uint8_t vtype; + isvar(name, &vtype, &ind, 0, 0, 0); + if (vtype==VAR_NV) return 0; + if (vtype&STYPE) return 0; + uint16_t index = glob_script_mem.type[ind.index].index; + + if (glob_script_mem.type[ind.index].bits.is_filter) { + float *fa = Get_MFAddr(index, alen, 0); + return fa; + } + return 0; +} float Get_MFVal(uint8_t index, int16_t bind) { uint8_t *mp = (uint8_t*)glob_script_mem.mfilt; @@ -1392,6 +1437,81 @@ uint32_t match_vars(char *dvnam, float **fp, char **sp, uint32_t *ind) { } #endif //USE_SCRIPT_GLOBVARS +char *isargs(char *lp, uint32_t isind) { + float fvar; + lp = GetNumericArgument(lp, OPER_EQU, &fvar, 0); + SCRIPT_SKIP_SPACES + if (*lp!='"') { + return lp; + } + lp++; + + if (glob_script_mem.si_num[isind]>0 && glob_script_mem.last_index_string[isind]) { + free(glob_script_mem.last_index_string[isind]); + } + char *sstart = lp; + uint8_t slen = 0; + for (uint32_t cnt = 0; cnt<256; cnt++) { + if (*lp=='\n' || *lp=='"' || *lp==0) { + lp++; + if (cnt>0 && !slen) { + slen++; + } + glob_script_mem.siro_num[isind] = slen; + break; + } + if (*lp=='|') { + slen++; + } + lp++; + } + + glob_script_mem.si_num[isind] = fvar; + if (glob_script_mem.si_num[isind]>0) { + if (glob_script_mem.si_num[isind]>MAX_SARRAY_NUM) { + glob_script_mem.si_num[isind] = MAX_SARRAY_NUM; + } + + glob_script_mem.last_index_string[isind] = (char*)calloc(glob_script_mem.max_ssize*glob_script_mem.si_num[isind], 1); + for (uint32_t cnt = 0; cntglob_script_mem.si_num[isind]) { + index = glob_script_mem.si_num[isind]; + } + strlcpy(str,glob_script_mem.last_index_string[isind] + (index * glob_script_mem.max_ssize), glob_script_mem.max_ssize); + } + } + lp++; + if (sp) strlcpy(sp, str, glob_script_mem.max_ssize); + return lp; +} // vtype => ff=nothing found, fe=constant number,fd = constant string else bit 7 => 80 = string, 0 = number // no flash strings here for performance reasons!!! @@ -2085,6 +2205,93 @@ chknext: len = 0; goto exit; } + + if (!strncmp(vname, "fwa(", 4)) { + struct T_INDEX ind; + uint8_t vtype; + lp = isvar(lp + 4, &vtype, &ind, 0, 0, 0); + if (vtype!=VAR_NV && (vtype&STYPE)==0 && glob_script_mem.type[ind.index].bits.is_filter) { + // found array as result + + } else { + // error + fvar = 0; + goto exit; + } + + while (*lp==' ') lp++; + lp = GetNumericArgument(lp, OPER_EQU, &fvar, 0); + uint8_t index = fvar; + if (index>=SFS_MAX) index = SFS_MAX - 1; + if (glob_script_mem.file_flags[index].is_open) { + uint16_t len = 0; + float *fa = Get_MFAddr(glob_script_mem.type[ind.index].index, &len, 0); + char dstr[24]; + for (uint32_t cnt = 0; cnt=SFS_MAX) find = SFS_MAX - 1; + char str[glob_script_mem.max_ssize + 1]; + if (glob_script_mem.file_flags[find].is_open) { + uint16_t len = 0; + float *fa = Get_MFAddr(glob_script_mem.type[ind.index].index, &len, 0); + char dstr[24]; + for (uint32_t cnt = 0; cnt=glob_script_mem.max_ssize - 1) break; + } + } + *cp = 0; + *fa++=CharToFloat(str); + } + } else { + fvar = 0; + } + lp++; + len = 0; + goto exit; + } + #endif // USE_SCRIPT_FATFS_EXT if (!strncmp(vname, "fl1(", 4) || !strncmp(vname, "fl2(", 4) ) { uint8_t lknum = *(lp+2)&3; @@ -2202,7 +2409,6 @@ chknext: } #endif //USE_LIGHT break; -#define MAX_SARRAY_NUM 32 case 'i': if (!strncmp(vname, "int(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, 0); @@ -2212,77 +2418,35 @@ chknext: goto exit; } if (!strncmp(vname, "is(", 3)) { - lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, 0); - SCRIPT_SKIP_SPACES - if (*lp!='"') { - break; - } - lp++; - - if (glob_script_mem.si_num>0 && glob_script_mem.last_index_string) { - free(glob_script_mem.last_index_string); - } - char *sstart = lp; - uint8_t slen = 0; - for (uint32_t cnt = 0; cnt<256; cnt++) { - if (*lp=='\n' || *lp=='"' || *lp==0) { - lp++; - if (cnt>0 && !slen) { - slen++; - } - glob_script_mem.siro_num = slen; - break; - } - if (*lp=='|') { - slen++; - } - lp++; - } - - glob_script_mem.si_num = fvar; - if (glob_script_mem.si_num>0) { - if (glob_script_mem.si_num>MAX_SARRAY_NUM) { - glob_script_mem.si_num = MAX_SARRAY_NUM; - } - - glob_script_mem.last_index_string = (char*)calloc(glob_script_mem.max_ssize*glob_script_mem.si_num, 1); - for (uint32_t cnt = 0; cntglob_script_mem.si_num) { - index = glob_script_mem.si_num; - } - strlcpy(str,glob_script_mem.last_index_string + (index * glob_script_mem.max_ssize), glob_script_mem.max_ssize); - } - } - lp++; - if (sp) strlcpy(sp, str, glob_script_mem.max_ssize); + lp = isget(lp + 3, sp, 0); + len = 0; + goto strexit; + } + if (!strncmp(vname, "is1[", 4)) { + lp = isget(lp + 4, sp, 1); + len = 0; + goto strexit; + } + if (!strncmp(vname, "is2[", 4)) { + lp = isget(lp + 4, sp, 2); len = 0; goto strexit; } @@ -2614,7 +2778,7 @@ chknext: if (!strncmp(vname, "s(", 2)) { lp = GetNumericArgument(lp + 2, OPER_EQU, &fvar, 0); char str[glob_script_mem.max_ssize + 1]; - dtostrfd(fvar, glob_script_mem.script_dprec, str); + f2char(fvar, glob_script_mem.script_dprec, glob_script_mem.script_lzero, str); if (sp) strlcpy(sp, str, glob_script_mem.max_ssize); lp++; len = 0; @@ -3260,6 +3424,7 @@ void Replace_Cmd_Vars(char *srcbuf, uint32_t srcsize, char *dstbuf, uint32_t dst uint16_t count; uint8_t vtype; uint8_t dprec = glob_script_mem.script_dprec; + uint8_t lzero = glob_script_mem.script_lzero; float fvar; cp = srcbuf; struct T_INDEX ind; @@ -3273,16 +3438,21 @@ void Replace_Cmd_Vars(char *srcbuf, uint32_t srcsize, char *dstbuf, uint32_t dst dstbuf[count] = *cp++; } else { if (isdigit(*cp)) { + if (*(cp+1)=='.') { + lzero = *cp & 0xf; + cp+=2; + } dprec = *cp & 0xf; cp++; } else { dprec = glob_script_mem.script_dprec; + lzero = glob_script_mem.script_lzero; } if (*cp=='(') { // math expression cp++; cp = GetNumericArgument(cp, OPER_EQU, &fvar, 0); - dtostrfd(fvar, dprec, string); + f2char(fvar, dprec, lzero, string); uint8_t slen = strlen(string); if (count + slen=0) { if (lastop==OPER_EQU) { - strlcpy(glob_script_mem.last_index_string + (saindex * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize); + strlcpy(glob_script_mem.last_index_string[glob_script_mem.sind_num] + (saindex * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize); } else if (lastop==OPER_PLSEQU) { - strncat(glob_script_mem.last_index_string + (saindex * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize); + strncat(glob_script_mem.last_index_string[glob_script_mem.sind_num] + (saindex * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize); } last_sindex = -1; } else { @@ -6182,6 +6356,7 @@ const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'"; #define MAX_GARRAY 4 + char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint16_t *rentries, uint16_t *ipos) { struct T_INDEX ind; uint8_t vtype; @@ -6659,7 +6834,7 @@ exgc: for (uint32_t ind = 0; ind < anum; ind++) { char acbuff[32]; float *fp = arrays[ind]; - dtostrfd(fp[aind], glob_script_mem.script_dprec, acbuff); + f2char(fp[aind], glob_script_mem.script_dprec, glob_script_mem.script_lzero, acbuff); WSContentSend_PD("%s", acbuff); if (ind Date: Wed, 23 Sep 2020 12:52:04 +0200 Subject: [PATCH 2/4] i2s audio fix define bug --- tasmota/xdrv_42_i2s_audio.ino | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tasmota/xdrv_42_i2s_audio.ino b/tasmota/xdrv_42_i2s_audio.ino index 5a31d832b..4a3bd91b0 100644 --- a/tasmota/xdrv_42_i2s_audio.ino +++ b/tasmota/xdrv_42_i2s_audio.ino @@ -54,11 +54,6 @@ AudioFileSourceID3 *id3; AudioGeneratorMP3 *decoder = NULL; void *mp3ram = NULL; -#ifdef USE_WEBRADIO -AudioFileSourceICYStream *ifile = NULL; -AudioFileSourceBuffer *buff = NULL; -char wr_title[64]; -//char status[64]; #ifdef ESP8266 const int preallocateBufferSize = 5*1024; @@ -69,6 +64,12 @@ const int preallocateCodecSize = 29192; // MP3 codec max mem needed //const int preallocateCodecSize = 85332; // AAC+SBR codec max mem needed #endif +#ifdef USE_WEBRADIO +AudioFileSourceICYStream *ifile = NULL; +AudioFileSourceBuffer *buff = NULL; +char wr_title[64]; +//char status[64]; + void *preallocateBuffer = NULL; void *preallocateCodec = NULL; uint32_t retryms = 0; From ee7b64692b424de5d9817a513771e1d3cb0c4536 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Wed, 23 Sep 2020 12:52:54 +0200 Subject: [PATCH 3/4] sendmail esp8266 mail attachments, array attachments --- .../src/ESP32_MailClient.cpp | 52 +++++- .../ESP32-Mail-Client/src/ESP32_MailClient.h | 5 +- tasmota/sendemail.ino | 172 +++++++++++++++++- 3 files changed, 211 insertions(+), 18 deletions(-) diff --git a/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp b/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp index 85cb0663e..687661ac9 100755 --- a/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp +++ b/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp @@ -654,7 +654,7 @@ bool ESP32_MailClient::readMail(IMAPData &imapData) { _sdOk = sdTest(); if (_sdOk) - if (!SD.exists(imapData._savePath.c_str())) + if (!imapData.fsp->exists(imapData._savePath.c_str())) createDirs(imapData._savePath); } else if (imapData._storageType == MailClientStorageType::SPIFFS) @@ -1788,6 +1788,7 @@ bool ESP32_MailClient::sendMail(SMTPData &smtpData) else { +/* if (!_sdOk) { if (smtpData._storageType == MailClientStorageType::SD) @@ -1798,13 +1799,18 @@ bool ESP32_MailClient::sendMail(SMTPData &smtpData) if (!_sdOk) continue; - +*/ bool file_existed = false; +/* if (smtpData._storageType == MailClientStorageType::SD) file_existed = SD.exists(smtpData._attach._filename[i].c_str()); else if (smtpData._storageType == MailClientStorageType::SPIFFS) file_existed = SPIFFS.exists(smtpData._attach._filename[i].c_str()); + else if (smtpData._storageType == MailClientStorageType::FFat) + file_existed = FFat.exists(smtpData._attach._filename[i].c_str()); +*/ + file_existed = smtpData.fsp->exists(smtpData._attach._filename[i].c_str()); if (file_existed) { smtpData._cbData._info = smtpData._attach._filename[i]; @@ -1820,10 +1826,15 @@ bool ESP32_MailClient::sendMail(SMTPData &smtpData) smtpData._net->getStreamPtr()->print(buf.c_str()); File file; + /* if (smtpData._storageType == MailClientStorageType::SD) file = SD.open(smtpData._attach._filename[i].c_str(), FILE_READ); else if (smtpData._storageType == MailClientStorageType::SPIFFS) file = SPIFFS.open(smtpData._attach._filename[i].c_str(), FILE_READ); + else if (smtpData._storageType == MailClientStorageType::FFat) + file = FFat.open(smtpData._attach._filename[i].c_str(), FILE_READ); + */ + file = smtpData.fsp->open(smtpData._attach._filename[i].c_str(), FILE_READ); send_base64_encode_mime_file(smtpData._net->getStreamPtr(), file); smtpData._net->getStreamPtr()->print(ESP32_MAIL_STR_34); @@ -2036,6 +2047,7 @@ bool ESP32_MailClient::sdBegin(uint8_t sck, uint8_t miso, uint8_t mosi, uint8_t _mosi = mosi; _ss = ss; _sdConfigSet = true; + SPI.begin(_sck, _miso, _mosi, _ss); return SD.begin(_ss, SPI); } @@ -2331,7 +2343,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT delete[] midx; if (imapData._storageType == MailClientStorageType::SD) - if (!SD.exists(filepath.c_str())) + if (!imapData.fsp->exists(filepath.c_str())) createDirs(filepath); if (!imapData._headerSaved) @@ -2353,7 +2365,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT } if (imapData._storageType == MailClientStorageType::SD) - file = SD.open(filepath.c_str(), FILE_WRITE); + file = imapData.fsp->open(filepath.c_str(), FILE_WRITE); else if (imapData._storageType == MailClientStorageType::SPIFFS) file = SPIFFS.open(filepath.c_str(), FILE_WRITE); } @@ -2922,7 +2934,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT delete[] midx; if (imapData._storageType == MailClientStorageType::SD) - if (!SD.exists(filepath.c_str())) + if (!imapData.fsp->exists(filepath.c_str())) createDirs(filepath); if (!imapData._headerSaved) @@ -2944,7 +2956,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT } if (imapData._storageType == MailClientStorageType::SD) - file = SD.open(filepath.c_str(), FILE_WRITE); + file = imapData.fsp->open(filepath.c_str(), FILE_WRITE); else if (imapData._storageType == MailClientStorageType::SPIFFS) file = SPIFFS.open(filepath.c_str(), FILE_WRITE); } @@ -3003,7 +3015,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT delete[] midx; if (imapData._storageType == MailClientStorageType::SD) - if (!SD.exists(filepath.c_str())) + if (!imapData.fsp->exists(filepath.c_str())) createDirs(filepath); filepath += ESP32_MAIL_STR_202; @@ -3011,7 +3023,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT filepath += imapData._messageDataInfo[mailIndex][messageDataIndex]._filename; if (imapData._storageType == MailClientStorageType::SD) - file = SD.open(filepath.c_str(), FILE_WRITE); + file = imapData.fsp->open(filepath.c_str(), FILE_WRITE); else if (imapData._storageType == MailClientStorageType::SPIFFS) file = SPIFFS.open(filepath.c_str(), FILE_WRITE); } @@ -3167,7 +3179,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT { if (imapData._storageType == MailClientStorageType::SD) - file = SD.open(hpath.c_str(), FILE_WRITE); + file = imapData.fsp->open(hpath.c_str(), FILE_WRITE); else if (imapData._storageType == MailClientStorageType::SPIFFS) file = SPIFFS.open(hpath.c_str(), FILE_WRITE); @@ -3714,6 +3726,17 @@ void IMAPData::setFetchUID(const String &fetchUID) void IMAPData::setFileStorageType(uint8_t storageType) { _storageType = storageType; + switch (storageType) { + case MailClientStorageType::SPIFFS: + fsp = &SPIFFS; + break; + case MailClientStorageType::SD: + fsp = &SD; + break; + case MailClientStorageType::FFat: + fsp = &FFat; + break; + } } void IMAPData::setDownloadAttachment(bool download) @@ -4733,6 +4756,17 @@ void SMTPData::removeAttachFile(uint8_t index) void SMTPData::setFileStorageType(uint8_t storageType) { _storageType = storageType; + switch (storageType) { + case MailClientStorageType::SPIFFS: + fsp = &SPIFFS; + break; + case MailClientStorageType::SD: + fsp = &SD; + break; + case MailClientStorageType::FFat: + fsp = &FFat; + break; + } } void SMTPData::clearAttachData() diff --git a/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h b/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h index 943cd62f7..b6a8da775 100755 --- a/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h +++ b/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h @@ -48,6 +48,7 @@ #include "RFC2047.h" #include "ESP32MailHTTPClient.h" #include "ESP32TimeHelper.h" +#include #define FORMAT_SPIFFS_IF_FAILED true @@ -90,6 +91,7 @@ struct MailClientStorageType { static const uint8_t SPIFFS = 0; static const uint8_t SD = 1; + static const uint8_t FFat = 2; }; static const char ESP32_MAIL_STR_1[] PROGMEM = "Content-Type: multipart/mixed; boundary=\""; @@ -1302,6 +1304,7 @@ private: std::string _host = ""; uint16_t _port = 993; uint8_t _storageType = 1; + FS *fsp = &SD; bool _unseen = false; std::string _loginEmail = ""; std::string _loginPassword = ""; @@ -1859,7 +1862,7 @@ protected: string _host = ""; uint16_t _port = 0; uint8_t _storageType = 1; - + FS *fsp = &SD; string _fromName = ""; string _senderEmail = ""; string _subject = ""; diff --git a/tasmota/sendemail.ino b/tasmota/sendemail.ino index 0a4c4de0e..bc080bd7f 100644 --- a/tasmota/sendemail.ino +++ b/tasmota/sendemail.ino @@ -330,6 +330,12 @@ String buffer; if (!buffer.startsWith(F("354"))) { goto exit; } + + buffer = F("MIME-Version: 1.0\r\n"); + client->print(buffer); + buffer = F("Content-Type: Multipart/mixed; boundary=frontier\r\n"); + client->print(buffer); + buffer = F("From: "); buffer += from; client->println(buffer); @@ -350,6 +356,7 @@ String buffer; AddLog_P2(LOG_LEVEL_INFO, PSTR("%s"),buffer.c_str()); #endif + #ifdef USE_SCRIPT if (*msg=='*' && *(msg+1)==0) { g_client=client; @@ -378,9 +385,98 @@ exit: } void xsend_message_txt(char *msg) { - g_client->println(msg); -} +#ifdef DEBUG_EMAIL_PORT + AddLog_P2(LOG_LEVEL_INFO, PSTR("%s"),msg); +#endif +#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) + if (*msg=='@') { + msg++; + attach_File(msg); + } else if (*msg=='&') { + msg++; + attach_Array(msg); + } else { + g_client->print(F("--frontier\r\n")); + g_client->print(F("Content-Type: text/plain\r\n\r\n")); + g_client->println(msg); + g_client->print(F("\r\n--frontier\r\n")); + } #else + g_client->print(F("--frontier\r\n")); + g_client->print(F("Content-Type: text/plain\r\n\r\n")); + g_client->println(msg); + g_client->print(F("\r\n--frontier\r\n")); +#endif +} + +#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) +#include +extern FS *fsp; + +void attach_File(char *path) { + g_client->print(F("--frontier\r\n")); + g_client->print(F("Content-Type: text/plain\r\n")); + char buff[64]; + char *cp = path; + while (*cp=='/') cp++; + File file = fsp->open(path, "r"); + if (file) { + sprintf_P(buff,PSTR("Content-Disposition: attachment; filename=\"%s\"\r\n\r\n"), cp); + g_client->write(buff); + uint16_t flen = file.size(); + uint8_t fbuff[64]; + uint16_t blen = sizeof(fbuff); + while (flen>0) { + file.read(fbuff, blen); + flen -= blen; + g_client->write(fbuff, blen); + if (flenprint(F("\r\n\r\nfile not found!\r\n")); + } + g_client->print(F("\r\n--frontier\r\n")); +} + +float *get_array_by_name(char *name, uint16_t *alen); +void flt2char(float num, char *nbuff); + +void attach_Array(char *aname) { + float *array = 0; + uint16_t alen; + array = get_array_by_name(aname, &alen); + g_client->print(F("--frontier\r\n")); + g_client->print(F("Content-Type: text/plain\r\n")); + if (array && alen) { +#ifdef DEBUG_EMAIL_PORT + AddLog_P2(LOG_LEVEL_INFO, PSTR("array found %d"),alen); +#endif + char buff[64]; + sprintf_P(buff,PSTR("Content-Disposition: attachment; filename=\"%s.txt\"\r\n\r\n"), aname); + g_client->write(buff); + float *fp=array; + for (uint32_t cnt = 0; cntwrite(nbuff, strlen(nbuff)); + } + } else { + g_client->print(F("\r\n\r\narray not found!\r\n")); + } + g_client->print(F("\r\n--frontier\r\n")); +} + +#endif // defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) + +#else + /* * Created by K. Suwatchai (Mobizt) @@ -413,6 +509,9 @@ void script_send_email_body(void(*func)(char *)); #define xPSTR(a) a //The Email Sending data object contains config and data to send SMTPData smtpData; +#define MAX_ATTCHMENTS 8 +char *attachments[MAX_ATTCHMENTS]; +uint8_t num_attachments; //Callback function to get the Email sending status //void sendCallback(SendStatus info); @@ -435,7 +534,7 @@ uint16_t SendMail(char *buffer) { // return if not enough memory uint32_t mem=ESP.getFreeHeap(); - AddLog_P2(LOG_LEVEL_INFO, PSTR("heap: %d"),mem); + //AddLog_P2(LOG_LEVEL_INFO, PSTR("heap: %d"),mem); if (memprint(F("\r\n\r\narray not found!\r\n")); + } +} void send_message_txt(char *txt) { - if (*txt=='&') { + if (*txt=='@') { txt++; smtpData.addAttachFile(txt); + } else if (*txt=='&') { + txt++; + attach_Array(txt); } else if (*txt=='$') { txt++; #if defined(ESP32) && defined(USE_WEBCAM) From ddac2668575913fec154a3a43113bfac0373e602 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Wed, 23 Sep 2020 12:53:52 +0200 Subject: [PATCH 4/4] fix esp32 watch init bug --- tasmota/xdrv_83_esp32watch.ino | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_83_esp32watch.ino b/tasmota/xdrv_83_esp32watch.ino index 2f759aa9a..6a58974c0 100644 --- a/tasmota/xdrv_83_esp32watch.ino +++ b/tasmota/xdrv_83_esp32watch.ino @@ -64,6 +64,7 @@ struct TTGO_globs { bool bma_double_click = false; bool bma_click = false; bool bma_button = false; + bool power_ok = false; } ttgo_globs; @@ -115,15 +116,19 @@ void TTGO_Init(void) { ttgo_globs.bma->enableWakeupInterrupt(true); ttgo_globs.bma->enableAnyNoMotionInterrupt(true); ttgo_globs.bma->enableAccel(); -#endif +#endif // USE_BMA423 } void initPower(void) { int ret = ttgo_globs.ttgo_power->begin(axpReadBytes, axpWriteBytes); if (ret == AXP_FAIL) { //DBGX("AXP Power begin failed"); + // Serial.printf("AXP202 failed\n" ); } else { I2cSetActiveFound(AXP202_SLAVE_ADDRESS, "AXP202"); + ttgo_globs.power_ok = true; + // Serial.printf("AXP202 OK\n" ); + //Change the button boot time to 4 seconds ttgo_globs.ttgo_power->setShutdownTime(AXP_POWER_OFF_TIME_4S); // Turn off the charging instructions, there should be no @@ -162,6 +167,7 @@ void initPower(void) { portYIELD_FROM_ISR (); } }, FALLING); + } } @@ -205,6 +211,8 @@ const char HTTP_TTGO_BMA[] PROGMEM = void TTGO_WebShow(uint32_t json) { + if (ttgo_globs.power_ok == false) return; + TTGO_GetADC(); char vstring[32]; @@ -276,8 +284,9 @@ int32_t ttgo_sleeptime; ttgo_sleeptime = stime; +#ifdef USE_DISPLAY DisplayOnOff(0); - +#endif if (ttgo_sleeptime>=0) { // ligh sleep mode WifiShutdown(); @@ -311,7 +320,9 @@ int32_t ttgo_sleeptime; if (ttgo_sleeptime) { ttgo_globs.lenergy = false; rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M); +#ifdef USE_DISPLAY DisplayOnOff(1); +#endif } else { while (ttgo_globs.lenergy == true) { TTGO_loop(0); @@ -332,7 +343,9 @@ uint8_t data; if (ttgo_globs.lenergy) { ttgo_globs.lenergy = false; rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M); +#ifdef USE_DISPLAY DisplayOnOff(1); +#endif } #ifdef USE_BMA423