Is it possible to display image in openHAB UI that is collected from MQTT protocol as a base64 data.
MQTT(base64 data)------------->OpenHAB(image)
Is it possible to display image in openHAB UI that is collected from MQTT protocol as a base64 data.
MQTT(base64 data)------------->OpenHAB(image)
Not easily. What you would need to do is receive the message and in a Rule decode the base64 into a binary file and save that file to a well-known location under the conf/html folder. You can then set an Item with the name of the Image and use the Image element on your sitemap.
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.lang.String
import javax.imageio.ImageIO;
rule "image re"
when
Item getImage received update
then
var String base64Image=getImage.state.toString
logInfo("image","image entered in pir sensor")
var byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image);
var BufferedImage img
try {
img = ImageIO.read(new ByteArrayInputStream(imageBytes));
// write the image to a file
File outputfile = new File("C:\\openhab\\conf\\icons\\classic\\image.png");
ImageIO.write(img, "png", outputfile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
end
but nothing is storing in file location
Are you getting errors in the logs?
For example, you are likely getting an error in the line ImageIO.read because read is a static method and one references static methods using ::, e.g. ImageIO::read
am getting this issuse after executing this line img = ImageIO.read(new ByteArrayInputStream(imageBytes));
2017-09-27 11:02:13.975 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘image re’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: CDI.rules#|::0.2.2.2.0.5.0.0.3::0::/1)
Now its working, Thanks just i changed
File outputfile = new File(“C:\openhab\conf\icons\classic\image.png”);
to
val File outputfile = new File(“C:\openhab\conf\icons\classic\image.png”);
is it possible to show video in openHAB ui