Hi,
I've been trying to get the tcp/telnet function to create a connection to a kodi box so that I can monitor notifications. This should be really simple stuff, all it should be is open port 9090 (default) on the correct IP .. and that's it. Listen and let parse() display output.
I've used Envisalink code from @doug as a base (as it's performance is rock solid for my envisalink connection) and cut it down to it's most basic parts to start with. The connection get established, and I can successfully even sendMsg to the kodi box from my driver, but I never see any responses.
I can use PuTTY from multiple PC's at the same time, and open a basic telnet connection .. and they all receive the notifications from the kodi box, including notifications from the messages I send in my driver, but the hubitat driver never gets anything to parse.
I'm completely at a loss as to what I'm doing wrong. Here's the driver code:
public static String version() { return "v0.0.1" }
public static boolean isDebug() { return true }import groovy.transform.Field
metadata {
definition (name: "KodiTCP", namespace: "hamsando", author: "Putch") {
capability "Initialize"
capability "Telnet"
capability "Actuator"
command "sendMsg", ["String"]
command "scan"
}preferences {
input("ip", "text", title: "IP Address", description: "ip", required: true)
}
}//general handlers
def installed() {
log.warn "installed..."
initialize()
}def updated() {
ifDebug("updated...")
ifDebug("Configuring IP: ${ip}")
initialize()
}def initialize() {
telnetClose()
try {
//open telnet connection
telnetConnect(ip, 9090, null, null)
//give it a chance to start
pauseExecution(1000)
ifDebug("Telnet connection to Kodi established")
//poll()
} catch(e) {
log.warn "initialize error: ${e.message}"
}
}def uninstalled() {
telnetClose()
}private parse(String message) {
ifDebug("Parsing Incoming message: " + message)
}def scan() {
sendMsg(VIDEOSCAN)
}def sendMsg(String s) {
ifDebug("sendMsg $s")
return new hubitat.device.HubAction(s, hubitat.device.Protocol.TELNET)
//sendHubCommand(new hubitat.device.HubAction(s, hubitat.device.Protocol.TELNET))
}//Telnet
def getReTry(Boolean inc){
def reTry = (state.reTryCount ?: 0).toInteger()
if (inc) reTry++
state.reTryCount = reTry
return reTry
}def telnetStatus(String status){
log.warn "telnetStatus- error: ${status}"
if (status != "receive error: Stream is closed"){
getReTry(true)
log.error "Telnet connection dropped..."
initialize()
} else {
log.warn "Telnet is restarting..."
}
}private ifDebug(msg)
{
log.debug('KODI Driver: ' + msg)
}@Field static final String VIDEOSCAN = "{"jsonrpc":"2.0","method":"VideoLibrary.Scan","id":"justme"}"