I would suggest moving these two lines from the beginning of the while loop to the end of the while loop. Since you are calling strtok twice before your first publish it would make sense that a is skipped.
There also seems to be a lot of work that appears superfluous
BTW, why return a non-interesting 1 when your code already produces a more useful value counter?
In addition, avoid delaying your Particle.function() for more than three seconds (if at all) as the cloud would expect to hear back from the call rather quickly before assuming a timeout error.
This would be a more straight forward way to do (pretty much) the same thing
int myFunction(const char* command) {
char cmd[strlen(command) + 1];
char msg[128];
int count = 0;
strncpy(cmd, command, sizeof(cmd)); // non-const copy is required for strtok()
snprintf(msg, sizeof(msg), "{\"size\": %d", strlen(cmd)); // avoid String concatenations wherever possible
for(char* tok = strtok(cmd, "_"); tok; tok = strtok(NULL, "_"))
snprintf(msg, sizeof(msg), "%s, \"var%d\": \"%s\"", msg, ++count, tok);
strncat(msg, "}", sizeof(msg)); // close the JSON string
Particle.publish(command, msg, PRIVATE); // only one publish for the entire result set
return count;
}
(this produces a JSON string for easy consumption on the receiving end)