I think it is likely that you'll have issues if you try to mix the content from your mobile app captures and the commands in the hass-proscenic-790T-vacuum code.
Let's assume that the hass code works and that the Hubitat raw socket interface provides similar functionality to exchange byte arrays as the python code does.
I can get a successful connection on the IP and port for the remote server. But I can't get a reply to my login or ping commands, presumably because the deviceId, userId, and token are bogus.
Grab this code and edit the code to put the correct values in device, token, and user. Create a virtual device of this type. Then open a Logs window in a separate tab and hit openSocket
, login
, and ping
(in that order) on the device page. Do you get a response?
Summary
/*
*/
metadata
{
definition(name: "raw socket testing", namespace: "tomw", author: "tomw", importUrl: "")
{
command "openSocket"
command "closeSocket"
command "login"
command "ping"
attribute "commStatus", "string"
}
}
preferences
{
section
{
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}
}
def logDebug(msg)
{
if (logEnable)
{
log.debug(msg)
}
}
def socketStatus(String message)
{
logDebug("socketStatus: ${message}")
}
def openSocket()
{
try
{
sendEvent(name: "commStatus", value: "unknown")
interfaces.rawSocket.connect("47.91.67.181", 20008, byteInterface: true)
sendEvent(name: "commStatus", value: "good")
}
catch (Exception e)
{
logDebug("error: ${e.message}")
sendEvent(name: "commStatus", value: "error")
}
}
def closeSocket()
{
try
{
interfaces.rawSocket.close()
sendEvent(name: "commStatus", value: "unknown")
}
catch (Exception e)
{
// swallow errors
}
}
def login()
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
byte[] header = [0xfb, 0, 0, 0, 0x10, 0, 0xc8, 0, 0, 0, 0x29, 0x27, 0x2a, 0x27, 0, 0, 0, 0, 0, 0]
outputStream.write(header)
def bodyPayload =
[
cmd: 0,
control: [targetId: ""],
seq: 0,
value:
[
appKey: "67ce4fabe562405d9492cad9097e09bf",
deviceId: "ENTER DEVICE ID",
deviceType: "3",
token: "ENTER TOKEN",
userId: "ENTER USER ID"
]
]
byte[] body = groovy.json.JsonOutput.toJson(bodyPayload)?.getBytes()
outputStream.write(body)
_writeByteStreamToSocket(outputStream.toByteArray())
}
def ping()
{
byte[] body = [0x14, 0, 0, 0, 0, 0x01, 0xc8, 0, 0, 0, 0x01, 0, 0x22, 0x27, 0, 0, 0, 0, 0, 0]
_writeByteStreamToSocket(body)
}
def _writeByteStreamToSocket(byte[] bytes)
{
logDebug("${new String(bytes, "UTF-8")}")
interfaces.rawSocket.sendMessage(hubitat.helper.HexUtils.byteArrayToHexString(bytes))
}
def parse(String message)
{
logDebug("parse: ${message}")
}