Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
2,379 Views

how to startup automatically my script file in intel galileo gen 2

Hi,

I am a beginner of working in the Intel Galileo Gen 2 board. I am using Eclipse IDE to build the script into the board. I am working in the blinking led projects it worked.

Every time I am using putty to executing the led blink project.

I want when I am switch on the board that led blink project it will be automatically executive.

what is the procedure it will be run automatically my script?

 

any body know about that please share with me.

we can also share with my mail id: mailto:Chinnasamytcs6007@gmail.com Chinnasamytcs6007@gmail.com

 

Tags (1)
8 Replies
Highlighted
Employee
1,377 Views

Hello chinna007,

If I'm not mistaken, once you upload a script from the Eclipse IDE, the scripts files get stored on /tmp. This directory gets erased every time the board reboots. My suggestion, if you want to get a script that starts automatically on boot, is to compile the script on the board's file system (using gcc or g++, etc.) and create a system service that starts it on boot (using https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and... systemd).

Peter.

Highlighted
Novice
1,377 Views

HI Intel_Peter,

I am using Eclipse IDE it will make a image file after build the script file(e.g blink.c file).

I got a blink file. After i am build the blink file into Intel Galileo Gen 2.

It was blinked. that time i plug out the power cable and plug on the power cable it not blinked.

once again i build the same file on the board.

how to run that build file automatically when i am plug up the power.

0 Kudos
Highlighted
Employee
1,377 Views

If you want the script to start automatically on boot, then you will have to create a system service. I'll give you a brief example on how to do one:

The first thing you will need is your script. Right now, I will use a simple Blink script:

# include

# include

# include

# include "mraa/gpio.h"

int main(int argc, char** argv)

{

mraa_platform_t platform = mraa_get_platform_type();

mraa_gpio_context gpio, gpio_in = NULL;

char* board_name = mraa_get_platform_name();

int ledstate = 0;

gpio = mraa_gpio_init(13);

fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);

mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

while(1)

{

ledstate = !ledstate;

mraa_gpio_write(gpio, ledstate);

sleep(1);

}

return 0;

}

Compile it and create an executable file with the command:

gcc blink.c -o blink.out -lmraa

After you've done that you can test it with "./blink.out" and you should see a blinking light on your board.

Now we can create our system service:

It'll look like this:

# !/bin/sh

[Unit]

Description=Starts a blink script on boot

[Service]

ExecStart=/home/root/blink.out

Type=idle

[Install]

WantedBy=basic.target

This file must be named with an extension ".service", so my service is called blink.service. And it must be stored in /lib/systemd/system/.

After you have stored the service file, type the command "systemctl enable blink.service". If you named your service different change blink.service for what you called it.

Now if you reboot the board you should see the blink starting on boot.

Peter.

0 Kudos
Highlighted
Novice
1,377 Views

Hi Intel_Peter,

Thanks. Now it is working when i am plug up the board. it will automatically running.

gcc blink.c -o blink.out -lmraa

 

In the above line why we use -lmraa to create a executable file

If any script we can use -lmraa to create a executable file.

 

 

chinna007

 

0 Kudos
Highlighted
Employee
1,377 Views

china007,

"-lmraa" is not used to create an executable file but to include MRAA when compiling it with gcc. In fact the option to create the executable in that command is "-o". If you would like to learn more about how to use gcc, I'd suggest you to check http://linux.die.net/man/1/gcc gcc(1): GNU project C/C++ compiler - Linux man page.

Peter.

0 Kudos
Highlighted
Community Manager
1,377 Views

And further down the line in creating system services, this link (https://wiki.archlinux.org/index.php/Systemd# Basic_systemctl_usage https://wiki.archlinux.org/index.php/Systemd# Basic_systemctl_usage) will come in handy!

0 Kudos
Highlighted
Community Manager
1,377 Views

If you run it as a service, where does stdout and stderr go?

Highlighted
Community Manager
1,377 Views

If you want to keep them, you can append them into a file using the ">" or ">>" operators.