Giter VIP home page Giter VIP logo

com.sensimity.ti.client's Introduction

Sensimity Appcelerator client

Client implementation for communication with the Sensimity platform (http://sensimity.com)

  • Get the networks and beacons/geofences from the sensimity-API (see also http://sensimity.github.io/docs/)
  • Scan for beacons/geofences within a defined Sensimity network
  • Handle beacon/geofences and business-rules (defined in Sensimity Dashboard)

Notes

To use this module it's necessary to use the Sensimity forks of two Appcelerator Titanium modules. The original ones are outdated and seem unmaintained.

Install

The installation- and configuration description is optimized for usage via the Titanium Alloy framework.

  1. Download the Sensimity client from the dist folder and copy it into the modules/commonjs directory.

  2. Add the following modules to the modules folder:

  3. Add the dependencies into the modules directory, used for the connection with the Sensimity-API and to send statistics to Sensimity:

  4. Define the modules into the tiapp.xml:

    <modules>
        <module platform="commonjs" version="0.8.0">com.sensimity.ti.client</module>
        <module platform="commonjs" version="1.1.8">reste</module>
        <module platform="iphone" version="0.12.0">org.beuckman.tibeacons</module>
        <!--<module platform="iphone" version="0.5.0">com.sensimity.ti.pathsense</module>-->
        <module platform="iphone" version="0.3">ti.mely</module>
        <module platform="android" version="1.5.0">com.drtech.altbeacon</module>
        <!--<module platform="android" version="0.5.0">com.sensimity.ti.pathsense</module>-->
        <module platform="android" version="0.1">ti.mely</module>
    </modules>
    
  5. Define a path to the backgroundService to use the module on Android:

    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <services>
            <service url="services/handleBackgroundScan.js" type="standard"/>
        </services>
    </android>
    
  6. Define the reason of using iBeacons

    <plist>
        <dict>
            <key>NSLocationAlwaysUsageDescription</key>
            <string>Your description for the reason of using iBeacons</string>
            <!-- in case of geofences -->
            <key>NSMotionUsageDescription</key>
            <string>Your description for the reason of using Geofences</string>
        </dict>
    </plist>
    

Configuration

  1. Setup your (module/config.json). Credentials can be requested through our contact form on: http://sensimity.com/contact-us-v1/ . These credentials can be used to retrieve the network information needed to integrate Sensimity in your app(s). The data-structure for Sensimity is like this:

        {
            "global": {
                "sensimity": {
                    "basicHeaderAuthUsername": "<string>",
                    "basicHeaderAuthPassword": "<string>",
                    "username": "<string>",
                    "password": "<string>",
                    // Can be found at the Sensimity-dashboard (after login)
                    "instanceRef": "S-<hex eight characters>-<serial-number>",
                    // necessary for android usage
                    "backgroundService": "services/handleBackgroundScan.js",
                    "monitoringScope": 'uuid|major|minor' // Optionally for beacons, default UUID
                }
            }
        }
    
  2. Bootstrap the sensimity logic (only if BLE enabled):

        var sensimity = require('com.sensimity.ti.client'),
            callback = function (successMessage) {
                if (!successMessage.success.ble && !successMessage.success.geofence) {
                    console.log('sensimity start failed');
                }
            };
        if (OS_IOS) {
            sensimity.start({
                networkId: <integer network-id>
            }, callback);
        } else if (OS_ANDROID) {
            sensimity.runService({
                 networkId: <integer network-id>
            }, callback);
        }
    
  3. [ANDROID only] Define the background service. (app/lib/android/services/handleBackgroundScan.js).:

    	var service = Ti.Android.currentService;
    	var serviceIntent = service.intent;
    	var sensimity = require('com.sensimity.ti.client');
    
        if (serviceIntent.getIntExtra('networkId', -1) !== -1) {
    	    sensimity.start({
    	        networkId: serviceIntent.getIntExtra('networkId', -1),
    	        runInService: true,
    	        behavior: 'aggressive'
    	    });
    	}
    	
    	function stop() {
    	    service.removeEventListener('taskremoved', stop);
    	    sensimity.stop();
    	    service.stop();
    	}
    	    
    	// Stop sensimity on taskremoved service
        service.addEventListener('taskremoved', stop);
    

Methods

All of the methods are accessible by using the Sensimity Client library:

var sensimity = require('com.sensimity.ti.client');

  • Start scanning within a specified network (only if BLE enabled), if BLE disabled please check the callback

    sensimity.start({
        networkId: <integer>,
    	runInService: true, // Optional, Android only
    	behavior: 'aggressive|proactive' // Optional, Android only
    }, <success callback>);
    
  • Stop scanning every network

    sensimity.stop();
    
  • Check BLE supported on current device

    Ti.API.info('Is BLE scanning supported: 'sensimity.isBLESupported());
    
  • Check BLE is supported and enabled on current device

    sensimity.isBLEEnabled(function (enabled) {
        Ti.API.info('Is BLE scanning enabled: ' + enabled);
    });
    
  • [ANDROID only] Put sensimity into backgroundmode scanning

    sensimity.pause();
    
  • [ANDROID only] Put sensimity into foregroundmode scanning back again

    sensimity.resume();
    
  • Sensimity client

    // Get networks
    sensimity.client.getNetworks({
        networkId: <integer>
    });
    

Events

To handle the triggered Business Rules and to handle the detected iBeacons, use the following eventListeners:

  • Handle triggered Business rule

    Ti.App.addEventListener('sensimity:beacon', function (e) {
        e = {
            beacon: <Detected beacon data>,
            knownBeacon: <Beacon known from Sensimity>,
            eventType: <enterregion|exitregion|ranging>
        };
    });
    
  • Handle triggered Business rule

    Ti.App.addEventListener('sensimity:businessrule', function (e) {
        e = {
            businessRule: <Triggered business rule>,
            beacon: <Detected beacon data>,
            knownBeacon: <Beacon known from Sensimity>
        };
    });
    

Credits

com.sensimity.ti.client's People

Contributors

adri avatar williamrijksen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.