Safely powering down my pi

341 views
Skip to first unread message

ltsc...@gmail.com

unread,
Aug 14, 2018, 11:35:56 PM8/14/18
to motioneye
Hello all. I'm a total noob at the Pi world and I'm loving it.

A little background to my project; I am trying to create a low cost dashcam. I know i can buy one but what fun is that?
I would like to be able to connect to it using an android or a iphone. I have a RPI3 B+.

Now as for my questions:

1-I would like to know if there's a way to install a power switch to my RPI3b+ via the GPIO??
I don't want to pull the power since I it'll corrupt my files.

2- Is there a way to connect to motioneye just using the pi's internal WiFi or Bluetooth and not be connected to a local network?

Thank you in advance for any information. I will surely keep searching as well.

Bob Findlay

unread,
Aug 15, 2018, 7:17:18 AM8/15/18
to motioneye
1 yes just install a switch to the gpio and then look in software for it being closed.  when you detect that, perform a shutodown
2 yes.  I believe you can set the wifi up on the pi to be an access point.  you can then connect another device directly to the pi


https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

obviously you won't need to do the routing and masquerading

Jürgen

unread,
Aug 19, 2018, 11:59:41 AM8/19/18
to motioneye
Hello,

I am using the following script to shutdown or reboot my MotionEyeOS installation based on GPIO-Pins:

open SSH connection to MotionEyeOS (bash), mount the folder writable:
• >  mount -o remount,rw /
• >  nano /usr/sbin/checkGPIOshutdownReboot.py
• copy script into editor, save and close the editor (ctrl-o,  Return, ctrl-x)
• make the script executable:
• > chmod +x /usr/sbin/checkGPIOshutdownReboot.py
• check it by running it from bash:  python /usr/sbin/checkGPIOshutdownReboot.py
• make the script autostart at every reboot (I gave it 300 seconds delay - in case of any troubles I would be able to open again ssh connection and stop the script)
• >  nano /data/etc/userinit.sh
•  copy the following into userinit.sh 
• (/bin/sleep 300 && python /usr/sbin/checkGPIOshutdownReboot.py)&


Script checkGPIOshutdownReboot.py:

#!/usr/bin/python3
# HW-Pin-Zaehlung verwendet!!
# FHEM: /home/scripts/checkGPIOshutdownReboot.py
# MotionEyeOS: /usr/sbin/checkGPIOshutdownReboot.py
# MotionEyOS:  mount -o remount,rw /
import os, sys, time, RPi.GPIO as gpio
gpio
.setmode(gpio.BOARD)   # Pin-Nummern des P1/J8-Headers
# chan_list = [5,40]
# gpio.setup(chan_list, gpio.IN, pull_up_down = gpio.PUD_UP)
gpio
.setup(5, gpio.IN, pull_up_down = gpio.PUD_UP)     # Pin  5 ist Reboot   - 3. Reihe
gpio
.setup(40, gpio.IN, pull_up_down = gpio.PUD_UP)    # Pin 40 ist Poweroff - letzte Reihe bei USB Buchse
while 1:
 
print "checking..."
 
if gpio.input(5)==gpio.LOW:
   
print "ok - reboot now"
    os
.system("reboot")
    sys
.exit()
 
if gpio.input(40)==gpio.LOW:
   
print "ok - power off now"
    os
.system("poweroff")
    sys
.exit()
  time
.sleep(5)



Good luck :)

cheers.


Reply all
Reply to author
Forward
0 new messages