diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-03-30 22:02:12 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-03-30 22:02:12 +0100 |
| commit | 914d60ca25def8805b7fb2dafcab17474e08cc87 (patch) | |
| tree | 53ad95f040157f442aa62d1e648f75896e26a106 /routes/energy-usage.js | |
| parent | ecc769dab59d427c1fa5dc8856dd32068b4ba6db (diff) | |
| download | tplink-energy-monitor-914d60ca25def8805b7fb2dafcab17474e08cc87.tar.xz tplink-energy-monitor-914d60ca25def8805b7fb2dafcab17474e08cc87.zip | |
Poll for realtime usage updates
Diffstat (limited to 'routes/energy-usage.js')
| -rw-r--r-- | routes/energy-usage.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/routes/energy-usage.js b/routes/energy-usage.js new file mode 100644 index 0000000..847248d --- /dev/null +++ b/routes/energy-usage.js @@ -0,0 +1,24 @@ +const express = require('express'); +const router = express.Router(); + +const deviceManager = require('../services/device-manager'); + +router.get('/:deviceId/realtime', function(req, res, next) { + + let deviceId = req.params.deviceId; + + let realtimeUsage = {}; + // TODO - cache results with a short TTL so we don't hammer the plug if multiple clients are requesting data + deviceManager.getDevice(deviceId).emeter.getRealtime().then(response => { + + // Voltage seems to be reported as its peak to peak voltage, not RMS. + // Show the RMS value since thats what would you expect to see. + // i.e. 220v not 310v (in the U.K) + response.voltage = response.voltage / Math.sqrt(2); + + res.json(response); + }); + +}); + +module.exports = router;
\ No newline at end of file |