Skip to content

Too big events #25

@Michdo93

Description

@Michdo93

Hi,

I use SSE to query the events of items from openHAB. I can do this there via the REST API. However, I have a problem with images. If I change a large image and replace it with a small one, the SSE events do not break.

However, if I replace a small image with a large one, it fails tremendously.

Here the part of my code:

import json
import pprint
import sseclient

if __name__ == "__main__":
    events = sseclient.SSEClient("http://192.168.0.5:8080/rest/events?topics=openhab/items/testImage/state")

    for event in events:
        print(event)
        print(type(event))
        print(type(event.data))
        print(len(event.data))
        pprint.pprint(event)

        try:
            if len(event.data) > 0:
                data = json.loads(event.data)

                event_topic = data.get("topic")
                event_item_name = event_topic.split("/")[2]
                event_payload = eval(data.get("payload"))
                event_type = data.get("type")

                print(event_item_name)
        except json.decoder.JSONDecodeError:
            print("Event could not be converted from JSON")

I check it in return with Curl, of course. There I see that a big event is arriving.

If I run my Python script, I get:

{"topic":"openhab/items/testImage/state","payload":"{\"type\":\"Raw\",\"value\":\"data:image/jpg;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw\\u003d\\u003d\"}","type":"ItemStateEvent"}
<class 'sseclient.Event'>
<class 'str'>
205
<sseclient.Event object at 0x7f435da7ffa0>
testImage

<class 'sseclient.Event'>
<class 'str'>
0
<sseclient.Event object at 0x7f435da7ff70>

<class 'sseclient.Event'>
<class 'str'>
0
<sseclient.Event object at 0x7f435da7ffa0>

<class 'sseclient.Event'>
<class 'str'>
0
...

Or in other words: Instead of receiving anything big, I suddenly receive nothing at all. The loop makes another iteration. That's all well and good. But for some reason this event is then empty. My assumption would be that it would be too large to be processed.

This is the equvialent command with curl:

curl "http://192.168.0.5:8080/rest/events?topics=openhab/items/testImage/state"

I receive:

...
event: message
data: {"topic":"openhab/items/testImage/state","payload":"{\"type\":\"Raw\",\"value\":\"data:image/jpg;base64,
....

It would be definitely too long to post the whole answer because an image is very long.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions