8 Replies Latest reply on Dec 8, 2014 3:04 AM by kenchen

    What Am I Doing Wrong With Wakeup-On-LAN (WOL)? [Semi-Resolved]

    Maggion

      So I picked up a Galileo last night because I need to do a Wakeup-On-LAN application for work. I unboxed it, updated to the current firmware, and I successfully got it to blink an LED with a simple sketch.

       

      Throughout last night and this morning I have been trying to get it to send a WOL magic packet so that I can verify the packet using a Wireshark capture. I see no network activity coming out of the ethernet port. I have tried using Ethernet.begin(mac) to get a DHCP-assigned IP address so that I can ping the device and know it is there, and I have also tried using Ethernet.begin(mac,ip) to set a fixed IP on it, but so far nothing works.

       

      Does anything know whether or not I have to call EthernetUdp.begin(port) before sending a UDP packet to the local network? I wouldn't think so because I do not plan on listening to any other devices.

       

      Here is my magic packet routine. I'll post my whole sketch if anyone is interested to see it. Someone please help me out by telling me whether or not it looks like I am sending the packet correctly.

       

       

       

       

       

       

      unsigned long sendWOLpacket(unsigned char macaddr[] )

      {

        // set all bytes in the buffer to 0

        //memset(packetBuffer, 0, NTP_PACKET_SIZE);

       

        int k = 0;

        for(k = 0; k < 6; k++)

        {

          packetBuffer[k] = 0xFF;

        }

        k = 6;

        for (i = 0; i < 16; i++)

        {

          for (j = 0; j < 6; j++)

          {

            packetBuffer[k + j] = wake_mac[j];

          }

        

          k += 16;

        }

       

       

        // all NTP fields have been given values, now

        // you can send a packet requesting a timestamp:       

        Udp.beginPacket(bcast, WOL_PORT);

        Udp.write(packetBuffer, WOL_PACKET_SIZE);

        Udp.endPacket();

      }

        • 1. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
          shadowrecon

          I believe if i read the documentation right this feautre is not supported. Correct me if im wrong.

             - ShadowRecon

          • 2. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
            Maggion

            I'm sorry, which feature do you mean?

             

            My stumbling point here is sending a packet over UDP. Any packet at all, to anywhere, on any port at all. Since my last post I have loaded the UDPSendReceiveString example program from the Arduino interface. I am sending it packets from a C# application.

             

            The Galileo is receiving packets and it is echoing them properly to the Serial Console. However, I am observing:

            -Galileo reports the sender address (address of my PC) as the broadcast address (255.255.255.255)

            -Galileo reports the sender's port as '0'

            -Galileo's reply does not appear on the network. And that is, when Galileo sends the packet to the broadcast address (which every UDP device should receive), and it is also when Galileo explicitly sends the reply to the IP Address of my PC.

             

            Using the example program included with the IDE, I am so far showing that Galileo can receive packets over UDP, but it is unable to send UDP packets, even over broadcast.

             

            This is aggravating. If I can't get this to work I am going back to Netduino Plus 2, because I don't have to wrestle with those for five hours just to send a single packet.

             

            Thoughts?

            • 3. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
              shadowrecon

              I was refering to the WOL. Ive looked up the documentation and i am correct as it is not supported on the intel galileo.

              ARK | Intel&#174; Galileo Board

              If you look at that link under advanced technologies you will see it is not supported.

               

              As far as the intel galileo being aggravating, i agree, but it has alot of power and is relatively new in the industry and still needs alot of work in my opion but it is stable once you get it working. I would play with the examples or look at just programming the galileo over ssh and using python to send and recieve packets as it has full access over the libraries avaiable for networking and more libraries can be added. Just my opion.

              1 of 1 people found this helpful
              • 4. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
                Maggion

                Ahhhh, well I could totally understand the Galileo not being able to receive WOL. But I am trying to send WOL messages, which are really just arbitrary packets going to arbitrary addresses.

                 

                I am closing this thread because my issue isn't really with WOL, it is with being unable to send UDP packets. I am thinking if I ask about UDP in general I'll catch a wider audience.

                 

                Thanks Shadow for your time looking at my post.

                • 5. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
                  shadowrecon

                  . No problem, i apperciate it when people take the time to look at my post too.

                   

                     - ShadowRecon

                  • 6. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
                    Maggion

                    I was hoping to keep this thing simple, but I guess I'm going to go ahead and learn my way through installing Linux on this thing so I can use Python to get the job done. Thanks again, over and out for now.

                    • 7. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
                      RobM50

                      Any luck with UDP or WOL sending on this?

                      • 8. Re: What Am I Doing Wrong With Wakeup-On-LAN (WOL)?
                        kenchen

                        I refered linux - Broadcasting UDP packet to 255.255.255.255 - Stack Overflow  to broadcast magic packet successfully.

                        Please check bellow... remember to chang your destination MAC address at line 9.

                         

                        #include "Dns.h"
                        
                        #define UDP_TX_PACKET_MAX_SIZE 102
                        uint16_t _offset=0;
                        int i = 0, j = 0, k = 0; 
                        const int WOL_PACKET_SIZE = 102;
                        byte packetBuffer[WOL_PACKET_SIZE];
                        uint8_t _buffer[UDP_TX_PACKET_MAX_SIZE];
                        unsigned char wake_mac[6] = { 0x00,0x1A,0xD4,0x01,0x59,0x78 };  // mac address of Target WOL machine
                        
                        void setup() {
                          // put your setup code here, to run once:
                           pinMode(13,OUTPUT);
                        }
                        void loop() {
                          // put your main code here, to run repeatedly: 
                           
                              Broadcast();
                         
                              digitalWrite(13,HIGH);
                              delay(500);
                              digitalWrite(13,LOW); 
                              delay(500);
                        
                              delay(1000);
                        }
                        
                        int Broadcast(void)
                        {
                          
                          IPAddress ip(255,255,255,255);
                          
                            int sock;
                            if( (sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
                            {
                                perror("socket : ");
                                return -1;
                            }
                            int broadcast = 1;
                            if( setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) != 0 )
                            {
                                perror("setsockopt : ");
                                close(sock);
                                return -1;
                            }
                        
                          for( k = 0; k < 6; k++)
                          {
                            packetBuffer[k] = 0xFF;
                          }
                          k = 6;
                          for (i = 0; i < 16; i++)
                          {
                            for (j = 0; j < 6; j++)
                            {
                              packetBuffer[k + j] = wake_mac[j];
                            }
                           
                            k += 6;
                          }
                            int written_bytes =  0;
                            if  (UDP_TX_PACKET_MAX_SIZE - _offset < WOL_PACKET_SIZE) {
                           written_bytes =  UDP_TX_PACKET_MAX_SIZE - _offset;
                         } else {
                          written_bytes = WOL_PACKET_SIZE;
                         }
                         memcpy(_buffer + _offset, packetBuffer, written_bytes);
                         _offset += written_bytes;
                        
                            struct sockaddr_in si;
                            si.sin_family = AF_INET;
                            si.sin_port   = htons( 2304 );
                            si.sin_addr.s_addr = ip._sin.sin_addr.s_addr;
                            /* send data */
                            size_t nBytes = sendto(sock, _buffer, _offset, 0, 
                                            (struct sockaddr*) &si, sizeof(si));
                        
                            return 0;
                        }