Changing Config parameter in Serial.begin

I am getting an error when I try to do the below thing.

String mconfig = “SERIAL_8E1”;

Serial.begin(9600,mconfig);

error I get is “no matching function for call to ‘HardwareSerial::begin(int&, String&)’”

I am using ESP8266.

Thanks

Right. Because SERIAL_8E1 is not a string, it is a defined constant. What are you trying to do by passing mconfig? You can dig into the serial code and find the defined type of SERIAL_8E1 or the second parameter of begin(), then you can define mconfig as a variable of that type.

HardwareSerial::begin(int&, String&)

It says its a string, am I understanding it wrong ?

Hardwareserial.cpp

Hardwareserial.h

Thanks

I_think:
HardwareSerial::begin(int&, String&)

Where are you seeing that? I don't see anything like that at those links. Here is the function signature:

void begin(unsigned long baud, SerialConfig config)

So ,how should I do ?

I want to dynamically change configuration. say from SERIAL_8N1 to SERIAL_7E1, or some other which user wants to configure.

Thanks

give the user the option to choose one element of the enumeration SerialConfig
https://github.com/esp8266/Arduino/blob/007e495e0d88eabc6dae31fad311df38f8914607/cores/esp8266/HardwareSerial.h#L35

and handover the CONTENT of the chosen option to

void begin(unsigned long baud, SerialConfig config)

not the name of the choosen enumeration!

i.e. on a webpage let the user choose from a html select-tag.

<select id="config">
  <option value="42">7E1</option>
  <option value="9">8E1</option>

42 and 9 are just example numbers, you will print them to your html with the enumeration anyway.

If my answer is not clear enough, make a SMALL compileable sketch showing your option setting and we might give a more detailed answer.

Please If you could help with example sketch. I am not using HTML. I will receive setting as an mqtt message.

Thanks.

I'm not using mqtt.

come up with a sketch where you receive a variable byte mconfig; and then use a switch case.

If my answer is not clear enough, make a SMALL compileable sketch showing your option setting and we might give a more detailed answer.

I_think:
So ,how should I do ?

I want to dynamically change configuration. say from SERIAL_8N1 to SERIAL_7E1, or some other which user wants to configure.

Thanks

I already told you what to do...

SerialConfig mconfig;
[...]
mconfig = SERIAL_8E1;
[...]
Serial.begin(9600,mconfig);

noiasca:
I’m not using mqtt.

come up with a sketch where you receive a variable byte mconfig; and then use a switch case.

I am using a temporary code to solve the purpose. but is looking for something right way to do. here is it

  if ( SerConfig == "8N1"){ Serial.begin(_BaudRate,SERIAL_8N1);}
  if ( SerConfig == "8E1"){ Serial.begin(_BaudRate,SERIAL_8E1);}
  if ( SerConfig == "8O1"){ Serial.begin(_BaudRate,SERIAL_8O1);}
  if ( SerConfig == "8N2"){ Serial.begin(_BaudRate,SERIAL_8N2);}
  if ( SerConfig == "8E2"){ Serial.begin(_BaudRate,SERIAL_8E2);}
  if ( SerConfig == "8O2"){ Serial.begin(_BaudRate,SERIAL_8O2);}
  if ( SerConfig == "7N1"){ Serial.begin(_BaudRate,SERIAL_7N1);}
  if ( SerConfig == "7E1"){ Serial.begin(_BaudRate,SERIAL_7E1);}
  if ( SerConfig == "7O1"){ Serial.begin(_BaudRate,SERIAL_7O1);}
  if ( SerConfig == "7N2"){ Serial.begin(_BaudRate,SERIAL_7N2);}
  if ( SerConfig == "7E2"){ Serial.begin(_BaudRate,SERIAL_7E2);}
  if ( SerConfig == "7O2"){ Serial.begin(_BaudRate,SERIAL_7O2);}

Really, you are still looking for the right way to do it? Did you read reply #8?

Where does SerConfig come from, by the way?

aarg:
Really, you are still looking for the right way to do it? Did you read reply #8?

Where does SerConfig come from, by the way?

That was a reply to previous. The forum rules are blocking me for posting messages. I have to wait for sometime before I post next (reply to you).

I will check and reply.

OK

So mqtt message gives me a string for setting eg. "8N1".
Which I store in string SerConfig.