Merge branch 'master' of ssh://git.maxhunt.design:9999/MAX/iot-v2-rn

This commit is contained in:
Your Name 2020-10-11 10:41:03 +01:00
commit c588914420

View File

@ -23,7 +23,7 @@ var led_array = {
app.get('/', function (request, responce) { app.get('/', function (request, responce) {
responce.render('index.ejs', {led_array:led_array}) responce.render('index.ejs', { led_array: led_array })
}) })
@ -35,6 +35,21 @@ app.post('/setlight', async function (request, responce) {
led_array.color = Number(request.body.color) led_array.color = Number(request.body.color)
// Now make an api call to the led controller // Now make an api call to the led controller
axios({
url: 'http://192.168.0.27:5000/setState',
method: 'post',
data: {
power: led_array.power,
brightness: led_array.brightness,
color: led_array.color
}
})
.catch((err) => {
console.error(err)
responce.send({ success: false, error: "NETWORK" })
})
.then(() => {
axios({ axios({
url: 'http://192.168.0.23:5000/setState', url: 'http://192.168.0.23:5000/setState',
method: 'post', method: 'post',
@ -44,7 +59,14 @@ app.post('/setlight', async function (request, responce) {
color: led_array.color color: led_array.color
} }
}) })
responce.send({success: true, error: false}) .catch((err) => {
console.error(err)
responce.send({ success: false, error: "NETWORK" })
})
.then(() => {
responce.send({ success: true, error: false })
})
})
} }
else { else {
@ -59,7 +81,7 @@ app.post('/getlight', async function (request, responce) {
brightness: led_array.brightness, brightness: led_array.brightness,
color: led_array.color color: led_array.color
} }
responce.send({led_array: rsp}) responce.send({ led_array: rsp })
}) })