Run my program after my gateway power up (operation system is OpenWrt)

Hi every one,
My name is Ahmad, I'm a beginner in OpenWrt OS. I've developed a program for a gateway to detect Bluetooth devices around the gateway and then send them to the Azure.
Everything is OK and I can run it manually, but, I want to run it automatically after power-up. I mean after completing the operating system load.

Could you please let me know how can I do it?

Add it to /etc/rc.local

1 Like

I did it, but it does not working. My program should be running all the time. According to the topic description my program detect all Bluetooth devices around the gateway and send them to the Azure every 1 second.

chmod +x? Or /root/program.sh & for background process?

1 Like

Then define there a detached shell in which you run the program, so that the program gets started but does not block the execution further...

( /bin/script.sh )&
1 Like

Have a look at how other daemons are stated from "/etc/init.d", and have a look to the documentation about init scripts and procd.

Perhaps your question is "how to make it run ever second"? In that case, just do a loop like "while sleep 1s; do ...; done" around your current script.

1 Like

I've checked https://openwrt.org/docs/techref/initscripts and did it but it did not work.
Also, it does not need to run every 1 second. The program does it insidely.

I don't understand what do you mean.

In the /etc/rc.local shell script, define your own program to be run in a separate shell, and detach that shell with "&", so that once launched, it remains alive despite the host script /etc/rc.local reaching end and terminating.

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

( /bin/myscript.sh )&

exit 0

My program location is:
/usr/bluemqtt

so, according to your script :
( /bin/myscript.sh )&

should I use this script?
( /usr/bluemqtt )&

In that case, you did it wrong.

Fine, it will be easier then.

Could you let me know how can I run it every 1 second?
My program stop working during execution. After one time sending data to the Azure automatically terminate. So, I think I should run it again. I used this command, but it still runs one time.

while true: do
cd /usr
./bluemqtt
sleep 1
done

I already told you, it's a couple of posts above yours, then you told me the program already does it...

In your code, "while true: do" should be "while true; do" instead.

1 Like

Thanks, guys, I've solved the problem.
This part was the solution:

" define there a detached shell in which you run the program so that the program gets started but does not block the execution further...

( /bin/script.sh )&
Exit 0


Also, my program has a bug too.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.