Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JMona1
New Contributor I
1,315 Views

Running a C program on an Edison Breakout board on power up.

I have been unsuccessful in getting help in another section ( ) of finding a solution to a simple issue. I want to have a program written in C (with the Eclipse IDE) run on an Edison breakout board run each time on power up without any user interaction.

I'm a Linux newbie and I'm looking for a simple step by step example of how one would do this. This has got to be a common situation yet I see no detailed documentation.

Please see the above forum tread first for more info. Just pointing me to endless treads of previous treads going deeper and deeper is of no help.

Thanks in advance

John

0 Kudos
19 Replies
idata
Community Manager
29 Views

Hi John,

Thanks for your interest in the Intel Edison Platform.

In the thread they gave you the correct solution. In here you can find the original document:

I would recommend to do the system service for the blink example, then try to do your own system service.

I hope you find this information useful, have a nice day!

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

Thanks for the fast reply Jose.

First I don't have a Arduino board to do the LED Blinker example. I have 6 Edison breakout boards. I guess I will have to rig up a single LED/bit to emulate the example.

I know about systemd/systemctl and how to active a .service. If you read through the tread mentioned above you will see that my test program was 'activated'. However the program itself was written to simply put a line of text on the console. No such line appears.

That's the problem. -- No solution so far!!!!

Would like help in getting a c program to put a line of text on the screen on power-up using a breakout board connected via a serial (or WiFi) link. Does not seem like I'm asking a lot.

John

idata
Community Manager
29 Views

Hey John - If I follow you, you don't see the output of your program on the console (connecting to it via serial?) Do you know if it is getting executed (can you have it write the time to a file in /tmp to show it ran?)

But how I would do what you want is to call the wall command in your systemd unit file. The wall command will echo something to all outputs.

i.e.

root@edison1:# wall "Hello World"

Broadcast message from root@edison1 (pts/0) (Thu Dec 22 20:55:11 2016):

Hello World

root@edison1: #

Now an example of something I have running on boot is to get the IP address and print it on a SparkFun OLED shield on boot using python . You can check that out here: https://github.com/joemcmanus/sparkfunOledBlock GitHub - joemcmanus/sparkfunOledBlock: Sample Programs for using the Sparkfun OLED Block

Hope that helps.

Cheers,

-Joe

JMona1
New Contributor I
29 Views

Hi Joe, I'm afraid I don't quite understand your suggestion.

My C code (test.c) is:-

main()

{

printf("Edison Board Initilized\n");

}

My test.systemd file (test.system) is:-

# !/bin/sh

[Unit]

Description=My Edison Activation

[Service]

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

[Install]

WantedBy=basic.target

[Install]

WantedBy=basic.target

Where and what do I place in these two files to see output as you suggest on power-up?

Thanks in advance

John

idata
Community Manager
29 Views

Hey John - A couple of things stand out. I think this is really all just some simple problems with Linux, which is what the Edison runs.

- Did you compile you C program on the Edison? I ask because you do not need the .exe extension in linux. Executables need to have the executable mode set (i.e. chmod +x fileName or chmod 755 fileName ).

