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

Topic can't receive messages normally. #208

Open
rachel1512 opened this issue May 16, 2022 · 1 comment
Open

Topic can't receive messages normally. #208

rachel1512 opened this issue May 16, 2022 · 1 comment

Comments

@rachel1512
Copy link

rachel1512 commented May 16, 2022

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.

@sclausen
Copy link
Owner

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

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

2 participants