mainflux/ui

Add support for reading images being sent from connected devices, UI should display images.

Opened this issue · 0 comments

Some devices could send images over MQTT, HTTP...
If the images are being sent over MQTT, HTTP image payload must be base64 encoded.
Here is the example how image can be sent:

cat image.png | base64plain > image.b64.png
BYTE=`cat image.b64.png `
BYTE=[{\"bn\":\"text\",\"vs\":\"$BYTE\"}]
echo $BYTE > payload
mosquitto_pub -d -u $TH -P $KEY  -t channels/$CH/messages/images -h localhost -p 1883 -f payload

Example code where message sent over MQTT is receieved in UI over WS.

src/app/pages/services/gateways/details/xterm/gateways.xterm.component.html

<div #terminal></div>
<div>
    <img [src]="image"/>
  </div>
<div #terminal id="terminal"></div>
.... 
src/app/pages/services/gateways/details/xterm/gateways.xterm.component.ts
export class GatewaysXtermComponent implements AfterViewInit, OnChanges, OnDestr
   subscriptions: Subscription[] = new Array();
   uuid: string;
   connected: boolean;
    image = '';
 
      const imgTopic = `${this.createTopic(this.gateway.metadata.ctrl_channel_id)}/images/#`;
      this.chanSub = this.mqttService.observe(imgTopic).subscribe(
        (message: IMqttMessage) => {
          let res: string;
          const pl = message.payload.toString();
          res = JSON.parse(pl);
          const msg = <SenMLRec>(<any>res[0]);
          this.image = `data:image/png;base64,` + msg.vs;
        });
      this.notificationsService.success(`Subscribed to channel ${imgTopic}`, '');
  }