Request: Voltage parameter for low battery warning [done in v8.10.0]

Started by Lukapple, August 24, 2017, 08:00:51 AM

Lukapple

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

Felix

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.

Lukapple

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.

Felix

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.

Lukapple

No, icon should stay unchanged. Just add new function for voltage, something like getTriggerVoltage(node), which will return voltage, defined in metrics file.

Felix

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 :)

Lukapple

#6
Yea, that would be great. Currently on mobile phone low battery image overlaps label.


Lukapple

Felix,
I've opened a github pull request for this.


Felix

#8
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.

Lukapple

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.

Felix

Ok my solution is like this, there is a new general setting called lowVoltageValue:


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:


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:


Does this make sense?

Lukapple

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.

Felix

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:


Lukapple

Thanks.
Do you have any pre-release branch on github ;)?

Felix

Not yet... lots of work for a release :)
I will plan to push my changes so far to github. Maybe later today.