New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP Server example #82

Closed
briggsm opened this Issue Jun 7, 2014 · 7 comments

Comments

Projects
None yet
3 participants
@briggsm

briggsm commented Jun 7, 2014

It looks like (from your Adafruit CC3000 Wifi Shield & Breakout Board product pages) that the CC3000 supports: "TCP and UDP in both client and server mode". And your library currently supports: "UDP/TCP client & TCP server connections".

Is the UDP Server side of things a work in progress? Or is it something too complicated to implement?

I think I need a UDP server to be setup for what I'm trying to accomplish (and I'd think many other users would like to do as well) - I'd like to rapidly send "Color" packets to control your NeoPixel strips. I need at a MINIMUM 20 packets (colors) / second, though 30 or more would be best (no flickering). Using the TCP server method I got about 2 frames / sec, and with some hacking, got it up to about 5 frames / sec. (I may be doing something wrong, but I've even analyzed the TCP stream with Wireshark, and it appears the CC3000 side of things has about a 20ms delay before sending most or all of it's packets - which adds up to a lot of time pretty fast).

I have Javascript which AJAX calls a PHP script on a mouse move/drag event on a color swatch. The called PHP script gets the color and sends it out as a UDP packet to where ever you tell it.

I understand the UDP Server is not currently supported in the library, but if you could point me in the right direction (if possible) I would greatly appreciate it! Any solution to receiving ~20-30 packets / second of color (3 data bytes) packets would be great!

@tdicola

This comment has been minimized.

Show comment
Hide comment
@tdicola

tdicola Jun 7, 2014

Contributor

It's not in the library yet, but the CC3000 host driver exposes low level UDP socket functions you might be able to use. I haven't done a lot with them, but from what I understand you really only need the recv function to look for data on a listening UDP socket (vs. TCP sockets where you need to accept them, keep the connection alive, etc.).

