1
\$\begingroup\$

Is this the proper use for switch case? I am looking to make a simple utility for reporting back Wireless AP info, Baud Rate, and Mode of a ESP8266 module.

When the program loads it gives the user a small menu of option and based on the input of the user (1,2 or 3) it will run the associated AT command stored as a variable in the code.

Will this work as is? Or am I missing something to send the command and get the data back?

void loop() {

if (Serial.available() > 0) {
input = Serial.read();
Serial.flush();

switch (input) {
  case '1':
      Serial.println(baud);
      break;

   case '2':
      Serial.println(wap);
      break;

   case '3':
      Serial.println(amode);
      break;

   default:
      Serial.print("'");
      Serial.print((char)input);
      Serial.println("' is not a command!");
}
 }
}

The baud, wap, and amode commands are setup as follows:

const char* wap = "AT+CWLAP";
const char* baud = "AT+CIOBAUD";
const char* amode = "AT+CWMODE";
\$\endgroup\$
  • \$\begingroup\$ I am stuck. The code works to send the commands to the serial monitor but it's not returning the information it should. It just shows the command. \$\endgroup\$ – Das Nuk Mar 5 '18 at 22:12
  • \$\begingroup\$ I can post my full code if that would help. \$\endgroup\$ – Das Nuk Mar 5 '18 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.