69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
const http = require('http')
|
|
const globalVars = require('../libs/globalVars')
|
|
const led = require('../libs/led')
|
|
const common = require('../libs/common')
|
|
const lcd = require('../libs/lcd')
|
|
|
|
module.exports = {
|
|
|
|
getStatus: () => {
|
|
var rest_options = {
|
|
host: '192.168.4.5',
|
|
port: 2020,
|
|
path: '/heating/status',
|
|
method: 'GET'
|
|
};
|
|
console.log('heating request')
|
|
var request = http.request(rest_options, function (response) {
|
|
var content = "";
|
|
|
|
// Handle data chunks
|
|
response.on('data', function (chunk) {
|
|
content += chunk;
|
|
});
|
|
|
|
// Once we're done streaming the response, parse it as json.
|
|
response.on('end', async function () {
|
|
var data = JSON.parse(content);
|
|
let heatingOn = data.heatingOn
|
|
|
|
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
|
|
|
globalVars.waterNextEvent = time
|
|
|
|
let m = await common.time(data.nextScheduleEventUtcTime)
|
|
|
|
if (globalVars.heatingOn === "" || globalVars.heatingOn === "error") {
|
|
if (heatingOn === 'true') {
|
|
globalVars.heatingOn = heatingOn
|
|
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
|
led.set('red')
|
|
} else {
|
|
globalVars.heatingOn = heatingOn
|
|
lcd.heatingPageOne('Off', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
|
led.set('blue')
|
|
}
|
|
} else {
|
|
// if (waterOn != globalVars.waterOn) {
|
|
if (heatingOn === 'true') {
|
|
globalVars.heatingOn = heatingOn
|
|
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
|
led.set('red')
|
|
} else {
|
|
globalVars.heatingOn = heatingOn
|
|
lcd.heatingPageOne('Off', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
|
led.set('blue')
|
|
}
|
|
// }
|
|
}
|
|
});
|
|
});
|
|
// Report errors
|
|
request.on('error', function (error) {
|
|
led.set('green')
|
|
lcd.heatingStatus('Error No Data')
|
|
globalVars.heatingOn = 'error'
|
|
});
|
|
request.end();
|
|
}
|
|
} |