SSID and PASSWORD read from SPIFFS file contain newline

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

SSID and PASSWORD read from SPIFFS file contain newline

Postby hellraise007 » Wed Sep 04, 2019 7:02 pm

  1. #include "SPIFFS.h"
  2. #include <WiFi.h>
  3. void setup(){
  4.   File file;
  5.   Serial.begin(115200);
  6.  
  7.   if(!SPIFFS.begin(true)){
  8.      Serial.println("An Error has occurred while mounting SPIFFS");
  9.      return;
  10.   }
  11.  
  12.  
  13.     file = SPIFFS.open("/test.txt", FILE_WRITE);
  14.     if(!file){
  15.       Serial.println("There was an error opening the file for writing");
  16.       return;
  17.     }
  18.     else
  19.     {
  20.       Serial.println("Opening the file for writing");
  21.     }
  22.     String ssid= "MAD";
  23.     String pass = "1234567890";
  24.     if(file.println(test))
  25.     {
  26.       Serial.println("SSID Written");
  27.     }
  28.  
  29.     //file.close();
  30.     file = SPIFFS.open("/test.txt",FILE_APPEND);
  31.     if(!file){
  32.       Serial.println("There was an error opening the file for appending");
  33.       return;
  34.     }
  35.  
  36.       if(file.println(test2))
  37.       {
  38.         Serial.println("Password Was Written");
  39.       }
  40.      
  41.     file.close();
  42.  
  43.    
  44.     file =SPIFFS.open("/test.txt");
  45.       //read
  46.       if(!file){
  47.       Serial.println("There was an error opening the file for reading");
  48.       return;
  49.     }
  50.     else
  51.     {
  52.       Serial.println("Opening the file for reading");
  53.     }
  54.     Serial.println("File Content : ");
  55.    
  56.     int i=0;
  57.     String s,p;
  58.     while(file.available())
  59.     {
  60.       if(i == 0)
  61.        s = file.readStringUntil('\n');
  62.       else
  63.        p = file.readStringUntil('\n');
  64.        i++;
  65.     }
  66.     file.close();
  67.     Serial.println(s.c_str());
  68.     Serial.println(p.c_str());
  69.   WiFi.softAP(s.c_str(),p.c_str());
  70.   Serial.print("Connecting to WiFi..");
  71.   // while (WiFi.status() != WL_CONNECTED) {
  72.   //   delay(500);
  73.   //   Serial.print(".");
  74.   // }
  75. }
  76.  
  77. void loop(){}
On execution the AP created ( client credentials passed) have a newline character at the end. How to remove the newline character from the end of the string?
wifi.JPG
wifi.JPG (15.44 KiB) Viewed 6812 times

boarchuz
Posts: 604
Joined: Tue Aug 21, 2018 5:28 am

Re: SSID and PASSWORD read from SPIFFS file contain newline

Postby boarchuz » Wed Sep 04, 2019 8:18 pm

file.println
file.print

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: SSID and PASSWORD read from SPIFFS file contain newline

Postby lbernstone » Thu Sep 05, 2019 1:14 am

s.trim();
p.trim();

Who is online

Users browsing this forum: No registered users and 50 guests