@mhaberler/capacitor-barometer
v2.0.1
Published
Capacitor-Barometer is a native plugin for Capacitor that provides access to barometric pressure sensor data on supported devices. Easily integrate real-time atmospheric pressure readings into your cross-platform mobile apps for weather tracking, altitude
Readme
@mhaberler/capacitor-barometer
Capacitor-Barometer is a native plugin for Capacitor that provides access to barometric pressure sensor data on supported devices. Easily integrate real-time atmospheric pressure readings into your cross-platform mobile apps for weather tracking, altitude estimation, or scientific applications.
Install
npm install @mhaberler/capacitor-barometer
npx cap syncAPI
isAvailable()start(...)stop()getPressure()echo(...)addListener('onPressureChange', ...)removeAllListeners()- Interfaces
isAvailable()
isAvailable() => Promise<{ available: boolean; }>Checks if the barometer sensor is available on the device.
Returns: Promise<{ available: boolean; }>
start(...)
start(options?: { interval?: number | undefined; } | undefined) => Promise<void>Starts listening for barometer updates. This will also trigger the 'onPressureChange' event.
| Param | Type |
| ------------- | ----------------------------------- |
| options | { interval?: number; } |
stop()
stop() => Promise<void>Stops listening for barometer updates.
getPressure()
getPressure() => Promise<{ pressure: number; timestamp: number; }>Gets the last known pressure reading. Ensure 'start()' has been called and data is available.
Returns: Promise<{ pressure: number; timestamp: number; }>
echo(...)
echo(options: { value: string; }) => Promise<{ value: string; }>An echo method for testing.
| Param | Type |
| ------------- | ------------------------------- |
| options | { value: string; } |
Returns: Promise<{ value: string; }>
addListener('onPressureChange', ...)
addListener(eventName: 'onPressureChange', listenerFunc: (data: { pressure: number; timestamp: number; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandleCalled when pressure data changes.
| Param | Type | Description |
| ------------------ | ------------------------------------------------------------------------ | ------------------------------------------ |
| eventName | 'onPressureChange' | The name of the event ('onPressureChange') |
| listenerFunc | (data: { pressure: number; timestamp: number; }) => void | The callback function to be executed. |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
removeAllListeners()
removeAllListeners() => Promise<void>Removes all listeners for this plugin.
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
v2.0.0 Changes
Optional interval parameter for start()
The start() method now accepts an optional interval parameter (Android only):
await Barometer.start({ interval: 1000 }); // Interval in milliseconds- Android: The
intervalsets the sensor update rate (in ms). - iOS: The parameter is ignored; iOS uses the default update rate.
If omitted, the default interval