Take a look at what I did with the mDNS responder to see how I listen on UDP port 5353 (it's listening for a special multicast IP, but I think you could just bind to address 0.0.0.0 instead of 224.0.0.251)--the relevant code is around line 151 to setup the listening socket, and then line 174 to check if data is available and read it: https://github.com/adafruit/CC3000_MDNS/blob/refactor_simplify/CC3000_MDNS.cpp

Hitting 30 packets/second could be tough. I haven't done a lot of stress testing the speed, but the CC3k isn't the fastest thing in the world. Everything that's received has to be shuttled around between the CC3k and the Arduino over an SPI bus a character at a time so that can hurt throughput.

Something that might help is if you can buffer multiple pixel color changes into a single request. You can only send/receive about 90 bytes at a time before filling the buffer though so be careful. The less packets you can send the better though since each packet has overhead of the CC3k notifying the Arduino, the Arduino reading it, etc. Good luck!

Contributor

tdicola commented Jun 7, 2014

It's not in the library yet, but the CC3000 host driver exposes low level UDP socket functions you might be able to use. I haven't done a lot with them, but from what I understand you really only need the recv function to look for data on a listening UDP socket (vs. TCP sockets where you need to accept them, keep the connection alive, etc.).

Take a look at what I did with the mDNS responder to see how I listen on UDP port 5353 (it's listening for a special multicast IP, but I think you could just bind to address 0.0.0.0 instead of 224.0.0.251)--the relevant code is around line 151 to setup the listening socket, and then line 174 to check if data is available and read it: https://github.com/adafruit/CC3000_MDNS/blob/refactor_simplify/CC3000_MDNS.cpp

Hitting 30 packets/second could be tough. I haven't done a lot of stress testing the speed, but the CC3k isn't the fastest thing in the world. Everything that's received has to be shuttled around between the CC3k and the Arduino over an SPI bus a character at a time so that can hurt throughput.

Something that might help is if you can buffer multiple pixel color changes into a single request. You can only send/receive about 90 bytes at a time before filling the buffer though so be careful. The less packets you can send the better though since each packet has overhead of the CC3k notifying the Arduino, the Arduino reading it, etc. Good luck!

@tdicola tdicola closed this Jun 7, 2014

@briggsm

This comment has been minimized.

Show comment
Hide comment
@briggsm

briggsm Jun 8, 2014

Thank you so much for your input & direction! Definitely helped get me off the ground again. For the record, without doing much else in code, except polling to see if any packets came in (using your method), I'm seeing about 60 packets / second (still just sending 3-byte packets). About double what I wanted. Now, I think the hard part might be keeping the rest of my code sleek enough so this number doesn't drop much below 30 packets / second. As soon as I get things working better, cleaner, and all together, I'll post some code in the forums, in case it might be useful to others. Thanks again!

briggsm commented Jun 8, 2014

Thank you so much for your input & direction! Definitely helped get me off the ground again. For the record, without doing much else in code, except polling to see if any packets came in (using your method), I'm seeing about 60 packets / second (still just sending 3-byte packets). About double what I wanted. Now, I think the hard part might be keeping the rest of my code sleek enough so this number doesn't drop much below 30 packets / second. As soon as I get things working better, cleaner, and all together, I'll post some code in the forums, in case it might be useful to others. Thanks again!

@tdicola

This comment has been minimized.

Show comment
Hide comment
@tdicola

tdicola Jun 8, 2014

Contributor

Awesome, glad I could help. Sounds like a really cool project!

Contributor

tdicola commented Jun 8, 2014

Awesome, glad I could help. Sounds like a really cool project!

@briggsm

This comment has been minimized.

Show comment
Hide comment
@briggsm

briggsm Jun 9, 2014

For the record, here's the post I put in the forums re: "UDP Server for CC3000":
http://forums.adafruit.com/viewtopic.php?f=25&t=55322

briggsm commented Jun 9, 2014

For the record, here's the post I put in the forums re: "UDP Server for CC3000":
http://forums.adafruit.com/viewtopic.php?f=25&t=55322

@briggsm

This comment has been minimized.

Show comment
Hide comment
@briggsm

briggsm Jul 11, 2014

Hi Tony, I've finally gotten my project in a state where I think it can be shared, and I created a tutorial (with video demos, pictures, and a "how-to"):

Tutorial: http://briggs-inc.com/blog/colorring/
ColorRing Library: https://github.com/briggsm/colorring
ColorRing CC Library: https://github.com/briggsm/colorringcc

The project, in a nutshell, is:
2 Adafruit NeoPixel LED strips, connected to Arduino board, controlled from a web browser, over Wi-Fi.
Use the web browser to create & send commands to the LED strips, as well as send real-time color data to the LED strips.

Thank you again for your great help in making this possible!

briggsm commented Jul 11, 2014

Hi Tony, I've finally gotten my project in a state where I think it can be shared, and I created a tutorial (with video demos, pictures, and a "how-to"):

Tutorial: http://briggs-inc.com/blog/colorring/
ColorRing Library: https://github.com/briggsm/colorring
ColorRing CC Library: https://github.com/briggsm/colorringcc

The project, in a nutshell, is:
2 Adafruit NeoPixel LED strips, connected to Arduino board, controlled from a web browser, over Wi-Fi.
Use the web browser to create & send commands to the LED strips, as well as send real-time color data to the LED strips.

Thank you again for your great help in making this possible!

@tdicola

This comment has been minimized.

Show comment
Hide comment
@tdicola

tdicola Jul 13, 2014

Contributor

Wow, that looks great! No problem, thanks for sharing it!

Contributor

tdicola commented Jul 13, 2014

Wow, that looks great! No problem, thanks for sharing it!

@Asherfri

This comment has been minimized.

Show comment
Hide comment
@Asherfri

Asherfri Dec 28, 2015

Guys, I am using the UDP server library. But for some reason after 5-10 minutes of operation, it stops responding. Even if I stay on idle for the whole period of time. When it doesn't respond, if I close the socket I am getting an error. If I open the socket again, I am back in business. Is there some mechanism driving the socket to sleep or idle?Any ideas?

Asherfri commented Dec 28, 2015

Guys, I am using the UDP server library. But for some reason after 5-10 minutes of operation, it stops responding. Even if I stay on idle for the whole period of time. When it doesn't respond, if I close the socket I am getting an error. If I open the socket again, I am back in business. Is there some mechanism driving the socket to sleep or idle?Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment