Ubiquiti Employee
Posts: 627
Registered: ‎06-27-2012
Kudos: 375
Solutions: 31
Contributions: 6

mFi-CS: persist ampHours across reboot

Some users have been using a script like this to persist ampHours across mPort reboots.  This is for the very specfic case where you are using mFi-CS current sensor power estimation in the controller Energy Tab (by setting the voltage in a custom sensor definition).  Without this script, the ampHours get reset to 0 after reboot which causes the energy estimation to go down.

 

It takes advantage of the fact that /proc/analog/rmsSum# are writable.  It simply periodically records the values to flash, and writes those values back after reboot.

 

This is an end user script, so please be careful (make sure flash isn't written too often...).  

 

1) store it as /etc/persistent/rc.poststart
2) chmod +x  /etc/persistent/rc.poststart
3) save
4) reboot
 
#!/bin/sh
cp /etc/persistent/data/rmsSum* /proc/analog/ 2>/dev/null
while true; do
  cp /proc/analog/rmsSum* /etc/persistent/data/
  cfgmtd -w -p /etc
  sleep 3600
done

 

Senior Member
Posts: 3,366
Registered: ‎02-16-2008
Kudos: 2478
Solutions: 38

Re: mFi-CS: persist ampHours across reboot

Thanks Randy!

 

What happens to the script and saved data on a firmware update?

If it ain't broke, fix it anyway
To avoid the Gates of Hell, I use Linux
Professional Electron Wrangler
Member
Posts: 233
Registered: ‎10-30-2013
Kudos: 170
Solutions: 2

Re: mFi-CS: persist ampHours across reboot

Hey @UBNT-Randy,

 

This is awesome and would be REALLY useful in my applications but I dont know how to actually implement this scriptSmiley LOL

At this stage I am too incompetent to even know where to put it or how to get there...

 

Would you be able to walk me through it step by step?Smiley Happy

Emerging Member
Posts: 80
Registered: ‎04-07-2015
Kudos: 24
Solutions: 1

Re: mFi-CS: persist ampHours across reboot


@andre_BunduNet wrote:

 

Would you be able to walk me through it step by step?Smiley Happy


You login with SSH on the Mport in question and the follow the steps of @UBNT-Randy.

 

The Mport is running BusyBox it's a variant of Linux Distro.

Member
Posts: 233
Registered: ‎10-30-2013
Kudos: 170
Solutions: 2

Re: mFi-CS: persist ampHours across reboot

Hey @aavdberg,

 

Thank you very much for your help. I am comfortable logging in to the mPort with SSH but then what? Do I type the command /etc/persistent/rc.poststart and then chmod +x  /etc/persistent/rc.poststart?? When do you enter the script: 

#!/bin/sh
cp /etc/persistent/data/rmsSum* /proc/analog/ 2>/dev/null
while true; do
  cp /proc/analog/rmsSum* /etc/persistent/data/
  cfgmtd -w -p /etc
  sleep 3600
done

I feel really dumb but I need this to work and it seems like this should be an obvious feature by default... 

 

Thank you for your patience!

SuperUser
Posts: 15,107
Registered: ‎08-07-2008
Kudos: 7315
Solutions: 415
Contributions: 1

Re: mFi-CS: persist ampHours across reboot

Look up a program called winscp.

It's a graphical UI for ssh sessions.

When you first try to login choose SCP as the protocol.  Your PC files will be on the left and the device you logged into files on the right.

 

You will see how you can create a file and paste in that code.

Walks in, tells it like it is, walks out , milks a cow
Member
Posts: 233
Registered: ‎10-30-2013
Kudos: 170
Solutions: 2

Re: mFi-CS: persist ampHours across reboot

Thanks @alan87i! I will do that.

 

Have learnt so much over the last few weeks, fun times.

Thank you to all you guys for always taking the time to assist! Blush5

New Member
Posts: 2
Registered: ‎07-20-2015

Re: mFi-CS: persist ampHours across reboot

Hello
I have a problem with a plug mpower 3 port.
After the reboot you give all 3 ports back in the ON state.
Is there a solution that after reboot the 3 ports to remain in the state they were before you give them reboot, ie OFF

New Member
Posts: 14
Registered: ‎09-05-2015
Kudos: 12

Re: mFi-CS: persist ampHours across reboot


 
1) store it as /etc/persistent/rc.poststart
2) chmod +x  /etc/persistent/rc.poststart
3) save
4) reboot


Step three above is not really clear. By "save" you need to execute the

cfgmtd -w -p /etc  

command manually so that your new rc.poststart script gets persisted. The cfgmtd command is copying the /etc directory to non volitle storage.

 

Note that after the mPort reboots there is a three minute window where your ampHours will be wrong. This is because the native startup scripts wait three minutes before launching rc.poststart

Highlighted
New Member
Posts: 8
Registered: ‎04-30-2014

Re: mFi-CS: persist ampHours across reboot

[ Edited ]

1. by Putty can store script? if can what command 

1. sleep 3600 is command to flash isn't written too often? It one time in a hour? Can change it to 86400 to write one time in one day for example?
2. save cfgmtd -w -p /etc this correct step three?
3. how to delete this script and this option to persistant save, in case to move another sensor, not current for example and flash isn't written unnecessarily