8 Replies Latest reply on Feb 10, 2017 3:58 PM by Intel Corporation

    How to configure the Intel Edison as an udp server in an adhock network ?

    jofeier

      I have done some experiments with the edison (systemstudio,  C ++ , Win7).

      The integration into an existing network via wifi was also ok.

      But the next Steps are not clear: I would like to use the edison with a special hardware for measurements.

      The edison should be an udp Server that responds to requests from a (Android-)Client. But there is no AP / Network, it must be an adhoc Connection.

      Now is the question how is to configure the System?

      What is to do with the system settings and what in application? Normally is assumed that the edison is integrated into a network (SSID, key, PW)

      Which IP is to be used?

      An example would be helpful.

       

      Thanks and greetings

      Achim

        • 1. Re: How to configure the Intel Edison as an udp server in an adhock network ?
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello Achim,

          Thank you for interest in the Intel® Edison Breakout Board.

          I understand that you want to measure a variable with a special hardware, then transfer the data to your Edison board, which acting as a UDP server, should send information, when requested, to an Android client. All of this through an ad-hoc connection.
          I have a question before presenting what I’ve found so far, are you not able to use an AP network or you don’t want to use one? Because if you can, you should check this link https://communities.intel.com/message/442354#442354 in order set the Edison as an UDP server.

          Generally, the UDP communication part is more Linux related than Edison related, so here is a link that may help you program UDP sockets http://www.binarytides.com/programming-udp-sockets-c-linux/.

          Regarding the ad-hoc connection, the Intel Edison Wi-Fi Guide, section 4.2.4 (http://www.intel.com/content/dam/support/us/en/documents/edison/sb/edison_wifi_331438001.pdf), gives the necessary steps to create/connect to such network.
           
          In case you need further assistance, don’t hesitate to contact us.

          Regards,
          Andres V.

          1 of 1 people found this helpful
          • 2. Re: How to configure the Intel Edison as an udp server in an adhock network ?
            jofeier

            Hi Andres,

             

            thanks for your mail.

            ....UDP  ad-hoc Connection: At the moment  is to be used an android tablet (as terminal).

            Some tablets can not open a WiFi hotspot if they don't  have internet-accsess. The final user does not allow the use of tabets with internet option.

             

            If the case the EDISON is configured as an AP, I assume that the energy consumption is higher!?

            This path would be not optimal also for other reasons (using of multiple devices....)

             

            I tried to program the edison (wifi Guide, 4.2.4 create / connect to an ad-hoc network).

            There were 2 Problems:

            1. I don't found the directory with the file 'edison_env' to load the wpacli_ibss_open.sh - script.

                my edison directory is empty !?

             

            C:\>dir F:\
            Datenträger in Laufwerk F: ist EDISON
            Volumeseriennummer: 80C7-D7A4

            Verzeichnis von F:\              <--- empty

            Datei nicht gefunden   

            C:\>

             

            2. Because I have configured one edison (as adhoc nw), but it haven't not worked completely.

            These are the Settings:

             

            root@edison_gfxxxx:~# ifconfig

            lo        Link encap:Local Loopback

                      inet addr:127.0.0.1  Mask:255.0.0.0

                      inet6 addr: ::1/128 Scope:Host

                      UP LOOPBACK RUNNING  MTU:65536  Metric:1

                      RX packets:48644 errors:0 dropped:0 overruns:0 frame:0

                      TX packets:48644 errors:0 dropped:0 overruns:0 carrier:0

                      collisions:0 txqueuelen:0

                      RX bytes:3696976 (3.5 MiB)  TX bytes:3696976 (3.5 MiB)

              

            usb0      Link encap:Ethernet  HWaddr 02:00:86:77:6a:b0

                      inet addr:192.168.2.15  Bcast:192.168.2.255  Mask:255.255.255.0

                      inet6 addr: fe80::86ff:fe77:6ab0/64 Scope:Link

                      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                      RX packets:5296 errors:0 dropped:0 overruns:0 frame:0

                      TX packets:3730 errors:0 dropped:0 overruns:0 carrier:0

                      collisions:0 txqueuelen:1000

                      RX bytes:3045212 (2.9 MiB)  TX bytes:531807 (519.3 KiB)

             

              

            wlan0     Link encap:Ethernet  HWaddr 78:4b:87:ad:31:95

                      inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0

                      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

                      RX packets:553 errors:0 dropped:0 overruns:0 frame:0

                      TX packets:1187 errors:0 dropped:0 overruns:0 carrier:0

                      collisions:0 txqueuelen:1000

                      RX bytes:29532 (28.8 KiB)  TX bytes:343779 (335.7 KiB)

               

             

            root@edison_gfxxxx:~# wpa_cli status

            Selected interface 'wlan0'

            bssid=00:24:d7:6a:03:09  --> PC

            ssid=edison_gfxxxx        (ad-hoc network: why that ?)

            id=0

            mode=IBSS

            pairwise_cipher=CCMP    (*)

            group_cipher=CCMP        (*)

            key_mgmt=WPA2-PSK     (*)

            wpa_state=COMPLETED

            ip_address=192.168.0.10  --> Edison

            p2p_device_address=7a:4b:87:ad:31:95

            address=78:4b:87:ad:31:95

            root@edison_gfxxxx:~#

             

            With this setting works the data exchange, but the PC must be AP. (in this case)

            (*) i can't cange this positions

            It would be great if i could adjust directly the edison network parameters (for one device, s.a. unix scripts )

             

            I would be glad about help.

             

            Greetings Achim

            • 3. Re: How to configure the Intel Edison as an udp server in an adhock network ?
              jofeier

              Hi Andres,

              For better understanding, I would like to show my goal.

              I hope the edison isn't the wrong way.

              Steps.png

              Greetings Achim

              • 4. Re: How to configure the Intel Edison as an udp server in an adhock network ?
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hello Achim,

                Thank you for the information provided.

                You mentioned that the data exchange is working, but the PC is not configured as an AP yet. What is preventing your PC from being used as an AP? What are you currently using as an AP?

                In the link previously provided (https://communities.intel.com/message/442354#442354), it is mentioned that the Edison should be put in AP mode, even if you are using it as an UDP transmitter/receiver.

                Is the access point in Step 3 different from the PC in steps 1 and 2?

                I’ll be waiting for your response.

                Regards,
                Andres

                • 5. Re: How to configure the Intel Edison as an udp server in an adhock network ?
                  jofeier

                  Hi Andres,

                  thanks for your mail.

                   

                  AP: We must use android tablets with no internet-accsess. That means, that a lot of these devices can't open a hotspot and thus therefore can not be an access point.

                         Yesterday we corrected our concept. The edison will be the master and AP, the tablet  client.

                         The originally planned ad hoc network is becoming more and more difficult. Normally Android does not support an ad hoc Network, and so is it necessary to make  changes.

                         But the licensing conditions  become more stringent.

                   

                  Now i have set the edison as an AP, the connection to the Android device worked fine.

                   

                  >> Is the access point in Step 3 different from the PC in steps 1 and 2?

                       The real device will be a router - this will be connected via a network to a PC.

                        Really  will be a Win PC the AP. -sorry-

                   

                  Please once more: where is the location of the file  'edison_env' ?

                   

                  Best regards

                  Achim

                  • 6. Re: How to configure the Intel Edison as an udp server in an adhock network ?
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hello Achim,

                     

                    Thank you for the information provided.

                     

                    I understand that you are testing a new setup, with the Edison board as access point, with the Android devices working as clients. You say that this setup is working fine.

                     

                    Which guide are you following? Is the ‘edison_env’ file needed for your new AP setup? Have you started the wpa_supplicant to use the wpa_cli (as stated here http://www.intel.com/content/dam/support/us/en/documents/edison/sb/edison_wifi_331438001.pdf, section 4.2)?

                     

                    This guide may help you find ‘edison.env’ (under Modifying the source files): http://drejkim.com/blog/2014/11/22/building-an-edison-image-and-changing-the-root-partition-size/.

                     

                    I’ll be waiting for your response.

                     

                    Regards,
                    Andres

                    • 7. Re: How to configure the Intel Edison as an udp server in an adhock network ?
                      jofeier

                      Hello Andres,

                      thanks for your mail.

                      For the design of the connection edison <--> android tablet I have used several documents and examples.

                      The documents you recommended were also helpful.

                      Here are some snippets: (it's running on my hardware)

                      (for remembering: simple UDP Connection between Intel Edison and Android tablet, Edison is now AP)

                       

                      Edison - part ( Eclipse Platform Version: Luna SR2 (4.4.2))

                       

                      main(int argc, char **argv)

                       

                      {

                           struct sockaddr_in myaddr;                               // edison address

                           struct sockaddr_in remaddr;                              // remote address

                           socklen_t addrlen = sizeof(remaddr);                 // length of addresses

                           int recvlen;                                                          // bytes received

                           int serversocket;                                                // socket edison - is server

                           unsigned char buf[BUFSIZE];                         // receive buffer

                           unsigned char buf2[BUFSIZE];                        // sendbuffer

                       

                           string returnString = "Edison is listening to you";    // return_message

                       

                      // create a UDP socket

                       

                      if ((serversocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {

                           printf("cannot create socket\n");

                           return 0;

                      }

                      printf("Socket open\n");

                       

                      // bind the socket

                       

                      memset((char *)&myaddr, 0, sizeof(myaddr));

                      myaddr.sin_family = AF_INET;

                      myaddr.sin_addr.s_addr = inet_addr("192.168.42.1");          // edison IP

                      myaddr.sin_port = htons(PORT);

                       

                      if (bind(serversocket, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {

                           printf("bind failed\n");

                           return 0;

                      }

                      printf("bind OK\n");

                       

                      // now loop, receiving and sending

                       

                      for (;;) {

                           printf("waiting on port %d\n", PORT);

                           recvlen = recvfrom(serversocket, buf, BUFSIZE, 0, (struct sockaddr *)&remaddr, &addrlen);

                           printf("received %d bytes\n", recvlen);

                           if (recvlen > 0) {

                                buf[recvlen] = 0;

                                printf("reveived Data: \"%s\"\n", buf);

                                printf("received from : %s\n", inet_ntoa(remaddr.sin_addr));

                       

                      // put here your other actions

                       

                                for(int i = 0; i < returnString.length(); i++) buf2[i]=returnString[i];

                                buf2[returnString.length()= '\0';

                                printf("this will be send:  %s\n", buf2);    

                                rc = sendto(serversocket, buf2, returnString.length(), 0, (struct sockaddr *)&remaddr, addrlen);

                                if (rc<0) {

                                     printf("send failed\n");

                                }

                                else {

                                     printf("send %d bytes: \"%s\"\n", rc, buf2);

                                }

                              }

                           "* ";

                      }

                       

                       

                      Android - part  is Client (Android Studio 2.2.3)

                       

                      public class MainActivity extends AppCompatActivity {

                       

                        private GoogleApiClient client;

                       

                      protected void onCreate(Bundle savedInstanceState) {

                         super.onCreate(savedInstanceState);

                        setContentView(R.layout.activity_main);

                         // Android tablet
                        // wifi - Mode, DHCP

                         WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

                        wifiManager.setWifiEnabled(true);          //  OFF = wifiManager.setWifiEnabled(false);

                       
                         boolean wifiEnabled = wifiManager.isWifiEnabled();

                       

                         if (wifiEnabled)  System.out.println("wifi ON !!!");

                            else System.out.println("wifi OFF !!!");

                       

                         while (true) {

                             System.out.println("start ....");

                             SendUDP t = new SendUDP();

                             t.start();

                              try {

                                  Thread.sleep(1000);                              // every sec one call

                                  } catch (InterruptedException e) {

                                       e.printStackTrace();

                                  }

                             }

                        }

                       

                       

                         public class SendUDP extends Thread {

                              public void run() {

                       

                                   int UDP_SERVER_PORT = 8888;

                                  String serverIP = "192.168.42.1";          // IP edison

                                  String message = "hello world from UDP client ";

                                  InetAddress serverAddr = null;

                                   try {

                                       serverAddr = InetAddress.getByName(serverIP); 
                                        } catch (UnknownHostException e) {

                                            e.printStackTrace();

                                      }

                       

                                   try {

                                        System.out.println("InetAddr: " + serverAddr.toString() + "\n");

                       

                                        byte[] sendbuf = message.getBytes();

                                        byte[] recbuf = new byte[512];

                                       Log.d("UDP", "sendmessage: ' "+new String(sendbuf)+"'");

                       

                                       DatagramPacket send_packet = new DatagramPacket(sendbuf,sendbuf.length, serverAddr, UDP_SERVER_PORT);

                                       DatagramSocket clientsocket = new DatagramSocket();

                                       clientsocket.send(send_packet);

                         

                                       DatagramPacket rec_packet = new DatagramPacket(recbuf,recbuf.length);

                             // waiting for response 

                                       clientsocket.receive(rec_packet);

                                       InetAddress inaddr = rec_packet.getAddress();  // server IP
                                        int  inport = rec_packet.getPort();                      // server port
                                        int  inlen = rec_packet.getLength();                   // length receive message
                                        byte[] indata = rec_packet.getData();                 // receive message

                                       System.out.println("return_message from " +inaddr+ " port " +inport+ "\n");

                                       System.out.println(">"+new String(indata,0,inlen)+ "< len: "+inlen+ "\n");

                       

                                       clientsocket.close();

                       

                                  } catch (SocketException e) {

                                       Log.d("UDP", e.getMessage());  // no response
                                        e.printStackTrace();

                                  } catch (UnknownHostException e) {

                                       Log.d("UDP", e.getMessage());

                                       e.printStackTrace();

                                  } catch (IOException e) {

                                        Log.d("UDP", e.getMessage());

                                       e.printStackTrace();

                                  } catch (Exception e) {

                                       Log.d("UDP", e.getMessage());

                                       e.printStackTrace();

                                  }

                                  Log.d("UDP", "End      thread");

                          }

                        }

                      }

                       

                      Others later

                      Greetings Achim

                      • 8. Re: How to configure the Intel Edison as an udp server in an adhock network ?
                        Intel Corporation
                        This message was posted on behalf of Intel Corporation

                        Hello Achim,

                        Thank you for the information provided.

                        I’m glad you found the documents provided useful.

                        Now that I have a better understanding of your setup, are you experiencing any issue? Is there anything I can assist you with? What part of your setup is missing?

                        I’ll be waiting for your response.

                        Regards,
                        Andres