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

Code: Untitled.cpp Select all

#include "SPIFFS.h"
#include <WiFi.h>
void setup(){
File file;
Serial.begin(115200);

if(!SPIFFS.begin(true)){
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}


file = SPIFFS.open("/test.txt", FILE_WRITE);
if(!file){
Serial.println("There was an error opening the file for writing");
return;
}
else
{
Serial.println("Opening the file for writing");
}
String ssid= "MAD";
String pass = "1234567890";
if(file.println(test))
{
Serial.println("SSID Written");
}

//file.close();
file = SPIFFS.open("/test.txt",FILE_APPEND);
if(!file){
Serial.println("There was an error opening the file for appending");
return;
}

if(file.println(test2))
{
Serial.println("Password Was Written");
}

file.close();


file =SPIFFS.open("/test.txt");
//read
if(!file){
Serial.println("There was an error opening the file for reading");
return;
}
else
{
Serial.println("Opening the file for reading");
}
Serial.println("File Content : ");

int i=0;
String s,p;
while(file.available())
{
if(i == 0)
s = file.readStringUntil('\n');
else
p = file.readStringUntil('\n');
i++;
}
file.close();
Serial.println(s.c_str());
Serial.println(p.c_str());
WiFi.softAP(s.c_str(),p.c_str());
Serial.print("Connecting to WiFi..");
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
// }
}

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 7340 times

boarchuz
Posts: 656
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: 1131
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: PerplexityBot, Semrush [Bot] and 4 guests