ngx-mqtt
ngx-mqtt copied to clipboard
Topic can't receive messages normally.
constructor(private _mqttService: MqttService ) {}
ngOnInit(): void {
this._mqttService.connect();
this.getMessage();
}
getMessage() {
this.mqttSubscription = this._mqttService
.observe(key)
.subscribe((message: IMqttMessage) => {
console.log(message.payload.toString());
});
}
app.module
export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
hostname: 'mqtest.nbamyl.com',
port: 443,
protocol: location.protocol === 'https:' ? 'wss' : 'ws',
username: 'auxyl',
password: 'Auxyl2020',
path: '/ws',
keepalive: 10,
connectOnCreate: false
};
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
SharedModule,
ServicesModule,
MqttModule.forRoot(MQTT_SERVICE_OPTIONS),
// routing module should stay at bottom
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
It works well at first, but there is no message after a while. then I reload the page, it is back to normal again.
Would you be so kind and provide a MWE as the issue template asked you to do so?