RobPope / BroadlinkOH3

OpenHAB3 implementation of Broadlink Binding including support for BG1
2 stars 1 forks source link

RM2 OFFLINE in binding, but responding #1

Open niebochod opened 3 years ago

niebochod commented 3 years ago

I have problem with RM2 device to be marked as OFFLINE ('Couldn't find statically-IP-addressed device') in openHAB 3.0.1 after a couple of days working perfectly fine.

It looks that after few days RM2 device enters into state where it's not responding to 'ping' requests:

# ping 10.0.0.161

Pinging 10.0.0.161 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 10.0.0.161:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

but it remains working and responsive for UDP packets, at least when checking with:

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import broadlink
>>> d = broadlink.discover()
>>> print (d)
[broadlink.remote.rmpro(('10.0.0.161', 80), mac=b'4\xea4\x8e\xfc\xb7', devtype=10119, timeout=10, name='智能遥控', model='RM pro', manufacturer='Broadlink', is_locked=False)]
>>> d[0].auth()
True
>>> d[0].check_temperature()
22.2
>>> d[0].check_temperature()
22.1

I can see also in my RouterOS, that it communicates successful with remote and local IPs. I can see also in the wireshark no network errors when using python lib as shown above: image

However, seems that binding does not make attempt to communicate with such device. Restarting binding produces logs as follow:

2021-04-03 13:38:01.015 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'broadlink:rm2:livingroom' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2021-04-03 13:38:01.177 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'broadlink:rm2:livingroom' changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to INITIALIZING
2021-04-03 13:38:01.185 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ThingStatus_Broadlink' changed from UNINITIALIZED to INITIALIZING
2021-04-03 13:38:04.200 [DEBUG] [handler.BroadlinkRemoteModel2Handler] - rm2:livingroom[?]: Statically-IP-addressed device not found at 10.0.0.161
2021-04-03 13:38:04.204 [WARN ] [handler.BroadlinkRemoteModel2Handler] - rm2:livingroom[?]: Online -> Offline due to: Couldn't find statically-IP-addressed device
2021-04-03 13:38:04.209 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'broadlink:rm2:livingroom' changed from INITIALIZING to OFFLINE: Couldn't find statically-IP-addressed device

Binding version: org.openhab.binding.broadlink-3.1.0-SNAPSHOT.jar

OpenHAB setup

Thing broadlink:rm2:livingroom "Broadlink: RM2" @ "Livingroom"
        [ pollingInterval=180,
        ipAddress="10.0.0.161",
        port=80,
        staticIp=true,
        mac="34:EA:34:8E:FC:B7",
        authorizationKey="<key>",
        iv="<iv>",
        retries=4,
        ignoreFailedUpdates=true

Restarting broadlink device solves problems for few days (where broadlink device responds to pings back).

niebochod commented 3 years ago

As i can see in the source code:

NetworkUtils.hostAvailabilityCheck(thingConfig.getIpAddress(), 3000)

used in this case use: https://docs.oracle.com/javase/1.5.0/docs/api/java/net/InetAddress.html#isReachable(int) that is trying to ping such device. But broadlink seems to be stop responding to pings.

niebochod commented 3 years ago

When i've removed NetworkUtils.hostAvailabilityCheck() call and let to query device for status i've got:

21:06:52.611 [ERROR] [.handler.BroadlinkRemoteModel2Handler] - rm2:34-ea-34-8e-fc-b7[v]: Problem getting status. Marking as offline ...
21:06:52.611 [WARN ] [.handler.BroadlinkRemoteModel2Handler] - rm2:34-ea-34-8e-fc-b7[v]: Online -> Offline due to: Problem getting status
21:07:22.626 [ERROR] [.handler.BroadlinkRemoteModel2Handler] - rm2:34-ea-34-8e-fc-b7[v]: Could not get status:
21:07:22.626 [ERROR] [.handler.BroadlinkRemoteModel2Handler] - Broadlink Exception:
java.net.ProtocolException: Response from device is not valid. (0x22=0xF9,0x23=0xFF,0x24=0x00)
        at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket(BroadlinkProtocol.java:195) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket(BroadlinkBaseThingHandler.java:193) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkRemoteModel2Handler.getStatusFromDevice(BroadlinkRemoteModel2Handler.java:41) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus(BroadlinkBaseThingHandler.java:227) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler$1.run(BroadlinkBaseThingHandler.java:102) [bundleFile:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:834) [?:?]
RobPope commented 3 years ago

I've been looking into this briefly today and having a similar issue. You mention the RM2, which I've not explicitly touched (but have updated other code in the protocol to get the SP4B working.

I'd suggest your best bet is to use the OH 3.1 jar from the Millhouse Group https://github.com/themillhousegroup/openhab2-addons/

niebochod commented 3 years ago

Seems that it also calls NetworkUtils.hostAvailabilityCheck (source), so i guess it will switch device into offline as well.

niebochod commented 3 years ago

With this change: https://github.com/niebochod/openhab-addons/commit/b32744b1b13667a243e574b704f82d2c1395bf26 it seems to be working fine (at least from initial tests).