Im trying to consume 3 values, which i get from a Paho-Client (time, geometry, temperature).The values will be saved in an object named message.
Now i want to inject the three values throug a Service in my component to save them first in an array.
So far it is only working by injecting the object(message) with one of the values (message.geometry) in my component. Mi idea is to push messaage.geometry, message.timestamp and message.temperatur.
This is my Service withe the Paho-Client
@Injectable()
export class GeomqttService {
client: any;
geohistory = [
{
topic: '',
timestamp: '',
payloadstring: '',
geometry: ''
}
];
constructor() {
this.client = new Paho.MQTT.Client('testmqtt.de', 8080, 's');
this.onConnectionLost();
this.client.connect({onSuccess: this.onConnected.bind(this)});
}
onMessageArrived = (message: Paho.MQTT.Message) => {
this.geohistory.push({
'topic': 'temp',
'timestamp': message.timestamp,
'payloadstring': message.payloadString,
'geometry': message.geometry
});
};
onConnected() {
console.log('Connected');
this.client.geosubscribe('topic.temperature', '', 'geometry.BBOX(-180 -90, 180 90)', 'INTERSECTS');
this.client.onMessageArrived = (message: Paho.MQTT.Message) => {
this.onMessage(message.geometry);
console.log('Message arrived: ' + message.geometry);
}
}
public onMessage(message: string) {}
Here i get the message.geometry, but i would like to inject 3 of the vules in my component, to first save them in an array and use them later on .
My component:
import { Component, OnInit } from '@angular/core';
import {GeomqttService} from './geomqtt.service';
@Component({
selector: 'app-paho',
templateUrl: './paho.component.html',
styleUrls: ['./paho.component.css']
})
export class PahoComponent implements OnInit {
data = [
{
topic: '',
timestamp: '',
payloadstring: '',
geometry: ''
}
];
constructor(private geomqttService: GeomqttService) {
this.geomqttService.onMessage = (message: string) => {
this.data = [{topic: 'test', timestamp: '' , payloadstring: '', geometry: message}];
console.log(this.data);
};
}
ngOnInit(){}
}