11 Replies Latest reply on Dec 21, 2015 3:32 PM by CMata_Intel

    Send and receive data to and from intel galileo

    PETRONG

      I have been able to make my intel galileo serve as a webserver, and i can connect to a web app on intel galileo through wifi from phone or laptop. But how do I send and receive data from intel Galileo? For example: If I clicked the turn on or turn off button on the web app, how do I make this instruction active on galileo?

       

      I have tried searching the internet for solution but only came across "ConnectAnyThing", but I don't see how I can add my own web pages and also write Node.js in my Intel XDK IOT if I used "ConnectAnyThing".

        • 1. Re: Send and receive data to and from intel galileo
          Taimoor

          You need to spawn a process probably (Child Process Node.js v4.2.1 Manual & Documentation)

           

          The example that the URL jumps to should work fine though (note version 4 though)

          • 2. Re: Send and receive data to and from intel galileo
            Taimoor

            Pasting the code here for convenience:

            var spawn = require('child_process').spawn,
              ls  = spawn('ls', ['-lh', '/usr']);
            
            ls.stdout.on('data', function (data) {
              console.log('stdout: ' + data);
            });
            
            ls.stderr.on('data', function (data) {
              console.log('stderr: ' + data);
            });
            
            ls.on('close', function (code) {
              console.log('child process exited with code ' + code);
            });
            • 3. Re: Send and receive data to and from intel galileo
              PETRONG

              Thanks a lot.

              But, please how do i use this code, where do i pass the button handle and the function it should execute, when the button is clicked.

              • 4. Re: Send and receive data to and from intel galileo
                Taimoor

                Can you be a little more specific? spawning will let you execute OS commands in node, receive their return values etc. You should look into the sample provided IoT - Getting started with the Intel® XDK IoT Edition | Intel® Developer Zone

                 

                The ToggleLED project performs a hardware action when a button is pressed in the browser.

                • 5. Re: Send and receive data to and from intel galileo
                  CMata_Intel

                  Hi PETRONG,

                   

                  I would like to know if you have been able to run the code provided for Taimoor. Also, did you check the ToggleLED project?

                   

                  Regards,

                  Charlie

                  • 6. Re: Send and receive data to and from intel galileo
                    PETRONG

                    Capture.JPG

                    This is a snapshot from a web app, When that pink switch on the right hand side of the image is clicked, its label changes to either "on" or "off". I want to be able to use that pink switch to either turn on or turn off the led.

                    I thought i could do something like; "if the label says 'off' then set led state as 0, else set led state as 1".

                     

                    I tried to use something like "document.querySelector(".switchLabel").innerHTML" to get the value of the switch label in intel XDK IOT main.js file, but it gave an error instead, saying that "document" is undefined.

                     

                    I suppose I must use node.js to do this, but I have no clues

                    Thanks

                    • 7. Re: Send and receive data to and from intel galileo
                      CMata_Intel

                      Hi PETRONG,

                       

                      I suggest you to take a look at the examples in the XDK: Web Sockets and Simple Web Server. There is another thread with a similar application: Launch python script in html page that may help you but is with Python

                       

                      Regards,

                      Charlie

                      • 8. Re: Send and receive data to and from intel galileo
                        PETRONG

                        I loaded the websockets template in Intel XDK IOT, but it gave errors signifying that I needed to install the socket.io module. I run this: "root@galileo:~# npm install socket.io" and it gives me the error below on the console. Please any way out?

                        Thanks.

                                                                                                                                                           

                        npm ERR! network tunneling socket could not be established, cause=getaddrinfo ENOTFOUND                                                                                    

                        npm ERR! network This is most likely not a problem with npm itself                                                                                                         

                        npm ERR! network and is related to network connectivity.                                                                                                                   

                        npm ERR! network In most cases you are behind a proxy or have bad network settings.                                                                                        

                        npm ERR! network                                                                                                                                                           

                        npm ERR! network If you are behind a proxy, please make sure that the                                                                                                      

                        npm ERR! network 'proxy' config is set properly.  See: 'npm help config'                                                                                                   

                                                                                                                                                                                                   

                        npm ERR! System Linux 3.8.7-yocto-standard  

                        • 9. Re: Send and receive data to and from intel galileo
                          PETRONG

                          ...one more question please: When I am completely done  with my galileo project how do upload it to the galileo so that i dont have to turn on intel XDK IOT to use it. I want to be able to connect to galileo with my phone without having to connect the galileo board to a pc on the same network, since my galileo is the webserver. How do I achieve this?

                          • 10. Re: Send and receive data to and from intel galileo
                            Taimoor

                            Normally, you shouldn't need to do anything if you started afresh. The XDK daemon should already start your project with a reboot.

                            • 11. Re: Send and receive data to and from intel galileo
                              CMata_Intel

                              Hi PETRONG,

                               

                              What is the output of running in your board the following commands?

                              uname -a

                              npm --version

                              node --version

                              Are you able to see this folder: /opt/xdk-daemon/current/node-inspector-server/node_modules/v8-debug/build/Release/.deps/home/pokybuild/yocto-autobuilder/yocto-worker/quark-multilib/build/build/tmp/work/i586-poky-linux/xdk-daemon/0.0.37-r0/

                              Which XDK version are you using?

                               

                              Regarding your question: how do upload it to the galileo so that i dont have to turn on intel XDK IOT to use it. You have access to the main.js in /node_app_slot, you can run the script in there with node main.js

                               

                              Regards,

                              Charlie