Skip to content

Instantly share code, notes, and snippets.

@tomvdb
Created May 22, 2022 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomvdb/4f0feb0dafecd7992ab5050a9b8a24fd to your computer and use it in GitHub Desktop.
Save tomvdb/4f0feb0dafecd7992ab5050a9b8a24fd to your computer and use it in GitHub Desktop.
Longmynd Automatic Boot
To setup longmynd on pi boot:
Create service file
sudo nano /etc/systemd/system/longmynd.service
Enter this into the text file:
[Unit]
Description=Longmynd Client
After=multi-user.target
Requires=network.target
[Service]
Type=idle
User=pi
ExecStart=/home/pi/longmynd/longmynd -W 8080 -i 230.0.0.12 4003 -I 230.0.0.12 4002 741538 250
Restart=always
[Install]
WantedBy=multi-user.target
then do
sudo systemctl daemon-reload
sudo systemctl enable longmynd.service
it should then start on reboot, you can also use these commands manually
sudo systemctl stop longmynd.service
sudo systemctl start longmynd.service
sudo systemctl status longmynd.service
@GRBlake488
Copy link

Tom,

I get an error when I try to run this on my Orange Pi Zero 2 with Debian Buster.

It says it is missing an EQUAL sign (=) in [12] ???

This is my version:

#To setup longmynd on pi boot:

#Create service file

#sudo nano /etc/systemd/system/longmynd.service

#Enter this into the text file:

[Unit]
Description=Longmynd Client
After=multi-user.target
Requires=network.target

[Service]
Type=idle
User=pi
ExecStart=/root/longmynd/longmynd/longmynd -W 8080 -i 192.168.10.4 4003 -I 192.168.10.4 4002 2400000 1500
Restart=always

[Install]
WantedBy=multi-user.target

then do

sudo systemctl daemon-reload
sudo systemctl enable longmynd.service

#it should then start on reboot, you can also use these commands manually

#sudo systemctl stop longmynd.service
#sudo systemctl start longmynd.service
#sudo systemctl status longmynd.service

Thanks.

George Blake

@GRBlake488
Copy link

I don't think the brackets "[ ]" nor the "THEN DO" lines are commands, correct?

I am going to try it with these commented out.

============================================================

#To setup longmynd on pi boot:

#Create service file

#sudo nano /etc/systemd/system/longmynd.service

#Enter this into the text file:

#[Unit]
Description=Longmynd Client
After=multi-user.target
Requires=network.target

#[Service]
Type=idle
User=pi
ExecStart=/root/longmynd/longmynd/longmynd -W 8080 -i 192.168.10.4 4003 -I 192.168.10.4 4002 2400000 1500
Restart=always

#[Install]
WantedBy=multi-user.target

#then do

sudo systemctl daemon-reload
sudo systemctl enable longmynd.service

#it should then start on reboot, you can also use these commands manually

#sudo systemctl stop longmynd.service
#sudo systemctl start longmynd.service
#sudo systemctl status longmynd.service

@infomaniac50
Copy link

infomaniac50 commented Jul 21, 2023

You need to be logged in as the pi user when you clone the repository from GitHub. If the machine is defaulting to root then you need to switch to the pi user. If you changed to root yourself then you need to exit the shell and go back to the pi user.

Exit the Root Shell

exit

Switching Users as Root

 sudo --user pi --shell /bin/bash --login

Typing a hashtag # tells the shell to ignore everything after that until the end of the line. These are called comments.

In the list of commands below you don't have to type the comments. They are there to provide context.

Installing the Program

# Make sure we are logged in as the pi user
# Typing whoami should return pi
# If it returns root then you should refer to "Switching Users as Root" or "Exit the Root Shell"
# If "Exit the Root Shell" disconnects you from the machine then it means you are logged in as root by default when you connect.
# You will have to switch users instead.
# The whoami command returns the name of the user that ran it
whoami
# Make sure we are in the home directory of the pi user
# Typing pwd and enter should return /home/pi
pwd
# Type cd /home/pi if you are not in the home directory of the pi user
cd /home/pi
# Clone the repository from GitHub
git clone https://github.com/philcrump/longmynd.git
# Open the directory with the source code
cd longmynd
# Compile the program
make
# Make sure the program is executable
# It should look a bit like this. -rwxr-xr-x 1 pi pi 1071664 Feb  2 00:38 /home/pi/longmynd/longmynd
# The first x is what we care about. This tells you the program is executable by the user that owns the file.
# In this case the owner is pi since we compiled the program while logged in as pi.
ls -l /home/pi/longmynd/longmynd
# Install the udev rules with 
sudo cp minitiouner.rules /etc/udev/rules.d/
# then unplug and replug the minitiouner
# You can try running the program if everything else worked correctly.
# The period in front of the current slash is an alias for the current directory.
# The shell swaps out the period for /home/pi/longmynd
# We started out in /home/pi when we logged in.
# Then we switched to the longmynd directory.
# Typing pwd should return /home/pi/longmynd
# Run longmynd specifying the following parameters (adapt to your network)
./longmynd -W 8080 -i 192.168.0.105 4003 -I 192.168.0.105 4002 741538 1500

Installing the SystemD Unit File

# To setup longmynd on pi boot:
# Create service file
sudo nano /etc/systemd/system/longmynd.service

Enter the text below exactly as specified except for the IP address

[Unit]
Description=Longmynd Client
After=multi-user.target
Requires=network.target

