0

I have written code on android which works, but it does not work when compiled for a "Generic 8266 board". I have a two dimension char array as String arrays are not accepted on 8266 compiler. It is set up as a set of buffers and a array of pointers pointing to them.

char buffer0[80] ; // storage containers
    char buffer1[80] ; 
    char buffer2[80] ;
    char buffer5[80] ;
    char buffer6[80] ; // buffer used to transport strings
    // Matrix of char buffers using pointers
    char *Scans[] = {"buffer0 , buffer1 , buffer2 , buffer3 , buffer4 , buffer5"};

This compiles OK and does not cause stack problems. I did look up the answers on Stackoverflow, but the answers are minus or only work for strings into a single char array, not multi-dimensioned and not out of the array back into a string for printing or using too control a program.

But I have had problems including stack problems error code 28/29 that have not been caught by the compiler, when it is run on the ESP-01 which a ESP8266 based board. I used the #include to compile the code. I have tried

char* strcpy_P(mess,Scans[0]);

mess.toCharArray(buffer0, 80);

mess.toCharArray(Scans[i], 80);

strcpy_P(Scans[i], mess);

Mess is the string I want to put into the array in a variable "i" controlled loop.

I have also tried all the char * to and from strings in https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html?highlight=str#functions-to-read-back-from-progmem and none of them work on 8266.

I want to be able to store a compilation of a number of strings into one string. Then copy it into the one of the char arrays (bufferx) within a loop using i to indicate which buffer to put the string into. Each one is from a different wifi station so they cannot be lumped together.

Then remove it from the right array number to print it out as lines in an email. It has to compile on ESP8266WiFi.h and not crash with stack errors as it will be working autonmously with out a serial port to dump errors to.

2 Answers 2

1

I've tried to compile your code in my Arduino IDE, there is no problem persist, it just work out. Try updating esp8266 board in your Arduino IDE.

Anyway, when you create an array containing multiple values, then you should seperate each values with commas, also every value should be double quoted.

so, instead of using this:

    char *Scans[] = {"buffer0 , buffer1 , buffer2 , buffer3 , buffer4 , buffer5"};

you should use this:

    char *Scans[] = {"buffer0" , "buffer1" , "buffer2" , "buffer3" , "buffer4" , "buffer5"};

Here is my full code:

    char buffer0[80];
    char buffer1[80];
    char buffer2[80];
    char buffer3[80];
    char buffer4[80];
    char buffer5[80];

    char *Scans[] = {"buffer0" , "buffer1" , "buffer2" , "buffer3" , "buffer4" , "buffer5"};
    String mess;

    void setup() {}

    void loop() {
      for (int i = 0; i <= 5; i++) {
        mess.toCharArray(Scans[i], 80);
      }
    }

hope this help.

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for the suggestion, the final solution that causes no crashes on the ESP-01 (8266 chipset) is // Set global variable char buffer0[80] ; // storage containers char buffer1[80] ; char buffer2[80] ; char buffer3[80] ; char buffer4[80] ; char buffer5[80] ; char buffer6[80] ; // buffer used to transport strings // Matrix of char buffers using pointers char Scans[] = {buffer0 , buffer1 , buffer2 , buffer3 , buffer4 , buffer5 }; // copies Matrix buffers back to String // string = Scans[i]; // Copies string into Matrix char Array // mess.toCharArray(buffer0, 80); String mess = ""; exceeding the number of buffers causes the stack crash. The code strcpy_P(Scans[i], mess) and char strstr_P(const char* haystack, PGM_P needle) only work on read only constants.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.