I'm attempting to send data from a serial connection to a GSM modem, but having problems. The string from rx looks like this:
1.0 2.0 3.0 4.0
Here's my code to replace the spaces and then I just want to pass the whole string on, regardless of what's inside (there could be negative values too).
data_current[data_index++] = ',';
char received = bike_port.read(); //bike
char test[32];
inData += received;
if (received == '\n')
{
String nospace = inData;
nospace.replace("\t",",");
debug_println("Data: ");
debug_println(nospace);
inData = ""; // Clear recieved buffer
delay(1000);
}
sprintf(test,32,"%d,%d,%d,%d",(String) nospace);
//strtok(received, tmp);
for (int i=0; i<strlen(test); i++) {
data_current[data_index++] = test[i];
}
I have also tried
sprintf(test,32,"%ld,(String) nospace);
What I get now is this error
cannot pass objects of non-trivially-copyable type 'class String' through '...'
Without the sprintf line I can successfully echo the string to debug_println (Serial Monitor). What am I doing wrong?
sprintf()
line doesn't seem to make sense. What are you trying to get it to do?