updates
This commit is contained in:
		
							parent
							
								
									32f1041a85
								
							
						
					
					
						commit
						b0ef1fe89a
					
				@ -29,6 +29,10 @@ module.exports = {
 | 
				
			|||||||
        value
 | 
					        value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let heatMap = [
 | 
					        let heatMap = [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "miGenie": 0,
 | 
				
			||||||
 | 
					                "realTemp": 0
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "miGenie": 84,
 | 
					                "miGenie": 84,
 | 
				
			||||||
                "realTemp": 22
 | 
					                "realTemp": 22
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@ module.exports = {
 | 
				
			|||||||
            const res = JSON.parse(response.body)
 | 
					            const res = JSON.parse(response.body)
 | 
				
			||||||
            return res
 | 
					            return res
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            console.log(error.response.body);
 | 
					            console.log('post error');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -10,6 +10,7 @@ module.exports = function (app) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    app.get("/heating/status", async function (req, res, next) {
 | 
					    app.get("/heating/status", async function (req, res, next) {
 | 
				
			||||||
        const response = await post.postRequest('{}', 'poll')
 | 
					        const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
 | 
					        // console.log(response.updateData)
 | 
				
			||||||
        const heating = response.updateData.zones[0].status
 | 
					        const heating = response.updateData.zones[0].status
 | 
				
			||||||
        const mrt = await common.updateTemp(heating)
 | 
					        const mrt = await common.updateTemp(heating)
 | 
				
			||||||
        const on = await common.heatingOn(heating)
 | 
					        const on = await common.heatingOn(heating)
 | 
				
			||||||
 | 
				
			|||||||
@ -8,4 +8,22 @@ module.exports = function (app) {
 | 
				
			|||||||
        res.json(heating)
 | 
					        res.json(heating)
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    app.post("/heating/status", async function (req, res, next) {
 | 
				
			||||||
 | 
					        const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
 | 
					        const heating = response.updateData.zones[0].status
 | 
				
			||||||
 | 
					        const mrt = await common.updateTemp(heating)
 | 
				
			||||||
 | 
					        const on = await common.heatingOn(heating)
 | 
				
			||||||
 | 
					        const csp = await common.heatMap(heating.currentSetpoint)
 | 
				
			||||||
 | 
					        const lsp = await common.heatMap(heating.lastTimerSetPoint)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let heatingStatus = {
 | 
				
			||||||
 | 
					            "heatingOn": JSON.stringify(on),
 | 
				
			||||||
 | 
					            "measuredRoomTemp": mrt,
 | 
				
			||||||
 | 
					            "currentSetpoint": csp,
 | 
				
			||||||
 | 
					            "lastTimerSetPoint": lsp,
 | 
				
			||||||
 | 
					            "lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        res.json(heatingStatus)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -28,4 +28,23 @@ module.exports = function (app) {
 | 
				
			|||||||
        res.json(water)
 | 
					        res.json(water)
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    app.get("/water/switch", async function (req, res, next) {
 | 
				
			||||||
 | 
					        const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
 | 
					        console.log('switch status start')
 | 
				
			||||||
 | 
					        const water = response.updateData.zones[1].status
 | 
				
			||||||
 | 
					        let on = await common.heatingOn(water)
 | 
				
			||||||
 | 
					        if (on == true) {
 | 
				
			||||||
 | 
					            on = '0'
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            on = '1'    
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let switchStatus = {
 | 
				
			||||||
 | 
					            "switch": on
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        console.log(switchStatus)
 | 
				
			||||||
 | 
					        console.log('switch status end')
 | 
				
			||||||
 | 
					        res.json(switchStatus)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,19 +1,48 @@
 | 
				
			|||||||
const post = require('../lib/post')
 | 
					const post = require('../lib/post')
 | 
				
			||||||
const common = require('../lib/common')
 | 
					const common = require('../lib/common')
 | 
				
			||||||
const bodyParser = require('body-parser');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = function (app) {
 | 
					module.exports = function (app) {
 | 
				
			||||||
    app.use(bodyParser.urlencoded({ extended: true }));
 | 
					    app.post("/water/switch", async function (req, res, next) {
 | 
				
			||||||
 | 
					        if (req.body.switch === 1) {
 | 
				
			||||||
    app.post("/water", async function (req, res, next) {
 | 
					            try {
 | 
				
			||||||
        if (req.query.switch === '1') {
 | 
					 | 
				
			||||||
                await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer')
 | 
					                await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer')
 | 
				
			||||||
        } else if (req.query.switch === '0') {
 | 
					                const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
            await post.postRequest('{"zoneId":[1]}', 'cancel_timer')
 | 
					                const water = response.updateData.zones[1].status
 | 
				
			||||||
        } else {
 | 
					                const on = await common.heatingOn(water)
 | 
				
			||||||
            throw new Error
 | 
					
 | 
				
			||||||
 | 
					                let waterStatus = {
 | 
				
			||||||
 | 
					                    "waterOn": JSON.stringify(on),
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                res.json(waterStatus)
 | 
				
			||||||
 | 
					            } catch (error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else if (req.body.switch === 0) {
 | 
				
			||||||
 | 
					            await post.postRequest('{"zoneId":[1]}', 'cancel_timer')
 | 
				
			||||||
 | 
					            const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
 | 
					            const water = response.updateData.zones[1].status
 | 
				
			||||||
 | 
					            const on = await common.heatingOn(water)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let waterStatus = {
 | 
				
			||||||
 | 
					                "waterOn": JSON.stringify(on),
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            res.json(waterStatus)
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            res.json({ "switch": "break" })
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        res.json(req.query)
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    app.post("/water/status", async function (req, res, next) {
 | 
				
			||||||
 | 
					        const response = await post.postRequest('{}', 'poll')
 | 
				
			||||||
 | 
					        const water = response.updateData.zones[1].status
 | 
				
			||||||
 | 
					        const on = await common.heatingOn(water)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let waterStatus = {
 | 
				
			||||||
 | 
					            "waterOn": JSON.stringify(on),
 | 
				
			||||||
 | 
					            "currentSetpoint": JSON.stringify(water.currentSetpoint),
 | 
				
			||||||
 | 
					            "lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
 | 
				
			||||||
 | 
					            "lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        res.json(waterStatus)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,5 +1,10 @@
 | 
				
			|||||||
var express = require("express");
 | 
					var express = require("express");
 | 
				
			||||||
var app = express();
 | 
					var app = express();
 | 
				
			||||||
 | 
					const bodyParser = require('body-parser');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.use(bodyParser.urlencoded({ extended: true }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.use(bodyParser.json())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require('./routes')(app);
 | 
					require('./routes')(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										20
									
								
								test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								test.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					var express = require("express");
 | 
				
			||||||
 | 
					var app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const bodyParser = require('body-parser')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.use(
 | 
				
			||||||
 | 
					  bodyParser.urlencoded({
 | 
				
			||||||
 | 
					    extended: true
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.use(bodyParser.json())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.post('/endpoint', (req, res) => {
 | 
				
			||||||
 | 
					  console.log(req.body)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.listen(2020, function () {
 | 
				
			||||||
 | 
					    console.log("Server running on port 2020");
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user