Mausberry Switch Script

Raspberry Pi related support

Mausberry Switch Script

Postby thedman! » 08 Apr 2016, 16:39

Hi Chaps,

I'm trying to install a mausberry switch. Its physicaly connected properly...

The instructions to install are:

For Arch:

1. wget http://files.mausberrycircuits.com/setupArch.sh
2. bash setupArch.sh
3. reboot

1. is fine
2. gives the error:

The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).

Has anyone got any idea how I should get the script installed given this???

Cheers,

Dave.
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

Re: Mausberry Switch Script

Postby thedman! » 08 Apr 2016, 18:44

The script of the setup file is:

echo '#!/bin/bash

#this is the GPIO pin connected to the lead on switch labeled OUT
GPIOpin1=23

#this is the GPIO pin connected to the lead on switch labeled IN
GPIOpin2=24

echo "$GPIOpin1" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
echo "$GPIOpin2" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction
echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
while [ 1 = 1 ]; do
power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
if [ $power = 0 ]; then
sleep 1
else
poweroff
fi
done' > /etc/switch.sh
chmod 777 /etc/switch.sh
echo '[Unit]
Description=MausBerry

[Service]
ExecStart=/bin/bash /etc/switch.sh

[Install]
WantedBy=multi-user.target' > /etc/systemd/mausberry.service
systemctl enable /etc/systemd/mausberry.service
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

Re: Mausberry Switch Script

Postby PeteB » 08 Apr 2016, 19:08

I used one of these for a while, not on Arch though (don't have one installed now).

Ran through the install instructions after your post, and seemed to install fine... Here is what I get when I follow the steps.


1. Output of wget:
Code: Select all
[root@runeaudio ~]# wget http://files.mausberrycircuits.com/setupArch.sh
--2016-04-08 19:08:59--  http://files.mausberrycircuits.com/setupArch.sh
Resolving files.mausberrycircuits.com (files.mausberrycircuits.com)... 50.62.52.1
Connecting to files.mausberrycircuits.com (files.mausberrycircuits.com)|50.62.52.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 779 [application/x-sh]
Saving to: ‘setupArch.sh’

setupArch.sh        100%[=====================>]     779  --.-KB/s   in 0s     

2016-04-08 19:09:00 (19.4 MB/s) - ‘setupArch.sh’ saved [779/779]


2. Output of setup:
Code: Select all
[root@runeaudio ~]# bash setupArch.sh
Created symlink from /etc/systemd/system/multi-user.target.wants/mausberry.service to /etc/systemd/mausberry.service.
Created symlink from /etc/systemd/system/mausberry.service to /etc/systemd/mausberry.service.


Were you logged in as root when you installed it?
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Mausberry Switch Script

Postby thedman! » 08 Apr 2016, 19:32

Hi Pete,

Thanks for your help. Yes I was logged in a root, i've tried twice since, still get the same message

Dave
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

Re: Mausberry Switch Script

Postby PeteB » 08 Apr 2016, 19:49

Ok.... I JUST downloaded and tried it after your post, b/c I want to use it in the future, even though I do not have the board connected now...

After reboot,
Code: Select all
systemctl list-units
shows

Code: Select all
mausberry.service   loaded active running   MausBerry


edit: In other words, I am trying to say you do not even need the board plugged and the script will still run. AFAIK, it just monitors a GPIO line, and executes shutdown command when it senses the switch being pressed.
PeteB
 
Posts: 421
Joined: 06 Feb 2016, 05:07

Re: Mausberry Switch Script

Postby hondagx35 » 08 Apr 2016, 20:27

Hi Dave,

change the last two lines to
Code: Select all
[Install]
WantedBy=multi-user.target' > /usr/lib/systemd/system/mausberry.service
systemctl enable mausberry.service


On arch the unit files should go to /usr/lib/systemd/system.
All enabled services will get symlinked to /etc/systemd/system/multi-user.target.wants/ or where the install section points to.

Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Mausberry Switch Script

Postby thedman! » 09 Apr 2016, 07:54

Thanks for your help so far, I've changed the last two lines to those you have recommended and when I issue

Code: Select all
sudo bash setupArch.sh


I get the message "Failed to execute operation: Too many levels of symbolic links"

Thanks again,

Dave.
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

Re: Mausberry Switch Script

Postby hondagx35 » 09 Apr 2016, 10:08

Hi thedman!,

you have to remove the old symlinks first.

Search for "mausberry.service" and delete all occurrences.
Code: Select all
find / -name mausberry.service


Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Mausberry Switch Script

Postby thedman! » 10 Apr 2016, 09:09

Wow! The script has installed properly now and the pi shutdown when pressed so thanks a million for your help people. However it started straight back up again, TBH I expected that, as it is a momentary switch. So I'll experiment with a different switch. However, I've trashed a jumper cable and the switch does nothing at the moment :roll:
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

Re: Mausberry Switch Script

Postby thedman! » 12 Apr 2016, 23:06

In other words, I am trying to say you do not even need the board plugged and the script will still run. AFAIK, it just monitors a GPIO line, and executes shutdown command when it senses the switch being pressed.


I've just grasped what you've said there Pete!

So in other words if I swap the switch to a latching one, I can remove the mausberry circuit, and it will shut down when I Press the switch. Before I trashed the cable it was shutting down when I pressed the switch and then immediately booting back up, but a latching switch would prevent this.... Hopefully all my replacement parts will arrive tomorrow so I can test this....
thedman!
 
Posts: 62
Joined: 24 Mar 2016, 15:45

support RuneAudio Donate with PayPal

Next

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 4 guests