https://github.com/denherrring/ng-mqtt
https://github.com/denherrring/ng-mqtt
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/denherrring/ng-mqtt
- Owner: DenHerrRing
- Created: 2020-08-17T18:28:23.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2020-08-18T09:03:15.000Z (almost 6 years ago)
- Last Synced: 2024-12-15T19:15:10.046Z (over 1 year ago)
- Language: TypeScript
- Size: 1.03 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ng-mqtt
This MQTT-Service/Wrapper is a library for Angular 10.
## installation
`npm i @denherrring/ng-mqtt --save`
## Usage
```
import { Observable } from 'rxjs';
import {
IMqttMessage,
MqttModule,
IMqttServiceOptions
} from 'ngx-mqtt';
export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
hostname: 'localhost',
port: 9001,
path: '/mqtt'
};
@NgModule({
imports: [
...
MqttModule.forRoot(MQTT_SERVICE_OPTIONS)
]
...
})
export class AppModule { }
@Component({
template: `
`
})
export class ExampleComponent implements OnDestroy {
private subscription: Subscription;
public message: string;
constructor(private _mqttService: MqttService) {
this.subscription = this._mqttService.observe('my/topic').subscribe((message: IMqttMessage) => {
this.message = message.payload.toString();
});
}
public unsafePublish(topic: string, message: string): void {
this._mqttService.unsafePublish(topic, message, {qos: 1, retain: true});
}
public ngOnDestroy() {
this.subscription.unsubscribe();
}
}
```
### Based on
This Project based on [ngx-mqtt](https://github.com/sclausen/ngx-mqtt).