Skip to content

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

Description

@mteodor

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}`, '');
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions