Some config usage adjustments
This commit is contained in:
@@ -46,7 +46,6 @@ axios.get(`http://${config.servers.deconz.url}:${config.servers.deconz.apiPort}/
|
|||||||
influxPayload += `${device} ${devices[device].join(",")}\n`
|
influxPayload += `${device} ${devices[device].join(",")}\n`
|
||||||
}
|
}
|
||||||
influxPayload = influxPayload.slice(0, -1)
|
influxPayload = influxPayload.slice(0, -1)
|
||||||
|
|
||||||
// Send data to influx
|
// Send data to influx
|
||||||
axios.post(`${config.servers.influx.url}/api/v2/write?orgID=${config.servers.influx.orgId}&bucket=${config.servers.influx.bucket}`,
|
axios.post(`${config.servers.influx.url}/api/v2/write?orgID=${config.servers.influx.orgId}&bucket=${config.servers.influx.bucket}`,
|
||||||
influxPayload,
|
influxPayload,
|
||||||
|
|||||||
+17
-1
@@ -3,10 +3,23 @@ import WebSocket from 'ws'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import exec from 'child_process'
|
import exec from 'child_process'
|
||||||
let config = JSON.parse(fs.readFileSync('config.json', 'utf8'))
|
let config = JSON.parse(fs.readFileSync('config.json', 'utf8'))
|
||||||
let ws = new WebSocket(`ws://${config.servers.deconz.url}:${config.servers.deconz.websocketPort}`)
|
let SOCKET_URL = `ws://${config.servers.deconz.url}:${config.servers.deconz.websocketPort}`
|
||||||
|
console.log(SOCKET_URL)
|
||||||
|
let ws = new WebSocket(SOCKET_URL)
|
||||||
|
|
||||||
|
ws.on('error', (error) => {
|
||||||
|
console.error('WebSocket error:', error)
|
||||||
|
console.log("ERROR")
|
||||||
|
})
|
||||||
|
ws.on('close', (code, reason) => {
|
||||||
|
console.log(`Connection closed with code ${code} and reason: ${reason}`);
|
||||||
|
// Clean up any resources here
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
ws.on('message', msg => {
|
ws.on('message', msg => {
|
||||||
let data = JSON.parse(msg)
|
let data = JSON.parse(msg)
|
||||||
|
//fs.appendFileSync('socket.log', msg+'\n')
|
||||||
try {
|
try {
|
||||||
if (data.state) {
|
if (data.state) {
|
||||||
let device = config.wsDevices.find(device => device.uniqueId === data.uniqueid)
|
let device = config.wsDevices.find(device => device.uniqueId === data.uniqueid)
|
||||||
@@ -26,6 +39,7 @@ ws.on('message', msg => {
|
|||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
console.log("ERROR")
|
||||||
})
|
})
|
||||||
if (device.openScript && data.state[device.valueKey]){
|
if (device.openScript && data.state[device.valueKey]){
|
||||||
console.log("Running open script")
|
console.log("Running open script")
|
||||||
@@ -33,11 +47,13 @@ ws.on('message', msg => {
|
|||||||
exec.exec(device.openScript)
|
exec.exec(device.openScript)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
console.log("ERROR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
console.log("ERROR")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user