1 2 Previous Next 20 Replies Latest reply on Feb 24, 2017 10:16 AM by monahanz

    Uploading a final C program on an Edison Breakout board to run without Eclipse etc.

    monahanz

      I have a question I don’t readily see answered here or in general on the web, which I think a general step by step account would be useful to many users…

      I have a C program which I developed in the Eclipse IDE environment.  It runs fine on my Edison breakout boards when uploaded via WiFi.  My question is how I get a final runtine program to run without uploading it with the IDE.

      A few specifics. 

      The program is the only thing the Edison breakout boards will ever do.  Essentially I and looking at the GPIO pins and responding accordingly.  (the UART, PWM etc. are wasted, a whole other issue).  I want the units to power up and run only that C program. Not even WiFi is required.    The program is called S100.c in Eclipse.

      How does one do this?  Can just add a line S100.exe to the end of my .profile text file in root\home and boot?  Where should S100.exe be located?

      I see all kinds of write-ups/discussions  on the web about placing files (of differing names and complexity) in directories like /etc./init.d    Most of the discussions see to be concerned with WiFi.  As I said I don’t need it. Does that simplify things?

      Also in my current Eclipse S100.c program I have printf(“text etc.”) statements proving diagnostic feedback to the Eclipse console.  I will remove them in the final runtime version, but I’m curious if I left them there would they hang the program.

      John

        • 3. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
          monahanz

          Thanks, I saw that tread some time back. It's so convoluted it's really unclear what I (minimally) need to do.  My application is very simple. I do not need Bluetooth or WiFi. about which that tread seems to be concerned about.  Mine is a "Hello World" type application.  I read somewhere (but cannot find it now), that I just need to put my program "S100.exe" at the end of my .profile file as a single line followed by a \n.  

          Questions (not answered):-

          1. Is that the case

          2. If not, is it asking too much for a few lines/example of how to do it.

          3. Where should my S100.exe file reside.

          4. Can I leave the Eclipse Console printf() functions in the runtime code. Will the hang the program or just be ignored.

           

          Please help, this has got to be a common problem for newbies for which the is a well known solution.

          John

          • 4. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi monahanz,

            Thank you for contacting us. Let us try to help you.
            More specifically, what you want is to avoid using any external IDE (Eclipse, Arduino, etc.) and instead take your code directly to the Edison, compile it and run it all in there, am I right? Please correct me if I’m wrong.
            In that case, what you’ll need to do is the following:

            • Create a file in your Edison using vi or nano text editors with the extension .c, e.g. mycode.c, and then paste your code in that file.
            • After that, you’ll want to compile it. Use GCC to do this, a really basic way to compile it would be with the following command gcc mycode.c –o mycode. This will take your code, compile it (gcc mycode.c) and generate an executable output called mycode (-o mycode). If you’re using any specific library you’ll need to add it to the compilation command as a parameter. For example, if you’re using MRAA in your code your complete command will be like this gcc mycode.c –o mycode –lmraa.
            • To run the newly created script just use ./mycode
            Hopefully, this is what you’re looking for.

            Regards,
            -Pablo
            • 5. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
              monahanz

              Thanks for the fast reply Pablo. That helps but does not quite answer my need.

              In your last line you say "To run the newly created script just use ./mycode". I assume you mean type that text in from the command line.

              I want the code to run upon power up each time.  I do not want to interact with the Edison in ANY way.

              Do you mean put the text "./mycode" in the .profile file in/home/root as the last line in that text file and just power up.

              Again where should the compiled file reside?

               

              I also disappointed/surprised that I cannot do something like that directly with the Eclipse compiled file.  It seems odd that after all the work setting up the Eclipse IDE one cannot simply execute a compiled file directly upon power up instead of going over to GCC.  Anybody/everybody is this the case?

               

              John

              • 6. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                nniles

                This is a general Linux question, really.  You can just Google "Linux run program at boot" and get lots of directions for how to do this.  The key to knowing which to follow is knowing that you want to use systemd to do it.

                 

                Here is a guide that should work for what you've described:

                How to write startup script for systemd - Unix & Linux Stack Exchange

                • 7. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                  monahanz

                  Don't agree!  how can it be a general Linux question if I'm asking how to have an Eclipse program run on power up?

                  Dropping Eclipse and going back to GCC seems like a cop out.

                   

                  Anybody else?

                  John

                  • 8. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hi guys,

                    Nniles: thank you very much for your help on this case.
                    Monahanz: regarding your question about how to avoid having to go into the Edison’s console to run the new program every time, you can write a service that runs the program automatically.
                    - Check the instructions below:

                    System services on Edison are handled by systemd, this tool is an init system that some Linux distributions use to manage all processes subsequently. I will not go deeper than that in this document but if you would like to learn more about systemd I highly recommend you to read the following documents:
                    http://bit.ly/1wh56nX
                    http://bit.ly/2ahEljc
                    In this example I will show you how to create a system service for a simple blink example written in JavaScript. However, this also applies to any other programming language, packages, etc. (with maybe a tiny modification).
                    For this example the code will be called blink.js and the service will be called blink.service. Nevertheless, these files can be called however you like as long as the service ends with the .service extension.
                    The blink example will be stored in /home/root/ and it will look like the following:

                    1. var mraa = require('mraa');  
                    2. var BLED = new mraa.Gpio(13);  
                    3. BLED.dir(mraa.DIR_OUT);  
                    4. var LEDSt = true;  
                    5. blink();  
                    6. function blink()  
                    7. {  
                    8.   BLED.write(LEDSt?1:0);  
                    9.   LEDSt = !LEDSt;  
                    10.   setTimeout(blink,1000);  
                    11. }  
                    The service file has to be stored in /lib/systemd/system and it will look like this:
                    1. #!/bin/sh  
                    2. [Unit]  
                    3. Description=Edison Arduino board LED Blinker  
                    4. [Service]  
                    5. ExecStart=/usr/bin/node /home/root/blink.js  
                    6. [Install]  
                    7. WantedBy=basic.target  
                     
                    Now give executable rights to blink.js with the command chmod +x blink.js.
                    To enable the service type the command systemctl enable blink.service. After rebooting the board the next time, the script should start automatically.
                     
                     
                    - Now, to answer your question about Eclipse, the approach is not very different from the one I just explained, the only difference is that you need to know where the Eclipse executable is being created. I just did some tests with Eclipse (Intel System Studio) and you can see in Eclipse’s console where the program is being run. My program was called blinkEdison, and it was located on /temp. Have you checked that directory? Is your Eclipse program there?

                    Regards,
                    -Pablo
                    • 9. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                      monahanz

                      Thanks Pablo, I'm getting there!  Unfortunately I will not be able to get to trying this for a day or two. 

                      What you have is most helpful thanks.

                       

                      I do remember seeing cases where people had test power up programs as the last line in their .profile file in /home/root/ 

                      In fact I'm almost sure I compiled "HelloWorld.exe" and ran it on my own initial system in .profile and had it run on power up.

                      Your blink.js is a script driven file.  I wondering if it's because you are not running a straight compiled .exe file you have to run is as a service.

                      Can you/anybody confirm that you cannot run a GCC C program in .profile.

                       

                      In your above code:-

                      1. #!/bin/sh 
                      2. [Unit] 
                      3. Description=Edison Arduino board LED Blinker 
                      4. [Service] 
                      5. ExecStart=/usr/bin/node /home/root/blink.js 
                      6. [Install] 
                      7. WantedBy=basic.target 

                       

                      What text do  I enter for [Unit], [Service]  and [Installed]

                      Thanks in advance

                       

                      • 10. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                        nniles

                        .profile is only run when a user logs in, so that method will not cause the program/script to be run unattended at boot (which is what it sounds like you want).

                         

                        systemd will allow you to start a program at boot without having to log in.

                         

                        All you need to change in the blink.service file is what comes after ExecStart=   so that it points at your program/script (full path) rather than calling node blink.js.  You might also want to name the file something other than blink.service...

                         

                        So if your program is called myexe and is located in /temp, change that line to:

                        ExecStart=/temp/myexe

                         

                        Thanks,

                        • 11. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                          monahanz

                          OK that makes sense. I forgot about the login aspect.

                          Thanks very much for your time and clear answer.

                          John

                          • 12. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                            monahanz

                            I am still having a problem getting the Edison (with breakout board only) to run a program on power up without user signon.  Some suggestions were presented by Pablo and others a few days back.  Only now can I check them out as I did not have access to the hardware for a few days.

                            I have spent 8 hours on this and now have gotten very frustrated.  It’s an application for the Edison that I can only assume others will later run into the same problem for IoT applications. 

                            First let me say I’m amazed/disappointed that the Intel  engineers have not built into Eclipse for the Edison such a capability.  Is this “on the list"?

                            From previous treads It appears one must take an Eclipse debugged application, splice it into a  text file on the Edison and run the old command line GCC compiler to generate a .exe file that can then be used as I outline below.  Seems we are going backwards….

                            Anyway here is what I have so far based on recommendations. 

                            I use the following simple C program called S100.c

                            main()

                            {

                            printf("Edison S100 Board Initilized\n");

                            }

                             

                            I place it in /home/root and compile it with GCC

                            GCC  ./S100.c –o ./S100

                            From the command line I can then run S100.EXE with

                            ./S100.exe

                            I get the output:-  Edison S100 Board Initilized working fine

                            So far so good.  All this is done from the directory /home/root

                             

                             

                            As recommended by Pablo I then go to the directory: /lib/systemd/system

                            I enter a text file named S100.service which contains:-

                            #!/bin/sh

                            [Unit]

                            Description=My Edison S100 Activation

                            [Service]

                            ExecStart=/usr/bin/node    /home/root/S100.exe

                            [Install]

                            WantedBy=basic.target

                            [Install] 

                            WantedBy=basic.target

                            From within the directory /home/root I type:-  systemctl enable S100.service.  No errors were reported.

                            I then power down are reboot the Edison.  Using the serial connection (not WiFi).  The unit seems to power up fine with lines upon lines of “OK” info.

                            Amongst the text is:-

                                  Starting My Edison S100 Activation...

                            [  OK  ] Started My Edison S100 Activation.

                            This seems to indicate that the service was activated.

                            However there is no text following which says:-

                            Edison S100 Board Initilized working fine

                            So it looks as if S100.exe is not actually being executed

                            I’m at a complete loss to know what the problem is or what to do next.

                            Please help

                             

                            John

                            • 13. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                              monahanz

                              Perhaps this will help.  I moved the S100.service to be the very last thing being called just in case a service was required to print on the screen the text from S100.exe:-  Edison S100 Board Initilized working fine.

                               

                              In my setup PulseAudio Sound System seems to be the last service called. So I entered the following S100.service file

                               

                              #!/bin/sh

                              [Unit]

                              Description=My Edison S100 Activation

                              After=pulseaudio.service

                              [Service]

                              ExecStart=/usr/bin/node   /home/root/S100.exe

                              [Install]

                              WantedBy=basic.target

                               

                              Still this did not help.

                              Please help

                              • 14. Re: Uploading a final C program on an Edison Breakout board to run without Eclipse etc.
                                nniles

                                Delete "/usr/bin/node" from the ExecStart line.  Node is used to run Javascript.  You're running a fully compiled executable, not Javascript.

                                 

                                Also, I can't guarantee that you will see text output to stdout from a program run as a service during boot.  It might work, but if you don't see the output after you make the change above, you might have more luck writing to a file.

                                 

                                Thanks,

                                1 2 Previous Next