I have been trying to use the email widget to send a daily mail message but I cannot get a message with more than 97 characters to be sent. In my code this message is sent.
Good Morning
I’m very cold today
It is 8:07 and the temp is 70’ with humidity at 40 percent. By
If I try to finish the last word and add an “e” no message is sent.
I am using an esp8266 and Android.
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#define WLAN_SSID "xxx"
#define WLAN_PASS "xxx"
SimpleTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
short temperature = 70;
short humidity = 40;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, WLAN_SSID, WLAN_PASS);
timer.setInterval(60000, TestMail);
timer.setInterval(1000, CountDown);
}
void loop() {
Blynk.run();
timer.run();
}
void TestMail(){
Serial.println("Sending Test Mail");
SendMessage(8, 7);
}
void SendMessage(short dawnHour, short dawnMinute){
String mailSubject = "Test Mail";
String mailMessage = "";
mailMessage = "Good Morning\nI'm very cold today\n";
mailMessage += "It is ";
mailMessage += dawnHour;
mailMessage += ":";
if (dawnMinute < 10){ mailMessage += "0"; }
mailMessage += dawnMinute;
mailMessage += " and the temp is ";
mailMessage += temperature;
mailMessage += "' with humidity at ";
mailMessage += humidity;
mailMessage += " percent. By";
// mailMessage += "e";
Blynk.email("prez_obama@gmail.com", mailSubject, mailMessage);
Serial.println(mailMessage);
}
void CountDown(){
Serial.print(".");
}
@vshymanskyy without using BLYNK_MAX_SENDBYTES what is the actual maximum number of characters and is there a breakdown between the maximum for the email subject and the email content?
@vshymanskyy with #define BLYNK_MAX_SENDBYTES 256 before the Blynk library we are able to email a 200 character byte array but not one containing 220 characters. The subject of the email is 20 characters so we were expecting the subject plus the body of 220 characters (total 240 characters) to be covered by the 256 bytes.
We have also tried increasing the 256 to 512 but we are still can’t send 220 byte body emails. Any ideas?
It might be Blynk server limitation that it wont accept larger packets so even changing libs might be not enough we need to wait for comments from dev.
True I solved this problem you need to increase BLYNK_MAX_READBYTES along with BLYNK_MAX_SENDBYTES. This way you can send larger messages. Basically BLYNK_MAX_READBYTES has to be at least the size of BLYNK_MAX_SENDBYTES.
Ok I found direct cause of the bug. In BlynkProtocol.h you have:
void BlynkProtocol<Transp>::sendCmd(uint8_t cmd, uint16_t id, const void* data, size_t length, const void* data2, size_t length2)
{
if (0 == id) {
id = getNextMsgId();
}
#ifdef BLYNK_DEBUG
BLYNK_LOG("<msg %d,%u,%u", cmd, id, length+length2);
#endif
if (!conn.connected() || (cmd != BLYNK_CMD_LOGIN && state != CONNECTED) ) {
#ifdef BLYNK_DEBUG
BLYNK_LOG("Cmd skipped");
#endif
return;
}
#if defined(BLYNK_SEND_ATOMIC)|| defined(ESP8266) || defined(SPARK) || defined(PARTICLE) || defined(ENERGIA)
// Those have more RAM and like single write at a time...
uint8_t buff[BLYNK_MAX_READBYTES]; // TODO: Eliminate constant
BlynkHeader* hdr = (BlynkHeader*)buff;
hdr->type = cmd;
hdr->msg_id = htons(id);
hdr->length = htons(length+length2);
size_t len2s = sizeof(BlynkHeader);
if (data && length) {
memcpy(buff + len2s, data, length);
len2s += length;
}
if (data2 && length2) {
memcpy(buff + len2s, data2, length2);
len2s += length2;
}
#ifdef BLYNK_DEBUG
BLYNK_DBG_DUMP("<", buff+5, len2s-5);
#endif
size_t wlen = 0;
#ifndef BLYNK_SEND_CHUNK
#define BLYNK_SEND_CHUNK 1024 // Just a big number
#endif
affected line is declaration of buff variable which is declared of size BLYNK_MAX_READBYTES should be BLYNK_MAX_SENDBYTES. In this case without change you get buffer overflow as the data overwrites content of the memory outside of the buffer.