Skip to content

Commit

Permalink
fix lights test
Browse files Browse the repository at this point in the history
  • Loading branch information
groupsky committed Nov 17, 2024
1 parent 56ffc1c commit 3b9569f
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions docker/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,64 @@ const brokerUrl = process.env.BROKER || 'mqtt://localhost'
console.log(`connecting ${brokerUrl}`)
const client = mqtt.connect(brokerUrl)
const timer = setTimeout(() => {
console.error('Timeout!')
process.exit(1)
console.error('Timeout!')
process.exit(1)
}, 1000)

client.on('connect', () => {
console.log('connected, sending...')
client.subscribe('/homy/ard1/output', (err) => {
if (err) {
console.log('Error sending', err)
process.exit(1)
}
console.log(`> [${'/homy/ard1/input'}]: ${JSON.stringify({ t: 'ic', i: 22, p: 44, l: 0, v: 1 })}`)
client.publish('/homy/ard1/input', JSON.stringify({ t: 'ic', i: 22, p: 44, l: 0, v: 1 }))
})
console.log('connected, sending...')
client.subscribe('/homy/ard1/output', (err) => {
if (err) {
console.log('Error sending', err)
process.exit(1)
}
console.log(`> [${'/modbus/dry-switches/mbsl32di2/reading'}]: ${JSON.stringify({
"inputs": 137366691,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
})}`)
client.publish('/modbus/dry-switches/mbsl32di2/reading', JSON.stringify({
"inputs": 137366691,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
}))
console.log(`> [${'/modbus/dry-switches/mbsl32di2/reading'}]: ${JSON.stringify({
"inputs": 3148963,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
})}`)
client.publish('/modbus/dry-switches/mbsl32di2/reading', JSON.stringify({
"inputs": 3148963,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
}))
})
})

client.on('message', (topic, message) => {
console.log(`< [${topic}]: ${message}`)
// message is Buffer
if (topic === '/homy/ard1/output') {
const msg = JSON.parse(message)
if (msg.pin === 20 && msg.value === -1) {
clearTimeout(timer)
client.end()
console.log(`< [${topic}]: ${message}`)
// message is Buffer
if (topic === '/modbus/dry-switches/relays00-15/write') {
const msg = JSON.parse(message)
if (msg.out13 === true) {
clearTimeout(timer)
client.end()
}
}
}
})

client.on('error', (err) => {
console.log('error', err)
console.log('error', err)
})

0 comments on commit 3b9569f

Please sign in to comment.