I have a few sketches doing what you want... I'm sending multiple 'commands' to spark. I created a Class to decode String messages. Here is an example:
In Header:
class httpCommand {
String argument;
public:
void extractValues(String);
String mssgCommand (void) {
return argument.substring(argument.indexOf("command#") + 8, argument.indexOf("#text="));
}
String mssgText (void) {
return argument.substring(argument.indexOf("#text=") + 6, argument.indexOf("#value0="));
}
int mssgValue0 (void) {
return (argument.substring(argument.indexOf("#value0=") + 8, argument.indexOf("#value1="))).toInt();
}
int mssgValue1 (void) {
return (argument.substring(argument.indexOf("#value1=") + 8, argument.indexOf("?"))).toInt();
}
};
//
void httpCommand::extractValues (String stringPassed){
argument = stringPassed;
}
In Setup:
Spark.function("httpRequest", httpRequest);
It is looking for me to send to Spark:
params=command#MY_COMMAND#text=MY_TEXT#value0=MY_INT#value1=MY2ND_INT?
it is certainly extensible...
I sort incoming commands like this:
Spark.function( ) function:
int httpRequest(String mssgArgs)
{
DEBUG_PRINTLN("command recieved...");
oldData = false;
lastDataTransmitTime = millis();
httpCommand command;
command.extractValues(mssgArgs);
DEBUG_PRINTLN(command.mssgCommand());
boolean badMessage = true;
for (int i = 0; i < NUMBER_OF_MESSAGE_TYPES; i++)
{
if (command.mssgCommand().equals(messageType[i]))
{
DEBUG_PRINTLN("Valid Message Recieved...");
DEBUG_PRINTLN("Message type:");
DEBUG_PRINTLN(command.mssgCommand());
DEBUG_PRINT("messgText = ");
DEBUG_PRINTLN(command.mssgText());
DEBUG_PRINT("messgValue0 = ");
DEBUG_PRINTLN(command.mssgValue0());
DEBUG_PRINT("messgValue1 = ");
DEBUG_PRINTLN(command.mssgValue1());
updateVariables(i, command.mssgText(), command.mssgValue0(), command.mssgValue1()); // Pass decoded variables to function
badMessage = false;
}
}
if (badMessage)
{
DEBUG_PRINTLN("non-conforming message attempt...");
return -1;
}
else return 1;
}
against an array of commands like this:
in the header:
const String messageType[NUMBER_OF_MESSAGE_TYPES] = {
"ledStatus", "alarmState", "garageState", "guestGarageState", "weatherCondition", \
"outsideTemp", "outsideHumid", "airconSetpoint", "weatherForecast", "messageData", \
"todayHigh", "todayLow", "windSpeed", "windDirection", \
"relayState", "brightLevel", "emailCount", "resetSpark", "resetHour" };