cc3000 recvfrom question

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
exoseleton
 
Posts: 1
Joined: Thu Jun 05, 2014 9:54 am

cc3000 recvfrom question

Post by exoseleton »

Hello,
I currently have an uno with an ethernet collecting data from the serial port, en simultaniously listening for an udp packet.
When recieved it sends the data collected from the serial as 1 or more udp packets to the ip of the recieved packet.

I just got the cc3000 wifi breakout, and have succeeded to receive the udp packet using the "recvfrom" function.

But this function halts execution of the for loop.
Is there a way to check for incoming packets and keeping the loop running?
Like this for the ethernet shield:

int packetSize = Udp.parsePacket();
if(packetSize){
}

thanks

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: cc3000 recvfrom question

Post by adafruit_support_rick »

As you have discovered, recvfrom only supports blocking mode. However, you can use setsockopt to set a timeout on receives. recvfrom will return 0 if it times out.
Here's a snippet of code from the sntp library:

Code: Select all

	int32_t				recvTimeout = 30000;
 . . .    . . .
	setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout));
	byteCount = recvfrom(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, &sockLen);

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”