ngx-mqtt icon indicating copy to clipboard operation
ngx-mqtt copied to clipboard

Topic can't receive messages normally.

Open rachel1512 opened this issue 2 years ago • 1 comments

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.

rachel1512 avatar May 16 '22 10:05 rachel1512

Would you be so kind and provide a MWE as the issue template asked you to do so?

sclausen avatar Jul 11 '22 08:07 sclausen