CC3000 UDP - multicast, broadcast?

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jrjbertram
 
Posts: 7
Joined: Sat Nov 02, 2013 7:15 pm

CC3000 UDP - multicast, broadcast?

Post by jrjbertram »

Hi,

I'm trying to create a "UDP serial console" for my Arduino Due + CC3000. I currently have a TCP based version that works well, except I don't like having to reconnect my telnet session every time I power cycle/reprogram my Arduino.

I've been working on getting a UDP based version, but have run into several issues I'm hoping someone has some ideas on.

1) I can't see UDP sendto traffic on wireshark.

My linux laptop (192.168.1.100) is running wireshark and recording traffic. I created a simple Stream class that calls "sendto" each time a Stream::write call happens. Return values are coming back as success from the sendto call.. have checked and recheck arguments... can't find what I'm missing.

Source is located at:
https://github.com/jrjbertram/robotomy/ ... dpStream.h
https://github.com/jrjbertram/robotomy/ ... Stream.cpp

Relevant code snippet:

Code: Select all

size_t UdpStream::write( uint8_t data)
{
  Serial.println( "write: entry" );
  
  sockaddr_in address;
  memset(&address, 0, sizeof(address));
  address.sin_family = AF_INET;
  address.sin_port = htons(_port);
  // JRB: Need to figure out how to set this to broadcast, or maybe a multicast address
  address.sin_addr.s_addr = 0xE1000025;  // multicast 225.0.0.37
  //address.sin_addr.s_addr = 0xC0A80164;  // 192.168.1.100, laptop addr
  socklen_t len = sizeof(address);


  Serial.println( "calling sendto" );
  int n = sendto(_socket, &data, 1, 0, (sockaddr*)&address, len);
  Serial.print( "sendto returned " );
  Serial.println( n );  // returns 1

  // snip
I've seen in the past that unicast UDP can be filtered by a switch, but Wireshark is running on the laptop I'm expecting to see the UDP traffic directed to. Just to be double-sure, I pulled in ping code from the WebClient example, and I do see the ICMP messages show up in Wireshark. Likewise, I can see HTTP traffic when I tweak the IP address to point to my laptop.

Interestingly, I tried tweaking one of the UDP-based NTP examples, but did not see any UDP traffic (even though it seemed to work). Not 100% sure I modified that example correctly, so ... hrmm.

Anyone know if this is normal? I'm also sniffing on the wireless lan interface.. not sure if that makes a difference.

2) I can't find a good example of how to use broadcast address or multicast address.

In the sendto snippet above, I've attempted to set to my broadcast address on my local network (192.168.1.255) and tried a random multicast address (225.0.0.37). Didn't see either on the wireshark trace.

3) Is anyone aware of a good / simple UDP client example? There seems to be lots of discussion of a UDP server, but I didn't see much in the way of client discussion. I'm aware that the NTP clients are UDP-based, they just have a lot of complexity. Looking for something simple.


Goal eventually here will be to power up the board, have a python script monitor on a broadcast or multicast address... this will allow me hopefully to untether from USB but still provide me a simple way to pass in commands and peek/poke at status of my project wirelessly. Might also try to hook up to something that already works, such as http://www.cinetix.de/interface/tiptrix/udpterm.htm


Thanks in advance,
- Josh.

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

Re: CC3000 UDP - multicast, broadcast?

Post by adafruit_support_rick »

Is Wireshark set to 'promiscuous mode'?

User avatar
jrjbertram
 
Posts: 7
Joined: Sat Nov 02, 2013 7:15 pm

Re: CC3000 UDP - multicast, broadcast?

Post by jrjbertram »

Sorry - yes, set in promiscuous mode. I see lots of traffic from various devices on my home network.

Its probably worth pointing out that I do see ARP requests from my cc3000 as well at startup.

I know that UDP packets can be dropped at will by any switch/router along the line... I've been assuming this wasn't occurring because I'm seeing my ping packets... I guess that's not any guarantee though.

Thanks for the reply.

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

Re: CC3000 UDP - multicast, broadcast?

Post by adafruit_support_rick »

Seems like you should be seeing UDP packets. If the NTP stuff is working, then they must be going out. It must be some sort of configuration problem in WireShark.

User avatar
jrjbertram
 
Posts: 7
Joined: Sat Nov 02, 2013 7:15 pm

Re: CC3000 UDP - multicast, broadcast?

Post by jrjbertram »

I figured out what I was doing wrong. I was attempting to hard code my IP address, but stupidly did not byte swap. The below snippet shows the correct byte swapping.

Code: Select all

  sockaddr_in address;
  memset(&address, 0, sizeof(address));
  address.sin_family = AF_INET;
  address.sin_port = htons(5005);
  // JRB: Need to figure out how to set this to broadcast, or maybe a multicast address
  //address.sin_addr.s_addr = 0xC0A80164;  // 192.168.1.100... laptop addr.
  address.sin_addr.s_addr = 0x6401a8C0;  // 192.168.1.100... laptop addr.
  socklen_t len = sizeof(address);
The sendto call was doing the right thing... took my packet, attempted to send it to the address requested (which due to byte swapping would have been 100.1.168.192. That didn't match my network 192.168.1.x with netmask 255.255.255.0, so it was probably being submitted to my gateway (my router) and happy went off to the interwebs. Sorry random server out there.

Anyway.... for posterity.

User avatar
jrjbertram
 
Posts: 7
Joined: Sat Nov 02, 2013 7:15 pm

Re: CC3000 UDP - multicast, broadcast?

Post by jrjbertram »

And also, explains why Wireshark didn't see the packets. My router would have determined they weren't routed to the local network, so they would not have been broadcast to my laptop's "port" (I'm technically on wifi, but whatever)... thus wireshark would never have seen the packet.

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

Return to “Other Products from Adafruit”