I got a an issue trying to use enum - first time to use it. That's why. I am not actually a developer so that may add up too.
I'll let you have a look at the code and will tell you my issue at the end.
void loop(){
if(esp8266.available()){
//read what's being sent from the ESP Module something like "SwitchThirteen,LOW"
String Recieved_Msg = esp8266.readString();
//split the messages
String SwitchNumber = getValue(Recieved_Msg, ',', 0); // SwitchNumber=SwitchThirteen
String State = getValue(Recieved_Msg, ',', 1); // State=LOW
Serial.println("Switch Number: " + SwitchNumber);
Serial.print("State: " + State);
Recieved_Msg = "";
TurnOnOffSwitch(SwitchNumber, State);
}
}
Here's where the problem shows up
I am trying to print the values of switch numbers respectively i.e SwitchOne should print 1 and SwitchTwo should print 2 so that eventually I will turn the actual pins HIGH/LOW based on what is coming from loop function.
The problem is that I am always getting a zero "0"
You pass SwitchNumber, a String, into your TurnOffSwitch function and then do nothing with it.
You create an enum variable named Switch but never assign it a value. Since it is a local variable the value will be whatever was on the stack.
To translate names into numbers you need a list of strings containing the names. An enum is NOT a list of strings. It is a list of variable names, each assigned a small constant integer value.