I have the following method that sends email
char location = "London";
void postMail(const __FlashStringHelper *msg)
_buffer = _readSerial(TIMEOUT);
if (_buffer.indexOf(F("OK")) != -1)
uint16_t msgLength = strlen_P(reinterpret_cast<PGM_P>(msg));
_buffer = _readSerial(12000);
I want to use the variable “location” when calling the function postMail(). I mean something like
postMail(location + F(" is beautiful"));
postMail(location + F(" is safe to visit"));
postMail(location + F(" should be your next destination"));
I want to be able to pass the variable location on each function call. This will make my life really easy. What is the most efficient way to do this without overburdening my RAM.
i don't believe you can use a pointer to reference strings stored in FLASH the way you do in RAM. they need to be copied to ram first
PROGMEM may help
change your postMail() function to accept two parameters.
void postMail(const char *loc, const __FlashStringHelper *msg)
postMail(location, F(" is beautiful"));
@blh, this didn't work because the postMail method has to send both location and the message body once. The location is supposed to be part of the message
Please post the code that didn’t work.
It will work. The postMail() function calculates the length of the message. Now you will have to calculate the length of the location and add that to the length of the message to get the total length.
The postMail() function does a gsm.print(msg) call. Now you will have to add another gsm.print() call to send the location before you send the message.
Oh thank you @blh64, the code works now. It didn't work before because I failed to add the length of the location variable to that of the message. Thank you for pointing that out to me. Everything works perfectly now. Thanks