The article on the 433 MHz radio was great. In the program a string containing humidity and temperature information is transmitted to the receiver, where it is put back together and result printed. I understand (roughly) how it is done for TWO items but how would one code for THREE or more items. I tried using the StringSplitter library but that was even more confusing since the example was all in one program file. I'm using Arduinos UNOs (and C++). Anyone?
I don't know what article on the 433 MHz radio you are referring to?
If I could see the relevant code example it would help.
Splitting strings isn't hard and I wouldn't bother with a library myself.
Looking at the StringSplitter example it looked simple enough to use.
String str1;
String str2;
String str3;
// The entire message is in the String str_out
// Split string into three values
// First, find the offsets of the two commas
int comma1 = str_out.indexOf(",");
int comma2 = str_out.index(",", comma1+1);
// Then extract the substrings
str1 = str_out.substring(0, comma1); // before first comma
str2 = str_out.substring(comma1+1, comma2); // between the two commas
str3 = str_out.substring(comma2+1); // after the second comma
Something else to consider:
int day, year;
char weekday[20], month[20], data[100];
strcpy(data,"Friday,February,14,2019");
sscanf(data, "%[^,],%[^,],%d,%d", weekday, month, &day, &year );
SpoilerAbout [^],The parser %[^], instructs the sscanf function to read characters other than comma until you get to a comma. This is not needed if the data is delimited by white-space - i.e. "%s %s %d %d" works otherwise.
It looks fine, except for the line, which should be using the same function:
int comma2 = str_out.indexOf(",", comma1+1);
If that's all you want to do then this is fine, and reasonably safe.
Cheers!
Thanks Mark. That's what I wanted. I was close. Your code looks simpler than original offering. Haven't tried it yet, but it gives me ideas...
Mark, your code works. At first my last entry (volts) ended with a bunch(5 or 6) of odd characters, so I changed this line: uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; to this line: uint8_t buf[16];, guessing that the buffer size was (3x5)+ 1 for null character. This cleaned it up. My question is why the first statement didn't work (taken from RadioHead library)?
Complete code here: