I am having issues with string assignment and manipulation issues. My environment is:
- Mostly class based.
- Arduino Ethernet board
- Using the latest version of IDE(1.6)
- Developing using VisualMicro
void RelayDevice::update(Controller<PowerDevice, SwitchEthernet> *control)
{
Serial.println("Device update called");
Serial.println(control->htmlPage);
String rawCommand = String(control->htmlPage);
Serial.println(rawCommand);
int ind1 = rawCommand.indexOf("?");
int ind2 = rawCommand.indexOf("HTTP/1.1");
Serial.print("Index1: "); Serial.println(ind1);
Serial.print("Index2: "); Serial.println(ind2);
String command = rawCommand.substring(ind1, ind2);
Serial.print("Command: "); Serial.println(command);
command->trim();
control->returnPage = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <datavalues><relay1state>1</relay1state></datavalues>";
}
Here’s the output: [Comments]
Device update called Function is called properly by event controller.
GET /?get HTTP/1.1 HtmlPage is set properly
Should be assigned and same as htmlPage
Index1: -1 Should have value 5
Index2: -1 Should have value 10
Command: Should have value get
Sending data Event manager calls TcpClient flush.
I dont understand why the control->htmlPage is not getting assigned to rawCommand. Even if i directly use the control->htmlPage the indexOf doesnt work.
Maybe I have forgotten C++ or its just one of those small programming bugs that give you nightmares. Please help… need to develop this urgently.