LowPowerLab Forum

Software support => Pi Gateway => Topic started by: Lukapple on August 24, 2017, 08:00:51 AM

Title: Request: Voltage parameter for low battery warning [done in v8.10.0]
Post by: Lukapple on August 24, 2017, 08:00:51 AM
Hi Felix,
Can you please add a parameter for setting a voltage value for low battery warning, which is visible on gateway home page? Voltage value is currently hard coded to 3.55(index.html page).
You could add it to metrics file with default value 3.55. .
My mote runs on 2xAA and reports 3.29 with full batteries. 

Thanks
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on August 24, 2017, 08:14:27 AM
Yes, something I wanted to do at some point.
Would you need a setting per node or a global setting?
The latter is easy, former would require more coding.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on August 24, 2017, 08:22:31 AM
Global setting(settings.json5) will work for my current setup, but it would be probably better if you could set it per node.  :)
You should solve this same way as icons - see getNodeIcon(node) function.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on August 24, 2017, 08:53:25 AM
Global should be pretty easy, then I can implement a node overridable attribute for settings and allow nodes to set their own value.

Quote from: Lukapple on August 24, 2017, 08:22:31 AM
You should solve this same way as icons - see getNodeIcon(node) function.

You mean instead of the regular node icon I should allow changing that to a big low battery warning?
Right now there is a separate small low-battery icon next to the node description.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on August 24, 2017, 09:01:44 AM
No, icon should stay unchanged. Just add new function for voltage, something like getTriggerVoltage(node), which will return voltage, defined in metrics file.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on August 24, 2017, 01:46:11 PM
I got another idea. I could use a transparent PNG to cover/blink over the node icon to indicate low voltage, that's a space saving :)
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on August 24, 2017, 01:59:47 PM
Yea, that would be great. Currently on mobile phone low battery image overlaps label.

(http://shrani.si/f/3A/Ec/1sVJ1Hco/img4422.jpg)
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on August 30, 2017, 05:23:50 PM
Felix,
I've opened a github pull request for this.

Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on August 31, 2017, 11:37:37 AM
I've seen it, thank you!
I was actually working on this and several other changes so ... I will see if your PR can merge, or perhaps I may need to manually make changes because the files have many changes locally.

EDIT: looked in more detail, it seems you just hardcode the voltage on the node type. But I had something a bit different in mind: add a new global setting, then add a new section with overridable settings at the node level. That way each node can be customized regardless of type, because each node type can still use different batteries which could have different low voltage levels.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on August 31, 2017, 04:02:23 PM
Yes, I didn't add any UI to set voltage level. You can set it on node type in user metrics file, like this:
exports.motes = {
  PoolMote: {
    label  : 'Pool',
    icon   : 'pool',
    lowBatVoltage : 3.29,
  },
...

Default voltage is still hardcoded.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on August 31, 2017, 07:14:48 PM
Ok my solution is like this, there is a new general setting called lowVoltageValue:
(http://i.imgur.com/oRm9MzG.png)

Then in the mote definitions there is a new possible section called settings {} where you can define a setting that a node type can override (they have to match the name of an existing setting):
Mailbox: {
    label   : 'Mailbox',
    icon : 'icon_mailbox.png',
    settings: { lowVoltageValue: '2.22' }, //blank will make it inherit from general settings.lowVoltageValue
  },


Then in the node, there is a new section that will display these settings.
When a custom value is not saved on the node page by the user, the specificity is in this order (from general to specific):  General settings setting value, node type setting value, node setting value.

Here's how that will look like for the voltage setting:
(http://i.imgur.com/WtYbHG2.png)

In the image above it inherits the value from the General Settings.

The lowVoltageValue setting is special and is used to display a new low voltage warning PNG that will pulse in and out using CSS:
(http://i.imgur.com/Et50kFD.png)

Does this make sense?
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on September 01, 2017, 01:51:56 AM
Yes, that's more user friendly, it looks perfect. I've closed my pull request.

I've one more wish - could you add "ATTACHMENTS array" parameter to sendEmail function (gateway.js).
something like:
global.sendEmail = function(SUBJECT, BODY, ATTACHMENTS)

What I want to do is to attach an image from webcam URL. So when motion is detected, I'll get email with photo :)

global.sendEmail = function(SUBJECT, BODY, ATTACHMENTS) {
  var mailOptions = {
    from: 'Moteino Gateway <[email protected]>',
    to: settings.credentials.emailAlertsTo.value, // list of receivers, comma separated
    subject: SUBJECT,
    text: BODY,
    attachments: ATTACHMENTS
  };

sendEmail('MOTION DETECTED',
'Motion detected, node: [' + node._id + ':' + node.label + '] @ ' + new Date().toLocaleTimeString(),
[{path: 'http://path.to.my.webcam.url/image.jpg'}])

Parameter ATTACHMENTS should be optional.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on September 01, 2017, 10:01:07 AM
Quote from: Lukapple on September 01, 2017, 01:51:56 AM
I've one more wish - could you add "ATTACHMENTS array" parameter to sendEmail function (gateway.js).

Sure thing. Already works:

(http://i.imgur.com/GRLe3Cz.png)
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on September 01, 2017, 10:14:14 AM
Thanks.
Do you have any pre-release branch on github ;)?
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on September 01, 2017, 11:22:56 AM
Not yet... lots of work for a release :)
I will plan to push my changes so far to github. Maybe later today.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on September 01, 2017, 12:55:58 PM
Sounds great! Thank you.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on September 05, 2017, 04:01:08 PM
Ok latest commit includes the new battery warning setting and changes.
The other changes also require you run npm install and you migrate your settings to the new settings.json5 because that has changed significantly.
I suggest backing up your Pi image in case something goes wrong.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on September 05, 2017, 04:03:31 PM
Thanks Felix!
I'll install it right away.
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Felix on September 05, 2017, 04:53:01 PM
Release notes with all changes and new features here:
https://github.com/LowPowerLab/RaspberryPi-Gateway/releases/tag/v8.10
Title: Re: [REQ] voltage parameter for low battery warning
Post by: Lukapple on September 05, 2017, 06:08:27 PM
Tested voltage setting and send mail attachment parameter and it works fine ;D