81 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-09-21 21:38:46 +01:00
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.heatingStatus('On')
2020-09-21 21:53:55 +01:00
lcd.lastSetTemp(data.lastTimerSetPoint)
lcd.currentRoomTemp(data.measuredRoomTemp)
2020-09-21 21:38:46 +01:00
lcd.NextEvent(globalVars.heatingNextEvent)
led.set('red')
} else {
2020-09-21 21:53:55 +01:00
globalVars.heatingOn = heatingOn
2020-09-21 21:38:46 +01:00
lcd.heatingStatus('Off')
2020-09-21 21:53:55 +01:00
lcd.lastSetTemp(data.lastTimerSetPoint)
lcd.currentRoomTemp(data.measuredRoomTemp)
2020-09-21 21:38:46 +01:00
lcd.NextEvent(globalVars.heatingNextEvent)
2020-09-21 21:53:55 +01:00
led.set('blue')
2020-09-21 21:38:46 +01:00
}
} else {
// if (waterOn != globalVars.waterOn) {
if (heatingOn === 'true') {
globalVars.heatingOn = heatingOn
lcd.heatingStatus('On')
2020-09-21 21:53:55 +01:00
lcd.lastSetTemp(data.lastTimerSetPoint)
lcd.currentRoomTemp(data.measuredRoomTemp)
2020-09-21 21:38:46 +01:00
lcd.NextEvent(globalVars.heatingNextEvent)
2020-09-21 21:53:55 +01:00
led.set('red')
2020-09-21 21:38:46 +01:00
} else {
globalVars.heatingOn = heatingOn
lcd.heatingStatus('Off')
2020-09-21 21:53:55 +01:00
lcd.lastSetTemp(data.lastTimerSetPoint)
lcd.currentRoomTemp(data.measuredRoomTemp)
2020-09-21 21:38:46 +01:00
lcd.NextEvent(globalVars.waterNextEvent)
2020-09-21 21:53:55 +01:00
led.set('blue')
2020-09-21 21:38:46 +01:00
}
// }
}
});
});
// Report errors
request.on('error', function (error) {
led.set('green')
lcd.heatingStatus('Error No Data')
globalVars.heatingOn = 'error'
});
request.end();
}
}