limitExceed(params: any) {
params.forEach((data: any) => {
if (data.humidity === 100) {
this.createNotification('warning', data.sensor, false);
} else if (data.humidity >= 67 && data.humidity <= 99.99) {
this.createNotification('warning', data.sensor, true);
}
});
}
createNotification(type: string, title: string, types: boolean): void {
this.notification.config({
nzPlacement: 'bottomRight',
nzDuration: 5000,
});
if (types) {
this.notification.create(
type,
title,
'Humidity reached the minimum limit'
);
} else {
this.notification.create(
type,
title,
'Humidity reached the maximum'
);
}
}
how to make it trigger/alert every 5 minutes. but first it will alert then after the first alert/trigger it will alert/trigger again every 5 minutes.
cause I already set the setInterval
like this.
setInterval(() => {
if (types) {
this.notification.create(
type,
title,
'Humidity reached the minimum limit'
);
} else {
this.notification.create(
type,
title,
'Humidity reached the maximum'
);
}
}, 300000);
but it didn't alert/trigger first.
You could create your notifications first, once, then set the interval:
function createNotification() {
this.notification.create(...);
}
createNotification();
setInterval(() => {
createNotification();
}, 300000);
Or, even cleaner, you could use the timer()
Observable
:
import {timer} from 'rxjs';
// starts immediately, then every 5 minutes
timer(0, 300000).subscribe(() => {
this.notification.create(...);
});
createNotification() {
if (types) {
...
} else {
...
}
}
// then in another method :
this.createNotification();
setInterval(() => {
this.createNotification();
}, 300000);
// Or more simply :
this.createNotification();
setInterval(() => this.createNotification.bind(this) , 300000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With