Automatic shutdown at powerloss

Post here your applications done based on UPiS
Share your ideas about new possible applications

Re: Automatic shutdown at powerloss

Postby LyMar17 » Sun Jun 29, 2014 1:16 pm

Ahhh, that makes sense :lol:

3 days ago I didn't even know of the 'sudo' command, now I'm implementing scripts on a Pi :D

I'll give it a try!
LyMar17
 
Posts: 16
Joined: Thu Jun 26, 2014 8:20 pm

Re: Automatic shutdown at powerloss

Postby maestro » Sun Jun 29, 2014 2:03 pm

Just a comment. sudo is needed when you are logged in as a non-privileged user and need to run some command with root privileges. When you are logged in as root, sudo command is pointless :)

Vit
maestro
 
Posts: 32
Joined: Tue Mar 11, 2014 7:07 pm

Re: Automatic shutdown at powerloss

Postby LyMar17 » Sun Jun 29, 2014 3:09 pm

well, at least the script is running.
However it seems the i2cget command isn't recognised.

root@raspbmc:/home/pi# /home/pi/upis/shutdown.sh
/home/pi/upis/shutdown.sh: line 13: i2cget: command not found
/home/pi/upis/shutdown.sh: line 13: i2cget: command not found
/home/pi/upis/shutdown.sh: line 13: i2cget: command not found
/home/pi/upis/shutdown.sh: line 13: i2cget: command not found


Probably a library missing?

Martijn
LyMar17
 
Posts: 16
Joined: Thu Jun 26, 2014 8:20 pm

Re: Automatic shutdown at powerloss

Postby LyMar17 » Sun Jun 29, 2014 3:40 pm

ok, fixed the i2c problem.

this is was comes up.

root@raspbmc:/home/pi# /home/pi/upis/shutdown.sh
pi: Sun Jun 29 16:37:13 CEST 2014 Power is lost!
pi: Sun Jun 29 16:37:14 CEST 2014 Power is back
pi: Sun Jun 29 16:37:15 CEST 2014 Power is lost!
pi: Sun Jun 29 16:37:18 CEST 2014 Power is back
pi: Sun Jun 29 16:37:23 CEST 2014 Power is lost!
pi: Sun Jun 29 16:37:26 CEST 2014 Power is back
pi: Sun Jun 29 16:37:27 CEST 2014 Power is lost!



At this moment the UPiS is getting power from mains...

after disconnecting the mains

Broadcast message from pi@raspbmc
(/dev/pts/1) at 16:39 ...

The system is going down for halt NOW!
pi: Sun Jun 29 16:39:56 CEST 2014 Exitting...


so the script is now working fine :D :D
LyMar17
 
Posts: 16
Joined: Thu Jun 26, 2014 8:20 pm

Re: Automatic shutdown at powerloss

Postby maestro » Sun Jun 29, 2014 6:36 pm

Last step is to make it run after start :) Simply add following to
/etc/rc.local
file:
Code: Select all
nohup /home/pi/upis/shutdown.sh &

The events from the script are logged in the syslog, so you can find them in /var/log/messages file at any time :)

Vit
maestro
 
Posts: 32
Joined: Tue Mar 11, 2014 7:07 pm

Re: Automatic shutdown at powerloss

Postby LyMar17 » Mon Jun 30, 2014 7:58 am

working perfectly :mrgreen:
LyMar17
 
Posts: 16
Joined: Thu Jun 26, 2014 8:20 pm

Re: Automatic shutdown at powerloss

Postby SteveMilner » Mon Jun 30, 2014 11:04 am

Hello Pimaster.

This sounds exactly like the solution that I need. However, I am new to this, but not new to Linux so perhaps you can help me please:

I have the Basic model.

1) What version of the firmware will be needed to support this function?
2) How do I check the version of firmware on the supplied basic module?
3) What software do I need to install onto my Raspberry Pi (sudo apt-get is how I install software) - I2C Tools? Will I need to implement the RTC clock as well?
4) What Jumper Settings do I need to make on the basic model which differ from the factory supplied settings?
5) What should I name my File Safe Shutdown script and what directory should it be placed in?
6) What command do I need to issue to change the delay between loss of external power and the execution of the safe shutdown script to be 30 seconds?

I hope you can help.


Pimaster wrote:Hi,
there is already implemented PICo command which define the time you need to automatic shutdown when on battery powering

5 or 0x05 fssd_batime Byte Common R/W File Safe Shut Down Timer for Unconditional Automatic File Safe Shutdown when UPiS is in BAT PWR Mode (loose the cable power) in seconds in HEX format

Read: Anytime, Return actual fssd_batime value

Write: 0xff – Disable the timer, default value

Write: 0x01 – 0xfe time in seconds when UPiS+RPi shutdown after cable power will go out (EPR or USB)

