Demo App for own2mesh capacitor plugin.
Find the plugin here: https://www.npmjs.com/package/own2mesh-capacitor-plugin-oklok
You can find the demo app here: https://gitlab.edvsz.hs-osnabrueck.de/own2mesh/demo-ionic-own-2-mesh
- Clone & use our Demo App
- install Dependencies
git clone https://gitlab.edvsz.hs-osnabrueck.de/own2mesh/demo-ionic-own-2-mesh.git cd ./demo-ionic-own-2-mesh npm i
and then follow the instructions of the app!
- or create your own App
Start with a new ionic app
ionic start myApp blank --capacitor
Choose the framework you like (angular was used in the demo application)
Go to the project folder
cd myApp
Install the own2mesh-capacitor-plugin
npm i own2mesh-capacitor-plugin-oklok
You may need to update your podfile
npx cap add ios
The plugin uses bluetooth to connect to locks. Therefore it is necessary to have this information in the Info.plist
Add the following line to : myApp/ios/App/App/Info.plist
<key>NSBluetoothAlwaysUsageDescription</key> <string>Our app uses bluetooth to find, connect and transfer data between different devices</string>
npx cap sync
Don't forget to add yourself to the team and choose your bundle identifier
npx cap open ios
npx cap add android
npx cap sync
npx cap open android
File Path: myApp/android/app/src/main/java/io/ionic/starter/MainActivity.java
import de.own2mesh.plugin.oklok.Own2MeshOkLokPlugin;
add(Own2MeshOkLokPlugin.class);
The MainActivity.java should look like this:
package de.own2mesh.own2mesh_demo; import android.os.Bundle; import com.getcapacitor.BridgeActivity; import com.getcapacitor.Plugin; import java.util.ArrayList; import de.own2mesh.plugin.oklok.Own2MeshOkLokPlugin; public class MainActivity extends BridgeActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initializes the Bridge this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{ // Additional plugins you've installed go here // Ex: add(TotallyAwesomePlugin.class); add(Own2MeshOkLokPlugin.class); }}); } }
Import the plugin
import {Plugins} from '@capacitor/core'; const {Own2MeshOkLokPlugin} = Plugins;
How to use a methode
Own2MeshOkLokPlugin.theMethodeYouLike();
lockName = {
name: string, // Physical lock name
address: string, // MAC Address (for android)
secret: string[16], // lock key as hexadecimal integer literal string array[16 items] (Begins with the 0 digit followed by either an x or X, followed by any combination of the digits 0 through 9 and the letters a through f or A through F.)
pw: string[6] // password as hexadecimal integer literal string array[6 items] (Begins with the 0 digit followed by either an x or X, followed by any combination of the digits 0 through 9 and the letters a through f or A through F.)
}
Important Hex Strings have to start with a leading 0 if they are single digit
lockOKGSS101 = {
name: 'OKGSS101',
address: 'F8:45:65:64:CC:B4',
secret: ['0x4c', '0x5f', '0x0c', '0x3c', '0x4c', '0x28', '0x53', '0x24', '0x23', '0x36', '0x12', '0x5b', '0x33', '0x59', '0x21', '0x04'],
pw: ['0x33', '0x32', '0x31', '0x39', '0x33', '0x37']
}
ionic build
Now you are ready to use the own2mesh-capacitor-plugin-oklok
NOTE: After you changed something run:
ionic build npx cap sync npx cap open "platform"
- Test Methode
Call this methode to make sure you can communicate with the plugin. Result by success: {"value":"Hello back from own-2-mesh plugin!"}
echo(options: { value: string }): Promise<{ value: string }>;
echo() { Own2MeshOkLokPlugin.echo({ value: 'Hello Own2MeshOkLokPlugin!' }).then(result => { console.log(result.value); }); }
- Open lock
Call this methode to open a lock.
open(options: { name: string, address: string, secret: string[], pw: string[] }): Promise<{ opened: boolean }>;
openLock() { Own2MeshOkLokPlugin.open({ name: lock.modelName, address: lock.address, secret: lock.secret, pw: lock.pw }).then(result => { console.log(result.opened); }); }
- Get battery status
Call this methode to get the battery status.
battery_status(options: { name: string, address: string, secret: string[] }): Promise<{ percentage: number }>;
batteryInfo() { Own2MeshOkLokPlugin.battery_status({ name: lock.name, secret: lock.secret, }).then(result => { console.log(result.percentage); }); }
- Get lock status
Call this methode to get the lock status.
lock_status(options: { name: string, address: string, secret: string[] }): Promise<{ locked: boolean }>;
lockStatus() { Own2MeshOkLokPlugin.lock_status({ name: lock.modelName, secret: lock.secret, }).then(result => { console.log(result.locked); }); }
- Get lock status
Call this methode to close a lock.
close(options: { name: string, address: string, secret: string[] }): Promise<{ closed: boolean }>;
closeLock() { Own2MeshOkLokPlugin.close({ name: lock.name, address: lock.address, secret: lock.secret, pw: lock.pw }).then(result => { this.openLockStatus = result.closed; }); }