understanding how CC3000 udp client works

Status
Not open for further replies.

mortonkopf

Well-known member
hello all, I need some help in understanding some of the basics with the CC3000. It could easily be that I have not understood the basics of how network dialogue works, its all new to me. I have the breakout board set up and working with Teensy 3.0, i can run the various tests which work giving the appropriate responses tot he serial monitor, and I can use jesperravn's tweaks to set a static IP address on the module. I am running an application on my macbook that spits out information to a given IP and port. My question is, can I set up the cc3000 module to listen for this info and print to the serial port by simple setting up a client and println? Would more of a "pairing process" to the send computer be required?

something like this:
Adafruit_CC3000_Client client;

and then in the loop:

if(client.available()) {
client.read(packetBuffer, sizeof(packetBuffer));
Serial.println(F(packetBuffer));
}

Of course, all the defines for cc3000 and begin() etc would be included.

thanks for any help
mortonkopf
 
Last edited:
For UDP, you have to tell the cc3000 what port you are expecting to see UDP packets and bind to it, then you can just do a recvfrom() to get packets sent to that port. So if you were expecting UDP packets on port 8888, you might do

Code:
     sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    memset(&socketAddr, 0, sizeof(sockaddr_in));
    localPort = 8888;
    socketAddr.sin_family = AF_INET;
    socketAddr.sin_addr.s_addr = 0;
    socketAddr.sin_port = htons(localPort);
    bind(sockfd, (sockaddr*)&socketAddr, sizeof(sockaddr_in));
...
    sockLen = sizeof(sockaddr_in);
    bytes = recvfrom(sockfd, buff, sizeof(buff), 0, (sockaddr*)&from, &sockLen);

For TCP, the incantations are a little different (see the CC3000 examples)
 
Manitou, I am still working my way through this, so I have not forgotten about it. Lots of new stuff to get into with regards to pointers and buffers. I have used them before with my poi project, but this is a bit more complex. Going well, apart from this one section:

sockaddr*)&from

The TI docs have this info, but I am struggling with how to use/declare the &from pointer in the "sockaddr * from" :
int recvfrom ( long sd , void * buf , long len , long flags , sockaddr * from , socklen_t * fromlen );
/* sd specifies the socket handle. */
/* buf points to the buffer where the message should be stored. */
/* len specifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-1460 bytes. */
/* flag specifies the type of message reception. On this version, this parameter is not supported. */
/* len specifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-1460 bytes. */
/* from is a pointer to an address structure indicating the source address: sockaddr. */
/* On success the return return the number of bytes received. On error, -1 is returned. 0 if timeout occurred. */

Thanks for any pointers on pointers.
 
Code:
    sockaddr_in         socketAddr, from;
    socklen_t           sockLen;

recvfrom() will write the senders IP and port number into the from structure.

you need to read about the BSD socket library. It's not a very elegant interface, but it's an old "standard".
 
Manitou,

thank you for the help and direction, I have managed to get my way through this, although I am still a bit hazy on Berkeley sockets, but then, there are things that I do not need to get into right now, I'll save it for another time. Anyhow, I have the Teensy 3.0 receiving UDP packets being pushed out of the macbook, and the contents are being printed over serial.

Next step, some fun with led manipulation.

all the best
 
Why does a buffer of greater than [64] cause a hang?

Well, thanks all for the UDP help. I have the CC3000 breakout board happily receiving UDP packets from michu's pixelcontroller software, which sends out led data for and 8*8 array. I am using that software to send led colour data to the static IP address of the CC3000 wifi breakout board, and am testing the receipt by printing to serial monitor. It is currently working at 40 frames a sec, the leds look ok, but I have not been checking for lost data)

I am stumped, however, but the sketch failing if I increase the buffer size that receives the incoming data to more than 64. I think I read on the forum that this was to do with a declaration in a core lib, but I can't find the post again. Any help in finding it would be great.

If you are interested in the sketch for setting up the cc3000 with a static IP address, setting a port, binding it, and streaming the received data to serial, here it is.

View attachment cc3000_receive_UDP_test.ino

the sketch opens a port named 2811 on a static address of 192.168.1.10. Software on the macbook sends out packets to this address and port over the router. Also, there is no checking of receipt at the moment, or checking for ordering from the router (although the ability for this is contained within the TPM2 protocol that the UDP packets sit within from the pixelcontroller software.

Oh, NB, the use of static address requires some code changes to the core lib (http://forums.adafruit.com/viewtopic.php?f=31&t=47004
)
 
Last edited:
I am stumped, however, but the sketch failing if I increase the buffer size that receives the incoming data to more than 64. I think I read on the forum that this was to do with a declaration in a core lib, but I can't find the post again. Any help in finding it would be great.

The default TX/RX buffer sizes for the CC3000 is 131 bytes (examples/buildtest reports value). I was able to send/receive up to 80 bytes (UDP), so I'm not sure why your 64-byte test would fail. The buffer sizes are set in utility/cc3000_common.h in the CC3000 library, so you can increase them there. There was also a bug in the SPI transfer loop (only used uint8_t for loop) so that even with bigger buffers, sketch would hang because of loop bug. You need to get the latest version of CC3000 library from github
https://github.com/adafruit/Adafruit_CC3000_Library

I have successfully sent/received 1000-byte UDP packets.

i'll need to try your static IP. When I tried static IP, DNS failed (gethostbyname() returned 0), but I did have a static IP for the CC3000 ...
 
manitou, thanks, i just found the other thread…

Replaced lib with updated github but problem of >64 byte buffer remains. I think that may I need to look into the pixelcontroller software to dig into the TPM2 protocol that is being used, but that shouldn't really make a difference.

RE static IP, the sketch setting the cc3000 board IP used modified cc3000.cpp and h files discussed here:
http://forums.adafruit.com/viewtopic.php?f=31&t=47004, and I have only used it to accept UDP packets from the computer software where the IP and port are explicitly declared as the address to send to.
 
Success. Thanks yet again for your help manitou. I went back and deleted all old copies of CC3000 folders and rebuilt the library, and now all functions well with large buffer sizes after changing the RX TX values in the common.h file. The Teensy 3.0 will now update the small (16*8) led array using octows2811 by receiving data wirelessly through the router. It is currently working at 40 fps (seems to be! no checking for dropped data)

phew!

next step is to look at the large array -universes issues.
thanks for your time and support
 
Last edited:
Status
Not open for further replies.
Back
Top