Any pointer on converting my query string to a character array?
Afterthought, I thought text strings in C were character arrays?
The String type is not the same as string type.
With character arrays, sprintf is your friend!
char query[64];
int stuffInt = 32;
char stuffString[32] = "This is just stuff";
sprintf(query,"Stuff I want to send: %d and %s",stuffInt,stuffString);
Serial.println(query);
It won't do floating point. You can do floats with a different function tho.
Thanks for that, however something I am forgetting is the fact that I have to have a query "string" there is no way round that, char arrays wont help.
The query string is what is used in the the HTTP post request to post the data to a web site, that query has to be a url encoded string, it cant be anything else.
My problem was running out of memory when trying to put that query string together "if" there was also a whole lot of other serial.print strings happening at the same time.
I think that problem would exist whether I was using normal strings or char arrays, if there is not enough memory to deal with it all it will crash, or am I wrong?
I am taking the byte array data from the xbee response and putting it into the query string directly and then posting it, I dont see how using char arrays in this scenario will help?
Thanks for that, however something I am forgetting is the fact that I have to have a query "string" there is no way round that, char arrays wont help.
The query string is what is used in the the HTTP post request to post the data to a web site, that query has to be a url encoded string, it cant be anything else.
That is a query "string", not a query "String". I use this all the time, and I do not use Strings. They crash. I use character arrays. The server does not know the string was assembled in a character array or a String, as long as it has no illegal characters in it.
The String variable is just a dynamically allocated character array, except it doesn't release the dynamic memory correctly, which causes the crashes. The example I posted above is exactly what I use to construct a query.
I can usually tell by looking into a friend's eyes, and they have "glazed over", that my answer has exceeded their capability to understand. I can't see your eyes.
Nothing is "tagged on" after the HTTP/1.0. Those variables are inserted into that "query string" at the %i for stuffInt, and at the %s for stuffString. This is what the server sees:
GET /mypage.php?oneParam=32&twoParam=This+is+some+stuff HTTP/1.0
For now the code appears stable, what I need to do going forward is work out how to use "string" not "String" and char arrays correctly, and convert all my Strings to char arrays as you suggest, this I am sure will go a far way to making the code even more stable.
To be honest when I first tried using char arrays with my code it was the defining the size of the array that got me, and the reason why I went to dynamic "Strings".
My xbee data was changing ever so slightly, the first bit, timestamp, flag and doors were fixed size but the 10 temp floats were changing in size, could be a -127.0 for a faulty or disconnected sensor, right up to 127.0 and anything in between.
This resulted in bad data for me, I now know I was just not doing it right!
You would have been doing it right with the String variable if that type worked correctly with Arduino, but it doesn't, so we are stuck with character arrays until they get the bug out.