- You do not need the "shebang" or shell line in your unit file (drop the # !/bin/sh) from your file.

-- Did you enable the service i.e. systemctl enable test.system ?

-- When you launch it manually what does it say (i.e. systemctl start test )

- Node does not run C programs, node is a javascript framework (Ok, it can call an executable, but avoid it).

- When you say "line of text on the console", are you connected to the edison using via ssh? I ask because if you are connected on the command line via ssh there is no need to run node, node is really just a web front end. People use it for more, but no need to interact with C if you are trying to put it on the command line/console.

-- If you run your test.exe does it print ? To do this run ./text.exe if the file is in your current directory.

It's a shame there is no good getting started with the Edison book.

Cheers,

-Joe

JMona1
New Contributor I
29 Views

Actually Joe I compiled the program test.c with GCC on the Edison. I know you don't have to have the .exe extension. I just use it to remind me what it is. The program runs fine from the command line when I boot and then log in to the user account root and type:- ./test.exe

Yes I do activate test.system with:- systemctl enable test.system

It works fine with no errors feedback.

Upon power up as the services are being activated I do see:-

"My Edison Activation" on the list. This indicates that test.system was called.

What I don't see is any text from the test.c (test.exe) program appearing;

On the console there should appear "Edison Board Initilized" before the logon prompt.

Currently I'm just connected to the Edison via a serial port --- to keep things simple.

On your system (whatever it is) can you get a program to run before/without the logon prompt.

Agree the absence of a decent "how to" book for the Edison/Eclipse setup is a real problem. The one out there "Programming the Intel Edison" by Donald Norris is useless.

John

idata
Community Manager
29 Views

 

Hi monahanz,

 

 

Your code is working! The reason you are not seeing any console output, is because in order to write any sort of text when the Edison reboots, you have to modify the kernel of your image.

 

 

I would recommend to create a routine that creates a text file and writes in it a "Hello World" instead of just doing a simple console output.

 

 

I hope you find this information useful, have a nice day!

 

 

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

I figured it out see:-

idata
Community Manager
29 Views

Hi monahanz,

 

 

I'm glad to hear that figure it out by your own! If you have any more questions, please don't hesitate to contact us.

 

 

We hope you have a nice day!

 

 

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

Thanks for your help Jose.

Actually I have one question on this. When I run the service (S100_Edison.service) viewing all the service messages on boot I see that my service is loaded. However it does not run (the few) remaining services. I currently have in the service file:-

[Unit]

 

Description=S100_Edison Program Activated <------</span>

 

After=pulseaudio.service

 

[Service]

 

ExecStart=/home/root/S100_Edison

 

[Install]

 

WantedBy=basic.target

pulseaudio seem to be near the end of the list. That one loads fine. I get after that:-

S100_Edison Program Activated

The root logon does not appear. It's not a big problem because my program runs OK but I'm worried something may be wrong.

Any suggestions what to do next?

John

idata
Community Manager
29 Views

Hi monahanz,

 

 

I'm not understanding your issue, could you maybe try to attach some screenshots?

 

 

Also when you mean the "root login does not appear", do you mean that you can't access your Linux console?

 

 

I will be waiting for your reply, have a nice day!

 

 

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

Here is the power-on messages Jose as the Edison boots up. See the picture.

You can see it never gets to the /root logon & password prompt.

Yet the service runs fine.

idata
Community Manager
29 Views

 

Hi monahanz,

 

 

Do you still have access to your Linux console?? If you do then everything should be working fine, if not try flashing again your image.

 

 

I will be waiting for your reply, have a nice day!

 

 

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

Jose, when the service is running there is no response from the Linux console. I cannot log on to /root because it never gets that far. My application does not use the Linus console -- just the pins on the breakout board. I flashed a completely new Edison breakout board today -- same result.

idata
Community Manager
29 Views

Hi monahanz,

I have just checked your code in the thread ( ), seems like when your service is activated the loop you start in test1.c never stops, this is the reason why you never get access to your "root login".

Everything seems to be working right, if you want access to your Linux console I would recommend to change your code in order to make it happen.

Hope you find this information useful, have a nice day!

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

I'm a bit confused then Jose. I understood a .service to be a separate tread running in the background while a "main" program is launched by the user is say ./root. that one would be started and stopped as needed. There seems to be numerous .services started and running as Linux boots up. Most seem to be running all the time. How is this done.

Also how is the order of the .services run. How can one make a .service be the very last one before the user logon prompt.

John

idata
Community Manager
29 Views

Hi monahanz,

Yes you are right that is how a system service works! In order to select when your service starts you have to use the "After" option, actually you use it in your service:

# !/bin/sh

 

[Unit]

 

Description=Test2 Program Activated <------<p> After=pulseaudio.service

 

[Service]

 

ExecStart=/home/root/test2.exe

 

[Install]

 

WantedBy=basic.target

I found really strange that you couldn't access your login in the Linux Console, so I decided to replicate your issue, see the images below.

As you can see I don't have problems accessing the login in my Linux Console. I really don't understand why is not working for you, since we have the same files, are you sure that you are using the latest image version?

I will be waiting for your reply, have a nice day!

Best Regards,

 

-Jose.
JMona1
New Contributor I
29 Views

Thanks for going to the trouble on that Jose.

Since then (over Christmas), I have noticed two things. It depends where I place the (test) .service. If I don't use the "After" command it comes at -- or towards the end and seems to be OK.

More important I too can get the above small program to work -- at least now -- not sure why not earlier.

However the "real program" using most of the Edison breakout pins still does not allowing me to access the Linux Console. This is quite a large program. I now suspect that one or more pins are causing the problem. What I have to do is build up the program using more an more pins. Unfortunately I will not be able to get back to trying that for at least a week or so.

I will post here when I get results.

Again thanks

John

idata
Community Manager
29 Views

Hi monahanz,

 

 

We will be waiting for results, have a nice day!

 

 

Best Regards,

 

-Jose.
Reply