motion-sensoro 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e815dc934bcd573e070f0605eb6099a3c9c9be49
4
+ data.tar.gz: ba55a7d9070777231b652e8423c270bf66176b61
5
+ SHA512:
6
+ metadata.gz: 421619445e4d69a9ce8c57abf122f20a6650365b01c6e6f7e19796f1619e2437946bedb13a917f9395c65bf62df35aa196ec91f53fc83ce9c0340c44b9059cb2
7
+ data.tar.gz: 9f0c6f38613469ba486181d911cba4cdd6060494e4c3212325c93c04bb9aa2850e2764cb1645f45fc3adad4fee6f349da105d10647e9e220a5d657fd329f8051
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2016 CargoSense Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the documentation
10
+ and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,61 @@
1
+ # motion-sensoro
2
+
3
+ motion-sensoro is a cross-platform API for <a href="http://www.rubymotion.com">RubyMotion</a> projects that want to access the <a href="http://www.sensoro.com/en/developer">Sensoro SDK</a>.
4
+
5
+ It provides a simple Ruby DSL on top of the SDK APIs that works both on iOS and Android.
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ $ gem install motion-sensoro
11
+ ```
12
+
13
+ Then include `motion-sensoro in your RubyMotion project's Gemfile or Rakefile.
14
+
15
+ ## API reference
16
+
17
+ ### Start listening to beacons
18
+
19
+ The `SensoroBeaconManager.start_listening` method can be used to register a block that will be called when a beacon is found or lost.
20
+
21
+ The given block will be called with 2 arguments: a `Symbol`, either `:beacon_found` or `:beacon_lost`, representing the event type, and a `SensoroBeacon` object representing the beacon.
22
+
23
+ ```ruby
24
+ SensoroBeaconManager.start_listening do |what, beacon|
25
+ case what
26
+ when :beacon_found
27
+ puts "Found beacon! #{beacon}"
28
+ when :beacon_lost
29
+ puts "Lost beacon! #{beacon}"
30
+ end
31
+ end
32
+ ```
33
+
34
+ ### Stop listening to beacons
35
+
36
+ ```ruby
37
+ SensoroBeaconManager.stop_listening
38
+ ```
39
+
40
+ ### Accessing the properties of a beacon
41
+
42
+ A `SensoroBeacon` object responds to the following methods:
43
+
44
+ ```ruby
45
+ beacon.uuid # proximity UUID, as a String
46
+ beacon.major # major value (representing a group of beacons), as an Integer
47
+ beacon.minor # minor value (representing a specific beacon within a group), as an Integer
48
+ beacon.serial_number # hardware serial number, as a String
49
+ beacon.battery_level # battery level as a Float from 0.0 to 1.0 (1.0 meaning fully charged)
50
+ beacon.firmware_version # current firmware version for the device
51
+ beacon.temperature # temperature value in Celsius, as an Integer
52
+ beacon.light # ambient light level in lux, as an Integer
53
+ beacon.accelerometer_count # number of accelerometer counts, as an Integer
54
+ beacon.accuracy # accuracy of the proximity value, measured in meters from the beacon, as an Integer
55
+ beacon.rssi # received signal strength of the beacon, measured in decibels, as an Integer
56
+ beacon.model_name # hardware model name of the device, as a String
57
+ ```
58
+
59
+ ## License
60
+
61
+ motion-sensoro is published under the BSD license. Check the `LICENSE` file for more information.
@@ -0,0 +1,61 @@
1
+ class SensoroBeaconManagerListener
2
+ def initialize(callback)
3
+ @callback = callback
4
+ @cache = {}
5
+ end
6
+
7
+ def onNewBeacon(beacon)
8
+ @callback.call :beacon_found, _beacon(beacon)
9
+ end
10
+
11
+ def onGoneBeacon(beacon)
12
+ @callback.call :beacon_lost, _beacon(beacon)
13
+ end
14
+
15
+ def onUpdateBeacon(beacons)
16
+ # TODO: refresh beacon sensors info
17
+ end
18
+
19
+ def _beacon(beacon)
20
+ @cache[beacon.serialNumber] ||= begin
21
+ obj = SensoroBeacon.new
22
+ obj.uuid = beacon.getProximityUUID
23
+ obj.major = beacon.getMajor
24
+ obj.minor = beacon.getMinor
25
+ obj.serial_number = beacon.getSerialNumber
26
+ obj.battery_level = beacon.getBatteryLevel
27
+ obj.remaining_lifetime = beacon.getRemainingLifetime
28
+ obj.firmware_version = beacon.getFirmwareVersion
29
+ obj.temperature = beacon.getTemperature
30
+ obj.light = beacon.getLight
31
+ obj.accelerometer_count = beacon.getAccelerometerCount
32
+ obj.accuracy = beacon.getAccuracy
33
+ obj.rssi = beacon.getRssi
34
+ obj.model_name = beacon.getHardwareModelName
35
+ obj
36
+ end
37
+ end
38
+ end
39
+
40
+ class SensoroBeaconManager
41
+ def self.context=(context)
42
+ @sensoroManager = Com::Sensoro::Cloud::SensoroManager.getInstance(context)
43
+ end
44
+
45
+ def self._sensoroManager
46
+ @sensoroManager or raise "Set `#{self}.context = self' in your main activity file."
47
+ end
48
+
49
+ def self.enabled?
50
+ _sensoroManager.isBluetoothEnabled
51
+ end
52
+
53
+ def self.start_listening(&callback)
54
+ _sensoroManager.setBeaconManagerListener(SensoroBeaconManagerListener.new(callback))
55
+ _sensoroManager.startService
56
+ end
57
+
58
+ def self.stop_listening
59
+ _sensoroManager.stopService
60
+ end
61
+ end
@@ -0,0 +1,58 @@
1
+ class SensoroBeaconManagerListener
2
+ def initialize(callback)
3
+ @callback = callback
4
+ @cache = {}
5
+ end
6
+
7
+ def beaconManager(manager, didRangeNewBeacon:beacon)
8
+ @callback.call :beacon_found, _beacon(beacon)
9
+ end
10
+
11
+ def beaconManager(manager, beaconDidGone:beacon)
12
+ @callback.call :beacon_lost, _beacon(beacon)
13
+ end
14
+
15
+ def beaconManager(manager, scanDidFinishWithBeacons:beacons)
16
+ # TODO: refresh beacon sensors info
17
+ end
18
+
19
+ def _beacon(beacon)
20
+ @cache[beacon.serialNumber] ||= begin
21
+ obj = SensoroBeacon.new
22
+ obj.uuid = beacon.beaconID.proximityUUID
23
+ obj.major = beacon.beaconID.major
24
+ obj.minor = beacon.beaconID.minor
25
+ obj.serial_number = beacon.serialNumber
26
+ obj.battery_level = beacon.batteryLevel
27
+ obj.firmware_version = beacon.firmwareVersion
28
+ obj.temperature = beacon.temperature
29
+ obj.light = beacon.light
30
+ obj.accelerometer_count = beacon.accelerometerCount
31
+ obj.accuracy = beacon.accuracy
32
+ obj.rssi = beacon.rssi
33
+ obj.model_name = beacon.hardwareModelName
34
+ obj
35
+ end
36
+ end
37
+ end
38
+
39
+ class SensoroBeaconManager
40
+ def self.enabled?
41
+ true # TODO
42
+ end
43
+
44
+ def self.start_listening(&callback)
45
+ @listener ||= begin
46
+ listener = SensoroBeaconManagerListener.new(callback)
47
+ SBKBeaconManager.sharedInstance.requestAlwaysAuthorization
48
+ SBKBeaconManager.sharedInstance.delegate = listener
49
+ SBKBeaconManager.sharedInstance.startRangingBeaconsWithID(SBKBeaconID.beaconIDWithProximityUUID(SBKSensoroDefaultProximityUUID), wakeUpApplication:true)
50
+ listener
51
+ end
52
+ end
53
+
54
+ def self.stop_listening
55
+ SBKBeaconManager.sharedInstance.stopRangingAllBeacons
56
+ SBKBeaconManager.sharedInstance.delegate = @listener = nil
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ case Motion::Project::App.template
7
+ when :android
8
+ app.files.concat(Dir.glob(File.join(File.dirname(__FILE__), "android/*.rb")))
9
+ Dir.glob(File.join(File.dirname(__FILE__), "../vendor/android/*.jar")).each do |jar|
10
+ app.vendor_project :jar => jar
11
+ end
12
+ app.permissions += ["android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.INTERNET", "android.permission.ACCESS_FINE_LOCATION"]
13
+ app.services += ["com.sensoro.beacon.kit.BeaconProcessService", "com.sensoro.beacon.kit.BeaconService", "com.sensoro.beacon.kit.IntentProcessorService"]
14
+ when :ios
15
+ app.files.concat(Dir.glob(File.join(File.dirname(__FILE__), "ios/*.rb")))
16
+ app.vendor_project(File.join(File.dirname(__FILE__), "../vendor/ios"), :static, :products => ['libSensoroBeaconKit.a', 'libSensoroCloud.a'], cflags: "-fobjc-arc")
17
+ app.frameworks += ["CoreBluetooth", "CoreLocation", "Security"]
18
+ else
19
+ raise "Project template #{Motion::Project::App.template} not supported by motion-sensoro"
20
+ end
21
+ app.files << File.join(File.dirname(__FILE__), 'sensoro_beacon.rb')
22
+ end
@@ -0,0 +1,18 @@
1
+ class SensoroBeacon
2
+ Properties = [:uuid, :major, :minor, :serial_number, :battery_level, :firmware_version, :temperature, :light, :accelerometer_count, :accuracy, :rssi, :model_name]
3
+ Properties.each { |x| attr_accessor x }
4
+
5
+ def <=>(obj)
6
+ obj.is_a?(SensoroBeacon) ? serial_number <=> obj.serial_number : 1
7
+ end
8
+
9
+ def to_h
10
+ hash = {}
11
+ Properties.each { |x| hash[x] = send(x) }
12
+ hash
13
+ end
14
+
15
+ def inspect
16
+ "<SensoroBeacon #{to_h.to_a.map { |k, v| "#{k}=#{v}" }.join(' ')}>"
17
+ end
18
+ end
@@ -0,0 +1,765 @@
1
+ //
2
+ // SBKBeacon.h
3
+ // Sensoro Beacon Kit
4
+ //
5
+ // Created by Blankwonder on 6/12/14.
6
+ // Copyright (c) 2014 Sensoro Inc. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import <CoreBluetooth/CoreBluetooth.h>
11
+ #import <CoreLocation/CoreLocation.h>
12
+ #import "SBKConstants.h"
13
+ #import "SBKBeaconID.h"
14
+
15
+ extern NSString * const SBKBeaconInRangeStatusUpdatedNotification;
16
+
17
+ /// the block as a callback when app communicate with beacon
18
+ typedef void (^SBKBeaconCompletionBlock)(NSError *error);
19
+
20
+ @protocol SBKBeaconDelegate;
21
+
22
+ /**
23
+ * The SBKBeacon class defines the interface of a sensoro beacon device. You can use instances of this class to get rssi, sensor data or configurate device settings. You do not create instances of this class directly. Use SBKBeaconManager to get SBKBeacon instances.
24
+ *
25
+ * The identity of a beacon is defined by its beaconID properties.
26
+ */
27
+ @interface SBKBeacon : NSObject
28
+
29
+ /**---------------------------------------------------------------------------------------
30
+ * @name Setting and Getting the Delegate
31
+ * ---------------------------------------------------------------------------------------
32
+ */
33
+
34
+ /**
35
+ * The delegate of the app object.
36
+ */
37
+ @property (readwrite, nonatomic, weak) id <SBKBeaconDelegate> delegate;
38
+
39
+ /**---------------------------------------------------------------------------------------
40
+ * @name General Properties
41
+ * ---------------------------------------------------------------------------------------
42
+ */
43
+
44
+ /**
45
+ * A SBKBeaconID object identify the beacon. (read-only)
46
+ */
47
+ @property (readonly, nonatomic, copy) SBKBeaconID * beaconID;
48
+
49
+ /**
50
+ * The beacon's hardware serial number. (read-only)
51
+ */
52
+ @property (readonly, nonatomic, copy) NSString * serialNumber;
53
+
54
+ /**
55
+ * Returns a Boolean value that indicates whether the beacon is in range. (read-only)
56
+ *
57
+ * @discussion Beacon will be marked out of range after approximate 8 second in order to prevent notifications delivering too frequently.
58
+ */
59
+ @property (readonly, nonatomic, assign) BOOL inRange;
60
+
61
+ /**
62
+ * the rssi value to decide if entering range of beacon.
63
+ *
64
+ * @discussion if received rssi is larger than this value, it is in range of this beacon.
65
+ */
66
+ @property (readwrite, nonatomic, assign) NSInteger inRangeMinimumRssiWhileEntering;
67
+
68
+ /**
69
+ * the rssi value to decide if leaving range of beacon.
70
+ *
71
+ * @discussion if received rssi is less than this value, it is out of range of this beacon.
72
+ */
73
+ @property (readwrite, nonatomic, assign) NSInteger inRangeMinimumRssiWhileLeaving;
74
+
75
+ /**
76
+ * The received signal strength of the beacon, measured in decibels. (read-only)
77
+ *
78
+ * @discussion If beacon is out of range, the value will be 0.
79
+ */
80
+ @property (readonly, nonatomic, assign) NSInteger rssi;
81
+
82
+ /**
83
+ * The relative distance to the beacon. (read-only)
84
+ *
85
+ * @discussion The value in this property gives a general sense of the relative distance to the beacon. Use it to quickly identify beacons that are nearer to the user rather than farther away.
86
+ */
87
+ @property (readonly, nonatomic, assign) CLProximity proximity;
88
+
89
+ /**
90
+ * The accuracy of the proximity value, measured in meters from the beacon. (read-only)
91
+ *
92
+ * @discussion Indicates the one sigma horizontal accuracy in meters. Use this property to differentiate between beacons with the same proximity value. Do not use it to identify a precise location for the beacon. Accuracy values may fluctuate due to RF interference. A negative value in this property signifies that the actual accuracy could not be determined.
93
+ */
94
+ @property (readonly, nonatomic) CLLocationAccuracy accuracy;
95
+
96
+ /**
97
+ * The battery charge level for the device. (read-only)
98
+ *
99
+ * @discussion Battery level ranges from 0.0 to 1.0 (100% charged).
100
+ */
101
+ @property (readonly, nonatomic, copy) NSNumber * batteryLevel;
102
+
103
+ /**
104
+ * The model of the device. (read-only)
105
+ */
106
+ @property (readonly, nonatomic, copy) NSString * hardwareModelName;
107
+
108
+ /**
109
+ * The current firmware version for the device. (read-only)
110
+ */
111
+ @property (readonly, nonatomic, copy) NSString * firmwareVersion;
112
+
113
+ /**
114
+ * The current work model for the device. (read-only)
115
+ */
116
+ @property (readonly, nonatomic) SBKBeaconWorkMode workModel;
117
+
118
+ /**---------------------------------------------------------------------------------------
119
+ * @name Establishing or Canceling Connections with Beacon
120
+ * ---------------------------------------------------------------------------------------
121
+ */
122
+
123
+ /**
124
+ * Establishes a connection to a beacon.
125
+ *
126
+ * @param completion The block to execute after the connecting is completed. If error parameter is nil means connection has been established successfully.
127
+ */
128
+ - (void)connectWithCompletion:(SBKBeaconCompletionBlock)completion;
129
+ /**
130
+ * Cancels an active or pending connection to a beacon.
131
+ */
132
+ - (void)disconnect;
133
+ /**
134
+ * The current status of the connection.
135
+ *
136
+ * @return A SBKBeaconConnectionStatus enum value.
137
+ */
138
+ - (SBKBeaconConnectionStatus)connectionStatus;
139
+
140
+
141
+ /**---------------------------------------------------------------------------------------
142
+ * @name Beacon Configuration
143
+ * ---------------------------------------------------------------------------------------
144
+ */
145
+
146
+ /**
147
+ * The dictionary of beacon base configuration attributes. (read-only)
148
+ *
149
+ * @discussion This property will be available after connect. For available options, see SBKBeaconBaseSettings.
150
+ *
151
+ * @see writeBaseSettings:completion:
152
+ */
153
+ @property (readonly, nonatomic) NSDictionary *baseSettings;
154
+
155
+ /**
156
+ * The dictionary of sensor configuration attributes. (read-only)
157
+ *
158
+ * @discussion This property will be available after connect. For available options, see SBKBeaconSensorSettings.
159
+ *
160
+ * @see writeSensorSettings:completion:
161
+ */
162
+ @property (readonly, nonatomic) NSDictionary *sensorSettings;
163
+
164
+ /**
165
+ * The value of sensor umm change interval attributes. (read-only)
166
+ *
167
+ * you can change value, @see writeSecureBroadcastInterval:completion:
168
+ */
169
+ @property (readonly, nonatomic) SBKBeaconSecureBroadcastInterval secureBroadcastInterval;
170
+
171
+ /**
172
+ * Updates proximity UUID of this beacon.
173
+ *
174
+ * @param proximityUUID Proximity UUID in NSUUID object.
175
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
176
+ *
177
+ * @return Can this writing operation be executed.
178
+ */
179
+ - (BOOL)writeProximityUUID:(NSUUID *)proximityUUID completion:(SBKBeaconCompletionBlock)completion;
180
+
181
+ /**
182
+ * Updates major and minor of this beacon.
183
+ *
184
+ * @param major The major value.
185
+ * @param minor The minor value.
186
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
187
+ *
188
+ * @return Can this writing operation be executed.
189
+ */
190
+ - (BOOL)writeMajor:(NSNumber *)major minor:(NSNumber *)minor completion:(SBKBeaconCompletionBlock)completion;
191
+
192
+ /**
193
+ * Updates base settings of this beacon.
194
+ *
195
+ * @param settings Configuration attributes you try to update in a dictionary. For available options, see SBKBeaconBaseSettings.
196
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
197
+ *
198
+ * @return Can this writing operation be executed.
199
+ */
200
+ - (BOOL)writeBaseSettings:(NSDictionary *)settings completion:(SBKBeaconCompletionBlock)completion;
201
+
202
+ /**
203
+ * Updates sensor settings of this beacon.
204
+ *
205
+ * @param settings Configuration attributes you try to update in a dictionary. For available options, see SBKBeaconSensorSettings.
206
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
207
+ *
208
+ * @return Can this writing operation be executed.
209
+ */
210
+ - (BOOL)writeSensorSettings:(NSDictionary *)settings completion:(SBKBeaconCompletionBlock)completion;
211
+
212
+ /**
213
+ * Resets beacon to factory settings. This will reset proximityUUID, major, minor, baseSettings and sensorSettings to original values.
214
+ *
215
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
216
+ *
217
+ * @return Can this writing operation be executed.
218
+ */
219
+ - (BOOL)resetToFactorySettingsWithCompletion:(SBKBeaconCompletionBlock)completion;
220
+
221
+ /**
222
+ * Updates UMM Change interval.
223
+ *
224
+ * @param interval The Secure Broadcast change interval. it is enum of @see SBKBeaconSecureBroadcastInterval;
225
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
226
+ *
227
+ * @return Can this writing operation be executed.
228
+ */
229
+ - (BOOL)writeSecureBroadcastInterval:(SBKBeaconSecureBroadcastInterval)interval completion:(SBKBeaconCompletionBlock)completion;
230
+
231
+ /**
232
+ * Updates the key to encrypt the broadcast packet.
233
+ *
234
+ * @param key the key to encrypt the broadcast packet;
235
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
236
+ *
237
+ * @return Can this writing operation be executed.
238
+ */
239
+ - (BOOL)writeBroadcastKey:(NSString*) key completion:(SBKBeaconCompletionBlock)completion;
240
+
241
+ /**
242
+ * Clear the key to encrypt the broadcast packet.
243
+ *
244
+ * @param completion The block to execute after the clear is completed. If error parameter is nil means writing successfully.
245
+ *
246
+ * @return Can this clear operation be executed.
247
+ */
248
+ - (BOOL)clearBroadcastKeyWithCompletion:(SBKBeaconCompletionBlock)completion;
249
+
250
+ /**
251
+ * Disable the iBeacon broadcast.
252
+ *
253
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
254
+ *
255
+ * @return Can this writing operation be executed.
256
+ */
257
+ - (BOOL)disableiBeaconWithCompletion:(SBKBeaconCompletionBlock)completion;
258
+
259
+ /**
260
+ * Enable the iBeacon broadcast.
261
+ *
262
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
263
+ *
264
+ * @return Can this writing operation be executed.
265
+ */
266
+ - (BOOL)enableiBeaconWithCompletion:(SBKBeaconCompletionBlock)completion;
267
+
268
+
269
+ /**
270
+ * Disable the AliBeacon broadcast.
271
+ *
272
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
273
+ *
274
+ * @return Can this writing operation be executed.
275
+ */
276
+ - (BOOL)disableAliBeaconWithCompletion:(SBKBeaconCompletionBlock)completion;
277
+
278
+ /**
279
+ * Enable the AliBeacon broadcast.
280
+ *
281
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
282
+ *
283
+ * @return Can this writing operation be executed.
284
+ */
285
+ - (BOOL)enableAliBeaconWithCompletion:(SBKBeaconCompletionBlock)completion;
286
+
287
+ /**
288
+ * Disable the enhance broadcast.
289
+ *
290
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
291
+ *
292
+ * @return Can this writing operation be executed.
293
+ *
294
+ * @discussion the Enhance broadcast can make the SDK find this device as Sensoro device even if iOS device was locked,
295
+ * in other words, the screen was turned off. Normally, this device can be found by iOS device as a iBeacon device. if
296
+ * you want use SDK and find Sensoro device when the iOS device was locked, you need enable this feature. To enable this
297
+ * mode will increase the power consumption.
298
+ */
299
+ - (BOOL)disableEnhanceBroadcastWithCompletion:(SBKBeaconCompletionBlock)completion;
300
+
301
+ /**
302
+ * Enable the enhance broadcast.
303
+ *
304
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
305
+ *
306
+ * @return Can this writing operation be executed.
307
+ *
308
+ * @discussion the Enhance broadcast can make the SDK find this device as Sensoro device even if iOS device was locked,
309
+ * in other words, the screen was turned off. Normally, this device can be found by iOS device as a iBeacon device. if
310
+ * you want use SDK and find Sensoro device when the iOS device was locked, you need enable this feature. To enable this
311
+ * mode will increase the power consumption.
312
+ */
313
+ - (BOOL)enableEnhanceBroadcastWithCompletion:(SBKBeaconCompletionBlock)completion;
314
+
315
+ /**
316
+ * flash light of SmartBeacon.
317
+ *
318
+ * @param command If the bit of command is 1, then this light will turn on one times, if 0 ,the light turn off.
319
+ * you can use custom command, or use @see SBKCommonLigthFlashCommand
320
+ * @param repeatCount The count that command was repeat.
321
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
322
+ *
323
+ * @return Can this writing operation be executed.
324
+ */
325
+ - (BOOL)flashLightWithCommand:(UInt8)command
326
+ repeat:(UInt8)repeatCount
327
+ completion:(SBKBeaconCompletionBlock)completion;
328
+
329
+ /**---------------------------------------------------------------------------------------
330
+ * @name Writing Authorization
331
+ * ---------------------------------------------------------------------------------------
332
+ */
333
+
334
+ /**
335
+ * Indicates if the application has permission to write setting to the beacon.
336
+ */
337
+ @property (readonly, nonatomic) SBKBeaconWritePermissionStatus writePermissionStatus;
338
+
339
+ /**
340
+ * You should use this method to request write permission if writePermissionStatus property is restricted.
341
+ *
342
+ * @param password Password string.
343
+ * @param completion The block to execute after the operation is completed. If error parameter is nil means success.
344
+ *
345
+ * @see writePermissionStatus
346
+ *
347
+ * @return Can this operation be executed.
348
+ */
349
+ - (BOOL)requireWritePermissionWithPassword:(NSString *)password completion:(SBKBeaconCompletionBlock)completion;
350
+
351
+ /**
352
+ * Changes the beacon's password.
353
+ *
354
+ * @param password New password string.
355
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
356
+ *
357
+ * @return Can this writing operation be executed.
358
+ */
359
+ - (BOOL)updateWritePassword:(NSString *)password completion:(SBKBeaconCompletionBlock)completion;
360
+
361
+ /**
362
+ * Clear the beacon's password.
363
+ *
364
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means clear successfully.
365
+ *
366
+ * @return Can this clear operation be executed.
367
+ */
368
+ - (BOOL)clearWritePasswordWithCompletion:(SBKBeaconCompletionBlock)completion;
369
+
370
+ /**
371
+ * @return Which energy saving mode the beacon supports.
372
+ */
373
+ - (SBKBeaconEnergySavingMode)availableEnergySavingMode;
374
+
375
+ /**---------------------------------------------------------------------------------------
376
+ * @name Temperature, Light and Accelerometer Sensor
377
+ * ---------------------------------------------------------------------------------------
378
+ */
379
+
380
+ /**
381
+ * Causes beacon to reload temperature and light sensors data immediately.
382
+ *
383
+ * @param completion The block to execute after the operation is completed. If error parameter is nil means success.
384
+ *
385
+ * @return Can this operation be executed.
386
+ */
387
+ - (BOOL)reloadSensorDataWithCompletion:(SBKBeaconCompletionBlock)completion;
388
+
389
+ /**
390
+ * @return Flag indicating whether temperature sensor is available.
391
+ */
392
+ - (BOOL)isTemperatureSensorAvailable;
393
+
394
+ /**
395
+ * @return Flag indicating whether light sensor is available.
396
+ */
397
+ - (BOOL)isLightSensorAvailable;
398
+
399
+ /**
400
+ * @return Flag indicating whether accelerometer sensor is available.
401
+ */
402
+ - (BOOL)isAccelerometerAvailable;
403
+
404
+ /**
405
+ * @return Flag indicating whether this beacon has beacon information, uuid, major, minor, proximity, accuracy etc..
406
+ */
407
+ - (BOOL)isBeacon;
408
+
409
+ /**
410
+ * @return Flag indicating whether this beacon has sensor information, temprature, light, accelerometer etc..
411
+ */
412
+ - (BOOL)isSensor;
413
+
414
+ /**
415
+ * Temperature value in Celsius
416
+ *
417
+ * @discussion Sensor data can only be updated when the app is running in the foreground.
418
+ */
419
+ @property (readonly, nonatomic, copy) NSNumber * temperature;
420
+
421
+ /**
422
+ * The ambient light level in lux.
423
+ *
424
+ * @discussion Sensor data can only be updated when the app is running in the foreground.
425
+ */
426
+ @property (readonly, nonatomic, copy) NSNumber * light;
427
+
428
+ /**
429
+ *
430
+ * The broadcast transmit power.
431
+ *
432
+ * @see SBKBeaconTransmitPower.
433
+ */
434
+ @property (nonatomic, readonly) NSNumber * broadcastTransmitPower;
435
+
436
+ /**
437
+ *
438
+ * The broadcast transmit interval.
439
+ *
440
+ */
441
+ @property (nonatomic, readonly) NSNumber * broadcastInterval;
442
+
443
+ /**
444
+ *
445
+ * The flag whether beacon is in energy saving mode.
446
+ *
447
+ */
448
+ @property (nonatomic, readonly) NSNumber * inEnergySaving;
449
+
450
+ /**
451
+ *
452
+ * The flag whether device is broadcasting ali beacon info.
453
+ *
454
+ */
455
+ @property (nonatomic, readonly) NSNumber * aliBeacon;
456
+
457
+ /**
458
+ *
459
+ * The flag whether beacon is in enhance broadcast mode.
460
+ *
461
+ */
462
+ @property (nonatomic, readonly) NSNumber * enhanceBroadcast;
463
+
464
+ /**
465
+ *
466
+ * The flag whether beacon is in eddystone broadcast mode.
467
+ *
468
+ */
469
+ @property (nonatomic, readonly) NSNumber * eddystoneEnabled;
470
+
471
+ /**
472
+ * The number of accelerometer count.
473
+ *
474
+ * @discussion Sensor data can only be updated when the app is running in the foreground.
475
+ */
476
+ @property (readonly, nonatomic, copy) NSNumber * accelerometerCount;
477
+
478
+ /**
479
+ * Flag indicating accelerometer state, boolean value wrapped in NSNumber.
480
+ *
481
+ * @discussion Sensor data can only be updated when the app is running in the foreground.
482
+ */
483
+ @property (readonly, nonatomic, copy, getter = isMoving) NSNumber * moving;
484
+
485
+ /**
486
+ * Flag indicating switch state to shake to light on.
487
+ *
488
+ * @discussion To shake to litght on is that you can use to ensure the device is working.
489
+ */
490
+ @property (readonly, nonatomic) NSNumber * shakeToLightOn;
491
+
492
+ /**
493
+ * Resets accelerometer counter value to zero.
494
+ *
495
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
496
+ *
497
+ * @return Can this operation be executed.
498
+ */
499
+ - (BOOL)resetAccelerometerCountWithCompletion:(SBKBeaconCompletionBlock)completion;
500
+
501
+ /**
502
+ * Write the state of switch to shake to light on.
503
+ *
504
+ * @param state YES: turn on this switch, NO: turn off this switch.
505
+ *
506
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
507
+ *
508
+ * @return Can this operation be executed.
509
+ */
510
+ - (BOOL)writeShakeToLightOnState: (BOOL) state completion:(SBKBeaconCompletionBlock)completion;
511
+
512
+ /**---------------------------------------------------------------------------------------
513
+ * @name Bridge to Core Bluetooth
514
+ * ---------------------------------------------------------------------------------------
515
+ */
516
+
517
+ /**
518
+ * The CBPeripheral object assign to this beacon.this object may be changed continuously.
519
+ */
520
+ @property (readonly, nonatomic, strong) CBPeripheral * assignedPeripheral;
521
+
522
+ /**---------------------------------------------------------------------------------------
523
+ * @name Eddystone.
524
+ * ---------------------------------------------------------------------------------------
525
+ */
526
+
527
+ /**
528
+ *
529
+ * The flag whether UID packet of eddystone is broadcasted.
530
+ *
531
+ */
532
+ @property (readonly, nonatomic) NSNumber * eddystoneUIDEnabled;
533
+
534
+ /**
535
+ *
536
+ * The flag whether URL packet of eddystone is broadcasted.
537
+ *
538
+ */
539
+ @property (readonly, nonatomic) NSNumber * eddystoneURLEnabled;
540
+
541
+ /**
542
+ *
543
+ * The flag whether TLM packet of eddystone is broadcasted.
544
+ *
545
+ */
546
+ @property (readonly, nonatomic) NSNumber * eddystoneTLMEnabled;
547
+
548
+ /**
549
+ *
550
+ * The NID of UID packet of eddystone.
551
+ *
552
+ */
553
+ @property (readonly, nonatomic) NSData * eddystoneNID;
554
+
555
+ /**
556
+ *
557
+ * The BID of UID packet of eddystone.
558
+ *
559
+ */
560
+ @property (readonly, nonatomic) NSData * eddystoneBID;
561
+
562
+ /**
563
+ *
564
+ * The interval of TLM packet of eddystone.
565
+ *
566
+ */
567
+ @property (readonly, nonatomic) NSNumber * eddystoneTLMInterval;
568
+
569
+ /**
570
+ *
571
+ * The URL of URL packet of eddystone.
572
+ *
573
+ */
574
+ @property (readonly, nonatomic) NSString * eddystoneUrl;
575
+
576
+ /**
577
+ *
578
+ * The battery voltage of TLM packet of eddystone.
579
+ *
580
+ */
581
+ @property (readonly, nonatomic) NSNumber * eddystoneBatteryVoltage;
582
+
583
+ /**
584
+ *
585
+ * The PDU count of TLM packet of eddystone.
586
+ *
587
+ */
588
+ @property (readonly, nonatomic) NSNumber * eddystonePduCount;
589
+
590
+ /**
591
+ *
592
+ * The wored time since reboot or power on of TLM packet of eddystone.
593
+ *
594
+ */
595
+ @property (readonly, nonatomic) NSNumber * eddystoneWorkedTime;
596
+
597
+ /**
598
+ * Write a url to eddystone.
599
+ *
600
+ * @param url The url that eddystone broadcast with url frame;
601
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
602
+ *
603
+ * @return Can this writing operation be executed.
604
+ */
605
+ - (BOOL)writeEddystoneUrl:(NSString*) url completion:(SBKBeaconCompletionBlock)completion;
606
+
607
+ /**
608
+ * enable some package of eddystone.
609
+ *
610
+ * @param package which package will enbaled or disabled;
611
+ *
612
+ * @param enable package is enbaled or disabled. YES : enable, NO : disable;
613
+ *
614
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
615
+ *
616
+ * @return Can this writing operation be executed.
617
+ */
618
+ - (BOOL)eddystonePackage: (EddystonePackageType) package enable: (BOOL) enable completion:(SBKBeaconCompletionBlock)completion;
619
+
620
+ /**
621
+ * write eddystone interval of TLM package.
622
+ *
623
+ * @param interval broadcast on this interval;
624
+ *
625
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
626
+ *
627
+ * @return Can this writing operation be executed.
628
+ */
629
+ - (BOOL)writeEddystoneTLMInterval: (EddystoneTLMInterval) interval completion:(SBKBeaconCompletionBlock)completion;
630
+
631
+ /**
632
+ * write eddystone nid of UID package.
633
+ *
634
+ * @param nidString nid presented by hex string;
635
+ *
636
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
637
+ *
638
+ * @return Can this writing operation be executed.
639
+ */
640
+ - (BOOL)writeEddystoneNID: (NSString*) nidString completion:(SBKBeaconCompletionBlock)completion;
641
+
642
+ /**
643
+ * write eddystone bid of UID package.
644
+ *
645
+ * @param bidString bid presented by hex string;
646
+ *
647
+ * @param completion The block to execute after the writing is completed. If error parameter is nil means writing successfully.
648
+ *
649
+ * @return Can this writing operation be executed.
650
+ */
651
+ - (BOOL)writeEddystoneBID: (NSString*) bidString completion:(SBKBeaconCompletionBlock)completion;
652
+
653
+ @end
654
+
655
+ /**
656
+ * The delegate of a SBKBeacon object must adopt the SBKBeaconDelegate protocol. The delegate uses this protocol’s methods to monitor the connection state and sensor date changing of a beacon. There are no required methods in this protocol.
657
+ */
658
+ @protocol SBKBeaconDelegate <NSObject>
659
+
660
+ @optional
661
+
662
+ /**
663
+ * Invoked when a connection is successfully created with a beacon.
664
+ *
665
+ * @param beacon The beacon that has been connected.
666
+ */
667
+ - (void)sensoroBeaconDidConnect:(SBKBeacon *)beacon;
668
+
669
+ /**
670
+ * Invoked when a connection required a password. if you receive this method, you must call
671
+ * requireWritePermissionWithPassword to get permission.
672
+ *
673
+ * @param beacon The beacon that has been connected.
674
+ */
675
+ - (void)sensoroBeaconRequirePassword:(SBKBeacon *)beacon;
676
+
677
+ /**
678
+ * Invoked when an existing connection with a beacon is torn down
679
+ *
680
+ * @param beacon The beacon that has been disconnected.
681
+ * @param error If an error occurred, the cause of the failure.
682
+ */
683
+ - (void)sensoroBeaconDidDisconnect:(SBKBeacon *)beacon error:(NSError *)error;
684
+
685
+ /**
686
+ * Invoked when a beacon's sensor settings changes.
687
+ *
688
+ * @param beacon The beacon providing this information.
689
+ * @param settings The new sensor setting.
690
+ */
691
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateSensorSetting:(NSDictionary*)settings;
692
+
693
+ /**
694
+ * Invoked when a beacon's RSSI changes.
695
+ *
696
+ * @param beacon The beacon providing this information.
697
+ * @param rssi The new rssi value.
698
+ */
699
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateRSSI:(NSInteger)rssi;;
700
+
701
+ /**
702
+ * Invoked when a beacon's temperature data changes.
703
+ *
704
+ * @param beacon The beacon providing this information.
705
+ * @param temperature New temperature value wrapped in NSNumber.
706
+ */
707
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateTemperatureData:(NSNumber *)temperature;
708
+
709
+ /**
710
+ * Invoked when a beacon's light lux changes.
711
+ *
712
+ * @param beacon The beacon providing this information.
713
+ * @param light New ambient light level in lux.
714
+ */
715
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateLightData:(NSNumber *)light;
716
+
717
+ /**
718
+ * Invoked when a beacon's accelerometer count changes.
719
+ *
720
+ * @param beacon The beacon providing this information.
721
+ * @param accelerometerCount New accelerometer count value.
722
+ */
723
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateAccelerometerCount:(NSNumber *)accelerometerCount;
724
+
725
+ /**
726
+ * Invoked when a beacon's moving state changes.
727
+ *
728
+ * @param beacon The beacon providing this information.
729
+ * @param isMoving New moving state.
730
+ */
731
+ - (void)sensoroBeacon:(SBKBeacon *)beacon didUpdateMovingState:(NSNumber *)isMoving;
732
+
733
+ @end
734
+
735
+ /// Constants
736
+
737
+ /**
738
+ * the Key for the Transmit Power in base setting dictionary.
739
+ */
740
+ extern NSString * const SBKBeaconBaseSettingsTransmitPowerKey;
741
+ /**
742
+ * the Key for the Advertising Interval in base setting dictionary.
743
+ */
744
+ extern NSString * const SBKBeaconBaseSettingsAdvertisingIntervalKey;
745
+ /**
746
+ * the Key for the Energy Saving Mode in base setting dictionary.
747
+ */
748
+ extern NSString * const SBKBeaconBaseSettingsEnergySavingModeKey;
749
+ /**
750
+ * the Key for the Measure Power in base setting dictionary.
751
+ */
752
+ extern NSString * const SBKBeaconBaseSettingsMeasuredPowerKey;
753
+
754
+ /**
755
+ * the Key for the Temperature Sampling Interval in sensoro setting dictionary.
756
+ */
757
+ extern NSString * const SBKBeaconSensorSettingsTemperatureSamplingIntervalKey;
758
+ /**
759
+ * the Key for the Light Sampling Interval in sensoro setting dictionary.
760
+ */
761
+ extern NSString * const SBKBeaconSensorSettingsLightSamplingIntervalKey;
762
+ /**
763
+ * the Key for the Accelerometer Sensitivity in sensoro setting dictionary.
764
+ */
765
+ extern NSString * const SBKBeaconSensorSettingsAccelerometerSensitivityKey;