One more thing to know, in the above strings how would the RX end know that how many characters are to be separated to get 4 separate values? they are in an array so how come the RX know the length of each of the 4 fragments of the received string?
nightcrawler218:
One more thing to know, in the above strings how would the RX end know that how many characters are to be separated to get 4 separate values? they are in an array so how come the RX know the length of each of the 4 fragments of the received string?
The data is formatted by the sprintf() statement, and the resultant String (note the upper case 'S', it's an object that encapsulates a char array) is populated by the sscanf() statement.
Assuming the 4 values sent across are
Sensor1Data = 123
Sensor2Data = 45
Sensor3Data = 768
Sensor4Data = 93
The string (note the lower case 's'. it's an array of char) sent is "123,45,768,93," Note that the trailing comma is unnecessary.
The receiver receives the string, and the sscanf() knows the format, and converts the string to a String. When you correct the number of variables being sent and received, you should make the receiver's format string the same as the sender's. Either leave off the trailing comma in both, or leave it in both.
lar3ry:
The string (note the lower case 's'. it's an array of char) sent is "123,45,768,93," Note that the trailing comma is unnecessary.
You mean thisprintf(Sensor1CharMsg, "%d%d%d%d" , Sensor1Data, Sensor2Data, Sensor3Data, Sensor4Data);
instead of that?printf(Sensor1CharMsg, "%d,%d,%d,%d," , Sensor1Data, Sensor2Data, Sensor3Data, Sensor4Data);
In the RX node
In the first case what would be the terminating character that denotes end of 1data, 2data etc?
In the second case are the trailing commas terminating character?
No. Suppose that the values are 11, 22, 33, and 44. The statement you have will create a buffer containing "11223344". How are you going to then parse that? You have no idea where one value ends and the next begins.
No. Suppose that the values are 11, 22, 33, and 44. The statement you have will create a buffer containing "11223344". How are you going to then parse that? You have no idea where one value ends and the next begins.
It means in Tx node I have to put a comma in between 2 separate values like
It means in Tx node I have to put a comma in between 2 separate values like...and in the Rx mode the string will be cut down into pieces everytime it sees a comma inbetween the values ri8?
Declaration static void print_float(float val, float invalid, int len, int prec)
call print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
What is the last argument "prec" ? & what is that double colon thing "TinyGPS::GPS_INVALID_F_ANGLE"?
Now arduino seems bit harder to understand :-/
Because that is syntactically invalid. You are not understanding the formatting part, between the double quotes, and the list of variables containing values to be formatted.
What is the last argument "prec" ?
Because that makes more sense than calling the precision value waterBuffalo.
& what is that double colon thing
It's called a scope resolution operator. It tells the compiler the scope that the variable/value is defined in (TinyGPS in that case).