Hi there,
this is a “is this possible” thing and not something i really need.
I would like to understand the steps and maybe use the knowledge for future ideas.
I´m currently using the speedtest binding to measure my connection, collect the data with InfluxDB and view them in Grafana.
The binding obtains the url
of the speedtest result and i would like to get this image into an openHAB item of the type Image
.
I already tried different methods but all of them failed…
1.Using HttpUtil
I was playing around with HttpUtil.downloadImage(<url>)
but i wasn´t able to get the function working.
First try:
import org.openhab.core.io.net.http
...
val speedImage = spdURL.state + ".png"
val ImageName = speedImage.toString.split("/").get(5)
logInfo(ruleId, "URL der Grafik: " + speedImage)
logInfo(ruleId, "Name der Grafik: " + ImageName)
var RawType Image = HttpUtil.downloadImage(speedImage)
spdImage.postUpdate(Image)
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Testswitch-1' failed: The name 'httpUtil' cannot be resolved to an item or type; line 28, column 25, length 8 in Testswitch
Second try:
import org.openhab.core.io.net.http
...
val speedImage = spdURL.state + ".png"
val ImageName = speedImage.toString.split("/").get(5)
logInfo(ruleId, "URL der Grafik: " + speedImage)
logInfo(ruleId, "Name der Grafik: " + ImageName)
spdImage.postUpdate(HttpUtil.downloadImage(speedImage))
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Testswitch-1' failed: The name 'httpUtil' cannot be resolved to an item or type; line 28, column 25, length 8 in Testswitch
2.Using wget
and base64
Ok when oH can´t do it i´ll try it with executeCommandLine
val speedImage = spdURL.state + ".png"
val ImageName = speedImage.toString.split("/").get(5)
val wget = "wget"
val base64 = "base64"
val getImage = speedImage + " -O /tmp/ " + ImageName
logInfo(ruleId, "Command: " + wget + " " + getImage)
var getImageResult = executeCommandLine(Duration.ofSeconds(10), wget, getImage)
logInfo(ruleId, "wget result: " + getImageResult)
var getBase64 = executeCommandLine(Duration.ofSeconds(10), base64, ImageName)
logInfo(ruleId, "Base64 result: " + getBase64)
spdImage.postUpdate(getBase64)
wget
is able to download the image but not into /tmp/
and i´m not able to find the file…
It´s not in the same directory the executeCommandLine
is working as the base64
isn´t able to see the file and convert it.
[INFO ] [g.openhab.core.model.script.TestRule] - Command: wget https://www.speedtest.net/result/c/c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png -O /tmp/ c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png
[INFO ] [g.openhab.core.model.script.TestRule] - wget result: --2021-08-07 17:28:39-- https://www.speedtest.net/result/c/c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png%20-O%20/tmp/%20c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png
Auflösen des Hostnamens www.speedtest.net (www.speedtest.net)… 151.101.66.219, 151.101.130.219, 151.101.2.219, ...
Verbindungsaufbau zu www.speedtest.net (www.speedtest.net)|151.101.66.219|:443 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 48712 (48K) [text/html]
Wird in » c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png« gespeichert.
0K .......... .......... .......... .......... ....... 100% 5,72M=0,008s
2021-08-07 17:28:40 (5,72 MB/s) - » c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png« gespeichert [48712/48712]
[INFO ] [g.openhab.core.model.script.TestRule] - Base64 result: base64: /tmp/c83e6a49-53c5-47c2-96be-8db3d2a53ec4.png: Datei oder Verzeichnis nicht gefunden
I´m wondering why the logged wget
command is correct but the base64
command has :
between the base64
and the filename.
And where is the wget
download stored?!
Doing this manually in a SSH sessions works without a problem.
- Platform information:
- Hardware: Raspberry Pi 4 Model B Rev 1.1
- OS: Raspbian GNU/Linux 10 (buster)
- Java Runtime Environment:
- openjdk version “11.0.12” 2021-07-20 LTS
- OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS)
- OpenJDK Client VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode)
- openHAB version: 3.1.0 (Build)