3 Replies Latest reply on Dec 9, 2016 1:57 PM by AndresV_Intel

    Communication between Arduino and Nodejs programs in Intel Galileo Gen 1

    EstebanCarnuccio

      Hi, I am trying to make two programs that communicate with each other in Intel Galileo Gen1. The first program I am programming in Node.js, while the other program with the Ide Arduino. But I can not get them to communicate with each other, I want them to function as a client-server.   So I wanted to consult, how I can do a program with the Ide Arduino that transfers data to another in Node.js, both running in Galileo?

       

      From already thank you very much

        • 1. Re: Communication between Arduino and Nodejs programs in Intel Galileo Gen 1
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello Esteban,

          I would recommend you to read this article https://software.intel.com/en-us/blogs/2015/05/05/efficient-data-sharing-using-interrupts-on-intel-edison. Even though it was written for the Edison, the basic principles and the programming can be applied to your Galileo.

          Also, you can check this site http://node-ardx.org/, which provides several examples related to the node.js – Arduino IDE communication within an Arduino based board.

          Regards,
          Andres
           

          • 2. Re: Communication between Arduino and Nodejs programs in Intel Galileo Gen 1
            EstebanCarnuccio

            Thank you very much Andres for the answer. But finally the communication between Ide Arduino and Node.js has been able to do so via UDP socket. For that reason I leave the code that I used to carry out the communication between the two programs, in case anyone it serves.

             

             

            • Arduino Code

             

            #include <SPI.h>

            #include <Ethernet.h>

            #include <EthernetUdp.h>

             

            byte arduinoMac[] = { 0x40, 0x25, 0xC2, 0x11, 0x30, 0x78 };

            IPAddress arduinoIP(127, 0, 0, 1); // desired IP for Arduino

            unsigned int arduinoPort = 8888;      // port of Arduino

             

            IPAddress receiverIP(127, 0, 0, 1); // IP of udp packets receiver

            unsigned int receiverPort = 6000;      // port to listen on my PC

             

            EthernetUDP Udp;

             

            void setup()

            {

              Ethernet.begin(arduinoMac,arduinoIP);

              Udp.begin(arduinoPort);

            }

             

            void loop()

            {

              Udp.beginPacket(receiverIP, receiverPort); //start udp packet

              Udp.write("Funciona!!"); //write sensor data to udp packet

              Udp.endPacket(); // end packet

            delay(1000);

            }

             

            • Node.js Code

            var dgram = require("dgram");

            var server = dgram.createSocket("udp4");

             

            server.on("message", function (msg, rinfo)

            { //every time new data arrives do this:

              console.log("Se recibe de la IP: "+ rinfo.address + ":" + rinfo.port); // you can comment this line out

              console.log("llego msj:"+msg);

            });

             

            server.on("listening", function ()

            {

              var address = server.address();

              console.log("server listening " + address.address + ":" + address.port);

            });

             

            server.bind(6000); //listen to udp traffic on port 6000

             

            Thank you very much for everything

            • 3. Re: Communication between Arduino and Nodejs programs in Intel Galileo Gen 1
              AndresV_Intel

              Hello Esteban,

               

              I’m glad you found a way to perform the communication between your programs, and thank you for sharing that information with the community.

               

              Regards,

              Andres