Hey, folks! Thought I would make my weekend project a telnet driver for a WattBox I have behind my TV in the living room.
I started hacking away and ran into problems almost immediately. Namely, the telnet command always times out. I tried the raw socket driver and verified connectivity to the device, which also illustrated that line endings were LF-only, since it sent back the hex characters.
An nc
session with the device looks like this:
Please Login to Continue
Username: ernie
Password: ********
Successfully Logged In!
?OutletName
?OutletName={LG Gallery OLED},{Outlet 2}
?Model
?Model=WB-250-IPW-2
?Firmware
?Firmware=1.2.0.6
And the driver code I hacked together so far looks like the below. I'm hoping I'm doing something silly, since there is next to no documentation on the telnet interface. It consistently hangs at the telnetConnect
call for 30 seconds, then errors with java.net.SocketTimeoutException
.
metadata {
definition (name: "WattBox", namespace: "ernie", author: "Ernie Miller", ocfDeviceType: "oic.d.switch") {
capability "Actuator"
capability "Configuration"
capability "Refresh"
capability "Switch"
command "connectTelnet"
command "disconnectTelnet"
command "sendMsg", ["String"]
}
}
preferences {
input "ip", "text", title: "IP / Hostname", required: true
input "port", "number", title: "Port (23)", required: true, defaultValue: 23
input "username", "text", title: "Username", required: true
input "password", "text", title: "Password", required: true
}
def parse(String message) {
log.info message
}
def telnetStatus(String message) {
log.info "telnetStatus - error: $message"
}
def connectTelnet() {
log.debug "Connecting to telnet: $host"
telnetConnect([termChars: [10]], ip, port as int, username, password)
}
def disconnectTelnet() {
log.debug "Resetting telnet session"
telnetClose()
}
def sendMsg(String message) {
log.debug "Sending: $message"
return new hubitat.device.HubAction(message, hubitat.device.Protocol.TELNET)
}