Using OH3.4.1 on openHABian.
My use case is:
- generate some URL
- call that URL (via GET)
- save response in an image item
- display said image item in OH3-GUI
So for my Dynamic pricing, tibber hourly tariff => making "future" charts or similar? - #2 by Ap15e needs, I’m now at a point where I can put together an URL, which calls quickchart.io and there I’ll have an PNG generated, which I want to use. Because I don’t want to call the API over and over again and because I want to learn some new, I’d like to create the image daily and then access it over the day in an image-item.
So far I’ve gotten here using JS Scripting (ECMA-2021):
// generating the data, here only the output var data = "16,14,14,14,14,17,24,27,26,25,24,24,23,23,24,25,25,27,28,26,25,24,22,18"; // header, in case it helps const headers = new Map(); headers.set('Content-Type', "image/png;base64"); headers.set('Content-Transfer-Encoding', "base64"); // creating the URL and sending GET-Request var quickchartURL = "https://quickchart.io/chart/render/sm-760d4a4b-751f-410a-89d8-28208435e98a?data1="+data; var quickchartPNG = actions.HTTP.sendHttpGetRequest(quickchartURL, headers, 1000); // putting the answer into the item items.getItem("TIB_PricesFutureChart").postUpdate("data:image/png;base64,"+quickchartPNG);
but of course:
2023-01-12 15:17:00.250 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - State 'data:image/png;base64,�PNG IHDRX,�_Z�;wIDATx���W˾��_�9�}ϝϽw�u��6��q�"D"JPq�3�8�F�8��[�lTpB���Lq F�yW�g�� [...] `�A#� � !A�!� FAA1��,G�1)�~END�B`�' cannot be parsed for item 'TIB_PricesFutureChart'.
but, it seems, I’m not getting the base64-encoded response, but the pure binary data from quickchart back. Do I have to somehow base64encode that - and how would I do that with HTTP-Actions?