[Service]
Type=idle
User=pi
ExecStart=/home/pi/longmynd/longmynd -W 8080 -i 230.0.0.12 4003 -I 230.0.0.12 4002 741538 250
Restart=always

[Install]
WantedBy=multi-user.target

When you are done press Control+X on the keyboard. This is the hotkey for exit in nano. Select Y to save the changes and press enter to confirm the filename to write.

Telling SystemD about the new service file and enabling start on boot

# Tell systemd to check all of the service definition files again.
sudo systemctl daemon-reload
# Tell systemd to start this service at boot.
sudo systemctl enable longmynd.service

Management commands to use for later.

# If everything is done correctly the service will start the next time the machine boots.
# The enable command you typed earlier only tells SystemD that you want to start this service at every boot.
# It doesn't start the command immediately.
# You don't need to type all of the commands here. These are just for management at a later date.
# If you want to start the service now without rebooting
sudo systemctl start longmynd.service
# You can check the service status after it is started.
sudo systemctl status longmynd.service
# You don't need the next command right now.
# If new code comes out on GitHub
# You should stop the service before upgrading the program
sudo systemctl stop longmynd.service

@GRBlake488
Copy link

Derek,

Longmynd will execute manually on USER=ROOT and will send data to my Laptop, but it will not send data when I run it under USER=PI.

Is this a permission issue? I tried:

./longmynd -W 8080 -i 192.168.10.4 4003 -I 192.168.10.4 4002 741538 1500

The laptop receives fine under ROOT but not under PI. I don't think the ETH0 is set or something is blocking transmission.

When I try: IFCONFIG it returns 192.168.10.3 which is correct.

Thanks.

George B.

@GRBlake488
Copy link

It would have been nice if Tom had made this easier for Beginners. His instructions assume you have some knowledge of Linux. Unfortunately, there are those of us who are hardware hacks and not programmers.

Here is what was finally successful:

=======================================================================================

#You need to be logged in as the pi user when you clone the repository from GitHub. If the machine is defaulting to root then you need to #switch to the pi user. If you changed to root yourself then you need to exit the shell and go back to the pi user.
#Exit the Root Shell

exit

#Switching Users as Root

sudo --user pi --shell /bin/bash --login

#Typing a hashtag # tells the shell to ignore everything after that until the end of the line. These are called comments.

#In the list of commands below you don’t have to type the comments. They are there to provide context.
#Installing the Program

#Make sure we are logged in as the pi user
#Typing whoami should return pi
#If it returns root then you should refer to "Switching Users as Root" or "Exit the Root Shell"
#If "Exit the Root Shell" disconnects you from the machine then it means you are logged in as root by default when you connect.
#You will have to switch users instead.
#The whoami command returns the name of the user that ran it

whoami

#Make sure we are in the home directory of the pi user
#Typing pwd and enter should return /home/pi
pwd
#Type cd /home/pi if you are not in the home directory of the pi user

cd /home/pi

#Clone the repository from GitHub

git clone https://github.com/philcrump/longmynd.git

#Open the directory with the source code

cd longmynd

#Compile the program

make

#Make sure the program is executable
#It should look a bit like this. -rwxr-xr-x 1 pi pi 1071664 Feb 2 00:38 /home/pi/longmynd/longmynd
#The first x is what we care about. This tells you the program is executable by the user that owns the file.
#In this case the owner is pi since we compiled the program while logged in as pi.

ls -l /home/pi/longmynd/longmynd

#You can try running the program if everything else worked correctly.
#The period in front of the current slash is an alias for the current directory.
#The shell swaps out the period for /home/pi/longmynd
#We started out in /home/pi when we logged in.
#Then we switched to the longmynd directory.
#Typing pwd should return /home/pi/longmynd
#Run longmynd specifying the following parameters (adapt to your network)

./longmynd -W 8080 -i 192.168.0.105 4003 -I 192.168.0.105 4002 741538 1500

#NOTE: The IP ADDRESS is the address where you are SENDING the data from the Raspberry / Orange Pi!

#Installing the SystemD Unit File

#To setup longmynd on pi boot:
#Create service file

sudo nano /etc/systemd/system/longmynd.service

#Enter the text below exactly as specified except for the IP address.
#NOTE: The IP ADDRESS is the address where you are SENDING the data from the Raspberry / Orange Pi!


**[Unit]
Description=Longmynd Client
After=multi-user.target
Requires=network.target

[Service]
Type=idle
User=pi
ExecStart=/home/pi/longmynd/longmynd -W 8080 -i 230.0.0.12 4003 -I 230.0.0.12 4002 741538 250
Restart=always

[Install]
WantedBy=multi-user.target**


#When you are done press Control+X on the keyboard. This is the hotkey for exit in nano. Select Y to save the changes and press enter to #confirm the filename to write.

#Telling SystemD about the new service file and enabling start on boot

#Tell systemd to check all of the service definition files again.

sudo systemctl daemon-reload

#Tell systemd to start this service at boot.

sudo systemctl enable longmynd.service

#Management commands to use for later.

#If everything is done correctly the service will start the next time the machine boots.
#The enable command you typed earlier only tells SystemD that you want to start this service at every boot.
#It doesn't start the command immediately.
#You don't need to type all of the commands here. These are just for management at a later date.
#If you want to start the service now without rebooting

sudo systemctl start longmynd.service

#You can check the service status after it is started.

sudo systemctl status longmynd.service

#You don't need the next command right now.
#If new code comes out on GitHub
#You should stop the service before upgrading the program

sudo systemctl stop longmynd.service

​--

Derek Chafin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment