storing and reading SSID and Pasword in SPIFFS

Hi,

I'm new to C++ arduino fs, so apologies up front

I have stored a textfile in FS with the following contents

'MyAccessPoint'

(Without the quotes)

I can read it to the Terminal with:

SPIFFS.begin(false);
File file = SPIFFS.open("/test.txt");
Serial.write(file.read());

but I want to use that 'string' as my first argument for WIFI.begin(ssid, password)

I'm not sure how to declare the variable for SSID and to assign it th value read from the file.

sorry for the 101

matt

the esp rememberes the ssid and password by it self to flash

However, if you still want to start parsing data out of a SPIFFS file, here is an example:
You hand the function a SPIFFS file handle (in your case 'file' ) a character buffer and its length.
You call the function for each line you want to read.
Maybe you can pick something out of this:

bool ICACHE_FLASH_ATTR getTokenFromStream( File inFile, char * outBuf, const uint16_t bufLen ) {
  // for input files with lines terminated with new line.
  // get a single token from the input line and then discard the entire line including the '\n'
  enum inState_t { start = 1 , inToken = 2 , end = 3 } ;
  inState_t inState = start ;
  
  uint16_t bufIndex = 0 ;
  for ( ; ; ) {
    if ( ! inFile.available() ) break ;
    char c = inFile.read() ;
    if (  c == '\n' ) break ;
    bool isWordChar = ( c > 0x20 && c <= 0x7E ) ;  // printable, not space

    if ( bufIndex >= ( bufLen - 1 ) ) inState = end ;
    else if ( inState == start && isWordChar ) {
      inState = inToken ;
      outBuf[ bufIndex ++ ] = c ;
    }
    else if ( inState == inToken && isWordChar ) {
      outBuf[ bufIndex ++ ] = c ;
    }
    else if ( inState == inToken && ! isWordChar ) {
      inState = end ;
    }
  } // end of loop

  if ( inState == start ) {
    return false ; // nothing found
  }
  else {
    outBuf[ bufIndex] = 0 ;
    return true ;
  }
}

'the esp rememberes the ssid and password by it self to flash@

can u elaborate here?

also, I got it working by converting String to Char

strcpy(ssid, line.c_str());

Thanks chaps/Chapesses

mattashfield:
'the esp rememberes the ssid and password by it self to flash@

can u elaborate here?

Test it. Connect to your WiFi network with a standard setup() and then change begin(ssid, pass) to begin() and try the sketch

and see Station Class — ESP8266 Arduino Core 3.1.2-21-ga348833 documentation