I want to get two variables from a webform from the wifimanager sketch into a hardwareserial setting. I first had to convert the values char Baudrate to int BAUD and char Comsetting to uint32_t COMSETTING. When I fill in the form with different settings for baudrate and comsettings, the output from the hardware serial to the comport over wifi (accessable via telnet) differs.
When i use the fixed setting:
COM[1]->begin(UART_BAUD1, SERIAL_PARAM1, SERIAL1_RXPIN, SERIAL1_TXPIN, true); #define UART_BAUD1 BAUD // Baudrate UART1 #define SERIAL_PARAM1 SERIAL_7N1 // Data/Parity/Stop UART1 #define SERIAL1_RXPIN 18 // receive Pin UART1 #define SERIAL1_TXPIN 15 // transmit Pin UART1 #define SERIAL1_TCP_PORT 23 // Wifi Port UART1
everything works fine and I get the output from the hardwareserial in a telnetsession.
I think there is something wrong with the conversion of the SERIAL_PARAM1 SERIAL_7N1 wich I want to set via the webform and the setting that sets the baudrate.
void comsetup_setup()
{
if (Comsetting == "7E1"){
#define SERIAL_PARAM1 SERIAL_7E1
}
if (Comsetting == "8N1"){
#define SERIAL_PARAM1 SERIAL_8N1
}
}
That is not how you compare strings in C/C++
Also, #defines are a compile time constant, that code runs at execution time so you can't change Comsetting on the fly and expect your code to change compile time constants.
{
if (Comsetting == "7E1"){ #define SERIAL_PARAM1 SERIAL_7E1
}
if (Comsetting == "8N1"){ #define SERIAL_PARAM1 SERIAL_8N1
}
}
That is not how you compare strings in C/C++
Also, #defines are a compile time constant, that code runs at execution time so you can't change Comsetting on the fly and expect your code to change compile time constants.
I understand. I'm new to this. What would be a better way to get the parameters for the hardwareserial from the web form?
You can use 'if' statements to control which value is assigned to the 'settings' variable. But, as already pointed out, your attempt to compare c-strings is incorrect. Fix that first.
You can ignore the if statement, i didn't refer to it in the sketch, I forgot to remove it.
When you look at the attached sketch you see that I have a variable in the webform Comsetting (char) wich I convert with uint32_t COMSETTING = atol(Comsetting); to uint32_t.
I then try to use the converted COMSETTING to set the hardwareserial.
So when I fill in the Comsetting webform with SERIAL_8N1 (char) it is converted to COMSETTING (uint32_t)
I think the Baudrate (char) to BAUD (int) already works but I'm not sure.
in your Bridge sketch, you are comparing Comsetting to strings (incorrectly)
void comsetup_setup()
{
if (Comsetting == "7E1"){
#define SERIAL_PARAM1 SERIAL_7E1
}
if (Comsetting == "8N1"){
#define SERIAL_PARAM1 SERIAL_8N1
}
}
which is it? What exactly are the contents of the variable Comsetting? if it is a string like "8N1", then converting that to a long int will give you the value 8 which is totally wrong.
You need to define a variable
uint_8_t ComValue; // don't know if this is the correct type
void comsetup_setup()
{
if (strcmp(Comsetting,"7E1") == 0 ){
ComValue = SERIAL_7E1;
}
if (strcmp(Comsetting,"8N1") == 0){
ComValue = SERIAL_8N1;
}
//...
COM[1]->begin(BAUD, ComValue, SERIAL1_RXPIN, SERIAL1_TXPIN, true);
}
rwanrooy:
You can ignore the if statement, i didn't refer to it in the sketch, I forgot to remove it.
When you look at the attached sketch you see that I have a variable in the webform Comsetting (char) wich I convert with uint32_t COMSETTING = atol(Comsetting); to uint32_t.
I then try to use the converted COMSETTING to set the hardwareserial.
So when I fill in the Comsetting webform with SERIAL_8N1 (char) it is converted to COMSETTING (uint32_t)
I think the Baudrate (char) to BAUD (int) already works but I'm not sure.
You are confusing a string "8N1" with a compiler constant SERIAL_8N1 with the value of said constant (0x06)
It worked for some time but I changed something in the sketch but I don't know what. I am searching for it for some time now but don't know what's wrong.
I managed to set the ComValue and the comport setting changed to the configured value. Now I am not able to set it anymore with the 7E1 or 8N1. I attached the code again.
We need to understand the meaning of the following declaration before we assign any value to it.
uint32_t ComValue;
The above declaration can also be written as:
unsigned long int ComVlaue;
The 'unsigned long int' type says that only a positive numerical value of the range (0x00000000 to 0xFFFFFFFF = 0 to 4294967294) could be stored in the variable ComValue.
Does this quantity: SERIAL_7E1 evaluate to a numerical value? If not, how can we assign/store this value in a variable like 'unsigned long int ComValue'?