string - getting the last 9 digits of a char buffer in Arduino -
in previous code of mine, using following line of code last 9digits of "command" string
if(command.indexof("kitchen light: set top color") >=0) {oncolorvaluered = (command.charat(28)- 48)*100 + (command.charat(29)- 48)*10 + (command.charat(30)- 48);}
now using char buffer (char packetbuffer[udp_tx_packet_max_size];) , using above code not work since packetbuffer not string, how please go this
try defining function search string
int indexof_for_char(const char *str, int str_length, const char *target) { // naive method (int index = 0; index < str_length; index++) { int j; // check if matched (j = 0; target[j] != '\0' && index + j < str_length && str[index + j] == target[j]; j++); // if matched, return index if (target[j] == '\0') return index; } return -1; }
and using subscripting.
if(indexof_for_char(packetbuffer, udp_tx_packet_max_size, "kitchen light: set top color") >=0) {oncolorvaluered = (packetbuffer[28]- 48)*100 + (packetbuffer[29]- 48)*10 + (packetbuffer[30]- 48);}
Comments
Post a Comment