Monitor motorhome leisure battery and provide simple control of habitation
Dependencies: net lpc1768 crypto clock web fram log
web-this/system/web-system-script.js@10:a97a7cb7aa82, 2022-06-10 (annotated)
- Committer:
- andrewboyson
- Date:
- Fri Jun 10 18:32:21 2022 +0000
- Revision:
- 10:a97a7cb7aa82
- Parent:
- 0:b843d647695c
Corrected amp second count in html
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 0:b843d647695c | 1 | //System script |
andrewboyson | 0:b843d647695c | 2 | 'use strict'; |
andrewboyson | 0:b843d647695c | 3 | |
andrewboyson | 0:b843d647695c | 4 | let serverName = ''; |
andrewboyson | 0:b843d647695c | 5 | let fileName = ''; |
andrewboyson | 0:b843d647695c | 6 | let readInterval = 0; |
andrewboyson | 0:b843d647695c | 7 | let writeSize = 0; |
andrewboyson | 0:b843d647695c | 8 | let count = 0; |
andrewboyson | 0:b843d647695c | 9 | let startTime = null; |
andrewboyson | 0:b843d647695c | 10 | let framUsed = 0; |
andrewboyson | 0:b843d647695c | 11 | |
andrewboyson | 0:b843d647695c | 12 | function parse() |
andrewboyson | 0:b843d647695c | 13 | { |
andrewboyson | 0:b843d647695c | 14 | let lines = Ajax.response.split('\n'); |
andrewboyson | 0:b843d647695c | 15 | serverName = lines[0]; |
andrewboyson | 0:b843d647695c | 16 | fileName = lines[1]; |
andrewboyson | 0:b843d647695c | 17 | readInterval = Ajax.hexToSignedInt16(lines[2]); |
andrewboyson | 0:b843d647695c | 18 | writeSize = Ajax.hexToSignedInt16(lines[3]); |
andrewboyson | 0:b843d647695c | 19 | count = Ajax.hexToSignedInt16(lines[4]); |
andrewboyson | 0:b843d647695c | 20 | startTime = new Date(parseInt(lines[5], 16) * 1000); |
andrewboyson | 0:b843d647695c | 21 | framUsed = Ajax.hexToSignedInt16(lines[6]); |
andrewboyson | 0:b843d647695c | 22 | } |
andrewboyson | 0:b843d647695c | 23 | function display() |
andrewboyson | 0:b843d647695c | 24 | { |
andrewboyson | 0:b843d647695c | 25 | let elem; |
andrewboyson | 0:b843d647695c | 26 | elem = Ajax.getElementOrNull('ajax-server-name' ); if (elem) elem.value = serverName; |
andrewboyson | 0:b843d647695c | 27 | elem = Ajax.getElementOrNull('ajax-file-name' ); if (elem) elem.value = fileName; |
andrewboyson | 0:b843d647695c | 28 | elem = Ajax.getElementOrNull('ajax-read-interval'); if (elem) elem.value = readInterval; |
andrewboyson | 0:b843d647695c | 29 | elem = Ajax.getElementOrNull('ajax-write-size' ); if (elem) elem.value = writeSize; |
andrewboyson | 0:b843d647695c | 30 | elem = Ajax.getElementOrNull('ajax-count' ); if (elem) elem.textContent = count; |
andrewboyson | 0:b843d647695c | 31 | elem = Ajax.getElementOrNull('ajax-start-time' ); if (elem) elem.textContent = startTime.toISOString().substr(0, 19).split('T').join(' ') + ' UTC'; |
andrewboyson | 0:b843d647695c | 32 | elem = Ajax.getElementOrNull('ajax-fram-used' ); if (elem) elem.textContent = framUsed; |
andrewboyson | 0:b843d647695c | 33 | } |
andrewboyson | 0:b843d647695c | 34 | |
andrewboyson | 0:b843d647695c | 35 | Ajax.server = '/system-ajax'; |
andrewboyson | 0:b843d647695c | 36 | Ajax.onResponse = function() { parse(); display(); }; |
andrewboyson | 0:b843d647695c | 37 | Ajax.init(); |