Skip to content

Commit 0db0305

Browse files
author
Matteo Poli
committed
Now publish topic and subscribe topic are separeted
1 parent fc4d4f6 commit 0db0305

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/app/components/mqtt-client/mqtt-client.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
</mat-form-field>
174174

175175
<mat-form-field class="form-field">
176-
<input matInput placeholder="Topic" [(ngModel)]="subscribeTo.topics[0]" formControlName="publishTopic"/>
176+
<input matInput placeholder="Topic" [(ngModel)]="publishingTopic" formControlName="publishTopic"/>
177177
<mat-hint>Insert Topic where publish</mat-hint>
178178
</mat-form-field>
179179
<mat-form-field class="form-field">

src/app/components/mqtt-client/mqtt-client.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class MqttClientComponent implements OnInit {
4343
focussedMessage = new ShowedMessage('', '')
4444
proto: ProtoInfo = new ProtoInfo('', '', '', '')
4545
currentIndex: number
46+
publishingTopic: string
4647
publishingMessage: string
4748
publishingQos: number
4849
mqttConfig = 'mqttConfig.json'
@@ -440,7 +441,7 @@ export class MqttClientComponent implements OnInit {
440441
const payload = myMessage.create(JSON.parse(self.publishingMessage))
441442
const str = myMessage.encode(payload).finish()
442443
console.log(str.join(' ,'))
443-
client.publish(self.subscribeTo.topics[0], str, self.publishingQos ? self.publishingQos : '0')
444+
client.publish(self.publishingTopic, str, self.publishingQos ? self.publishingQos : '0')
444445
self.showSnackBar('Message published on MQTT.')
445446
}
446447
})
@@ -451,7 +452,7 @@ export class MqttClientComponent implements OnInit {
451452
// ======================================================================= //
452453

453454
publishHex() {
454-
client.publish(this.subscribeTo.topics[0], this.fromHexToString(this.publishingMessage), this.publishingQos ? this.publishingQos : '0')
455+
client.publish(this.publishingTopic, this.fromHexToString(this.publishingMessage), this.publishingQos ? this.publishingQos : '0')
455456
this.showSnackBar('Message published on MQTT.')
456457
}
457458

@@ -460,7 +461,7 @@ export class MqttClientComponent implements OnInit {
460461
// ======================================================================= //
461462

462463
publishString() {
463-
client.publish(this.subscribeTo.topics[0], this.publishingMessage, this.publishingQos ? this.publishingQos : '0')
464+
client.publish(this.publishingTopic, this.publishingMessage, this.publishingQos ? this.publishingQos : '0')
464465
this.showSnackBar('Message published on MQTT.')
465466
}
466467

@@ -532,6 +533,7 @@ export class MqttClientComponent implements OnInit {
532533
storage.get(dataPath + this.topicFile)
533534
.then(data => {
534535
this.subscribeTo.topics = data.topics
536+
this.publishingTopic = data.topics
535537
this.cd.detectChanges()
536538
})
537539
.catch(err => {
@@ -552,7 +554,7 @@ export class MqttClientComponent implements OnInit {
552554
console.error(err)
553555
})
554556
}
555-
})
557+
})
556558

557559
this.configurationForm = this._formBuilder.group({
558560
mqttBrokerAddress: this._formBuilder.control,

0 commit comments

Comments
 (0)