Hi all,
I'm hoping someone can help here as I've been stuck on this for some time. My Arduino Nano has run out of SRAM space and I'm trying to move some string constants to program memory / flash from RAM.
I want to store things like wifi ssid, password, API keys, server name (for ThingSpeak) etc in flash and access them locally in the function vs being globally defined.
I've been testing the standard sketch attached which works fine, but how do I call two or more of the strings consecutively to use in my function. A single string works fine, but I need to call for example
status = WiFi.begin(ssid,pwd);
where both ssid and pwd are stored via PROGMEM. Inserting the strcpy_P into the WiFi.begin() does not work as the string is in the buffer which is overwritten when the next string is referenced.
#include <avr/pgmspace.h>
const char string_0[] PROGMEM = "String 0 Test"; // "String 0" etc are strings to store - change to suit.
const char string_1[] PROGMEM = "String 1 Test";
const char string_2[] PROGMEM = "String 2 Test";
const char string_3[] PROGMEM = "String 3 Test";
const char string_4[] PROGMEM = "String 4 Test";
const char string_5[] PROGMEM = "String 5 Test";
// Then set up a table to refer to your strings.
const char * const string_table[] PROGMEM = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5 };
char buffer[15]; // make sure this is large enough for the largest string it must hold
void setup()
{
Serial.begin(9600);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[1])));
Serial.println( buffer );
}
void loop()
{
//Not used
}
So I need to be able to so something like,
status = WiFi.begin(string_0,string_1);
Any help greatly appreciated.