it is tested and working

just use it

warmest regards
Pi Master
SteveMilner
 
Posts: 14
Joined: Mon Jun 30, 2014 10:55 am

Re: Automatic shutdown at powerloss

Postby Pimaster » Mon Jun 30, 2014 11:45 am

Dear Steve,
Thank you for your post!!
Please find my answers in the text as usual.


SteveMilner wrote:Hello Pimaster.

This sounds exactly like the solution that I need.
Thank you, hope so !
However, I am new to this, but not new to Linux so perhaps you can help me please:
OK

I have the Basic model.
OK

1) What version of the firmware will be needed to support this function?
The automatic [b]Files Safe Shut Down - FSSD - is implemented at the beginning, however during the time it has been improved in order to cover more users need following various requests we received during the time[/b]

2) How do I check the version of firmware on the supplied basic module?
You have basically 2 way to do it
1. with @commands -> @version or @status from terminal program (running on RPi or remote PC)
2. using the PICo command viewing the appropriate variable with the following command
$sudo i2cget -y 1 0x6B 0

However, please notice that the PICo interface has been implemented and still developing from version 1.6. The final version of this interface will be with released official version of the firmware update 1.1, however to to many changes and updates we done in this version it is still under extensively testing and debugging and not yet released.


3) What software do I need to install onto my Raspberry Pi (sudo apt-get is how I install software) - I2C Tools? Will I need to implement the RTC clock as well?
YES, I2C TOOLS


4) What Jumper Settings do I need to make on the basic model which differ from the factory supplied settings?
Look, the Jumpers settings are are usual set to support USB connection due to testing done in our premisses. Depending to what serial connectivity you like to have you need to have a proper settings. i.e. if you like to handle your UPiS via PC terminal then settings need to route the UPiS serial port to the USB bridge, if you like to handle the UPiS via RS232 from the RPi, the the setting need to route its (UPiS) serial port to the RPi (you will need to make then also some changes in the RPi settings).
Please follow the manual with detailed description of it.


The PICo interface is always as far you have installed i2c tool and I2C pins of the UPiS wired to I2C of the RPi (with Jumpers)

5) What should I name my File Safe Shutdown script and what directory should it be placed in?
The exact script ( a working sample) is provided in the manual, as also the place and name where it need to be place. As far it is a sample, you have always the possibility to write your own based on our example - i.e. based on interrupt and not pooled

6) What command do I need to issue to change the delay between loss of external power and the execution of the safe shutdown script to be 30 seconds?
The former implementation of the FSSD was based on the final discharge of the battery. Actual version, supported by the 1.7 and later one, has an implemented PICo command where you can define the time delay needed to FSSD your RPi when power loss. It is up to 254 second, defined in a proper PICo variable. Please read the attached to each firmware release PDF file with detailed description

I hope you can help.
Please do not hesitate to ask again if you need any additional clarification, or I have not so clear describe something.
We are here to support you !!

Warmest Regards
Pi Master


Pimaster wrote:Hi,
there is already implemented PICo command which define the time you need to automatic shutdown when on battery powering

5 or 0x05 fssd_batime Byte Common R/W File Safe Shut Down Timer for Unconditional Automatic File Safe Shutdown when UPiS is in BAT PWR Mode (loose the cable power) in seconds in HEX format

Read: Anytime, Return actual fssd_batime value

Write: 0xff – Disable the timer, default value

Write: 0x01 – 0xfe time in seconds when UPiS+RPi shutdown after cable power will go out (EPR or USB)

it is tested and working

just use it

warmest regards
Pi Master
Warmest Regards
PiM
---
Designing with Mentor Graphics PADS - www.pads.com
Please read and follow the PiForum rules
http://www.forum.pimodules.com/viewtopic.php?f=13&t=196
---
Pimaster
Site Admin
 
Posts: 1593
Joined: Fri Sep 14, 2012 7:50 am

Re: Automatic shutdown at powerloss

Postby SteveMilner » Thu Jul 03, 2014 9:55 am

I am working my way towards this as a solution, and thanks for your help in other posts.

After the script has executed the shutdown and the Pi has shut down, will it automatically restart when the main power is restored?

If not, can anyone think of a way this can be achieved.

My application is in car use. I want to power down safely after the car has bee switched off, which this topic covers. After I switch the car back on I want it to be powered up.

Regards,
Stephen
SteveMilner
 
Posts: 14
Joined: Mon Jun 30, 2014 10:55 am

Re: Automatic shutdown at powerloss

Postby LyMar17 » Thu Jul 03, 2014 7:31 pm

yes it will ;)
LyMar17
 
Posts: 16
Joined: Thu Jun 26, 2014 8:20 pm

PreviousNext

Return to UPiS Users Application

Who is online

Users browsing this forum: No registered users and 1 guest

cron