Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mteodor opened this issue Dec 26, 2020 · 0 comments

Comments

@mteodor
Copy link
Member

mteodor commented Dec 26, 2020

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}`, '');
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant