I'm playing with the CC3000 card and the Adafruit's CC3000 library. The data actually gets across to the server, however because it's a proprietary protocol I can't use one of the "prepackaged" protocols like http. I'm simply sending a string using the client.println(). I expected the string to be in one packet as it is relatively short, app 100-150 chars. The result was surprising - the library creates one packet for each character I send.
Here's a sample string:
$-1|0.00|0.00|0|0.00|-1|0.00|0|48.28|75.88|0.00|0.00|98657.25|4.15|0.99@
Yep what you're seeing is a side effect of how the Print class (which implements the print and println functions) is implemented in Arduino. It will go through character by character and call a lower level write which ends up sending each character as a different packet with the CC3000 client. Definitely not the best option for speed. :) Luckily there are a couple functions on the CC3000 client you can use instead for better performance.
Try switching to use client.fastrprintln instead of client.println. Likewise you can use client.fastrprint instead of client.print. This will take the entire string and send it in one go instead of breaking it down character by character.
One thing to be aware of though is that there's a limit to how much you can send in one packet. It's based on the memory available to the CC3000 buffer and on an Arduino it's 90 characters, so make sure a single fastrprint or fastrprintln doesn't send more than 90 characters at a time. If you hit this limit unfortunately the Arduino will lock up because the driver code goes into an infinite loop to prevent overwriting random parts of memory.
tdicola wrote:
Try switching to use client.fastrprintln instead of client.println. Likewise you can use client.fastrprint instead of client.print. This will take the entire string and send it in one go instead of breaking it down character by character.
Thanks, I'll try this and report back. Is there a documentation for the library somewhere? I'm ok in C, but not really good in even reading the libraries and/or C#.
tdicola wrote:
One thing to be aware of though is that there's a limit to how much you can send in one packet. It's based on the memory available to the CC3000 buffer and on an Arduino it's 90 characters, so make sure a single fastrprint or fastrprintln doesn't send more than 90 characters at a time. If you hit this limit unfortunately the Arduino will lock up because the driver code goes into an infinite loop to prevent overwriting random parts of memory.
Yup, I heard about this one. However, I assume the 90 byte limit applies to payload only, right?
The examples included in the library are the best documentation of the usage. The library is ultimately a wrapper around the lower level CC3000 host driver functions from TI which are documented here: http://software-dl.ti.com/ecs/simplelin ... index.html
Yep the 90 byte limit is for the payload of a single fastrprint/write call. In reality the buffer is a bit larger (~130 characters) but some of that space is used up with headers talking to the CC3000 so you're left with 90 bytes of payload data.
The error you see is from no fastrprint overload being available that takes in the Arduino String class as a parameter. The String class can be problematic because it dynamically allocates space under the covers, so if you do a lot of string manipulation (like concatenating strings together) in a loop you can quickly fragment the heap and run out of memory (there's only about ~1k of memory free on a normal Arduino after the buffers, etc. are taken). Most folks end up pulling out String class usage and switching to C strings/character arrays with the typical string.h functions. However with Arduino 1.05+ it looks like the String class lets you get at the string as a c string using the c_str() function, so try switching to call fastrprintlin like: client.fastrprint(reading.c_str()).
BRAVO!!! The sketch compiled. Thank you very much to get me through this hurdle. I still have to test the functionality, but at least I have a workable code now.