This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129EXL network broadcast

Hello,

I have multiple TM4C129EXL in a network, under a router. Each uC has a specific job to do. When a device identify an event I would like to share this event with each node within a network. It's very similar to UDP Broadcasting.

Each node should not know other endpoint IP address. (Best case). But if it is the only way I can do it somehow... (Worst case)

What is the preferred way to achieve the above functionality? What tools are available in TI RTOS to get this? (An UDP Broadcast example maybe?)

Looking forward any reply.

  • I found this forum post that might help you:

    e2e.ti.com/.../1313216

    And this discussion of the topic in stackoverflow:

    stackoverflow.com/.../network-udp-broadcast-design

    My understanding is that any packet sent to the 255.255.255.255 IP address (or your network's specific subnet (ie 192.168.0.255)) is considered a broadcast packet to all the devices on your subnet. If all of your nodes set up a listener socket on an agreed upon port number, and the broadcaster sends a packet to that port and that IP address, then everyone should receive everyone's broadcasts.

    I hope this helps.

    Alan
  • Hello Alan,

    Thank you for your reply. As you suggested I started to implement the udp broadcast. But I have a problem

    When I try to set the SO_BROADCAST I always have an error. Even with type int and char too. 

    void udpBroadcast(){
    
    	System_printf("Start udpBroadcast\n");
    	System_flush();
    
    	Task_sleep(10000);
    
    	struct sockaddr_in their_addr;
    	int socketfd;
    	if(socketfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP) == -1){
    		System_abort("failed to create socket");
    		System_flush();
    	}
    
    	char optval = 1;
    	int optlen = sizeof(optval);
    
    
    	// Set KEEPALIVE option to 1
    	optval = 1;
    	if (setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, &optval, optlen) < 0)
    	{
    		System_printf("Error: setsockopt failed\n");
    		System_flush();
    	}
    
    
    	if(getsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, &optval, &optlen) < 0)
    	{
    		System_printf("Error: setsockopt failed\n");
    		System_flush();
    	}
    
    
    
    	memset(&their_addr,0,sizeof(their_addr));
    	their_addr.sin_family = AF_INET;
    	their_addr.sin_port = htons(1200);
    	their_addr.sin_addr.s_addr = htonl(0xC0A801FF);	// 192.168.1.255
    	//memset(their_addr.sin_zero,'\0',sizeof(their_addr.sin_zero));
    
    	uint8_t packet[50];
    	memset(packet,0xFA,50);
    
    	int sent = sendto(socketfd,packet,50,0,(struct sockaddr *)&their_addr,sizeof(their_addr));
    	if(sent < 0){
    		System_printf("unable to send broadcast");
    		System_flush();
    	}
    
    	close(socketfd);
    
    }
    

    This link helps me a lot but I can not get over with SO_BROADCAST: 

    in the doc: SPRU524J here is the description:

    SO_BROADCAST: Requests permission to send broadcast datagrams on the socket. Broadcast was a privileged operation in earlier versions of the system.

    Any idea? 

    I modified the UDPEcho example to set the socket option but no effect.

  • the error code is 9: Bad file descriptor....