Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Seungwoo-Yu-Projects-2021/capacitor-plugin-sensors

 
 

Repository files navigation

Capacitor Plugin Sensors

Support platform

  • android

Install

npm i --save capacitor-plugin-sensors

Usage example

import { SensorsPlugin, SensorType, Sensor } from 'capacitor-plugin-sensors/dist/esm';

// query sensors by type
SensorsPlugin.get(SensorType.ALL).then(
    sensors => {

        // find sensor whos type is SensorType.LIGHT
        let lightSensor: Sensor = null;
        for (const sensor of sensors) {
            if (sensor.type == SensorType.LIGHT && lightSensor == null) {
            lightSensor = sensor;
            }
            
            console.log(`get sensor: ${sensor.id}  ${sensor.name}  ${sensor.type}`);
        }

        if (lightSensor != null) {
            // start sensor and listening its values
            SensorsPlugin.start(lightSensor, values => {
                console.log(`get light values: ${values}`);
            }, error => {
                console.error(`get light value error: ${error}`);
            });
        }
    }
).catch(e => console.error(e));

About

capacitor plugin for list sensors and read sensor data easily.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 65.3%
  • TypeScript 15.5%
  • Swift 8.5%
  • Ruby 5.5%
  • Objective-C 3.7%
  • JavaScript 1.5%