Skip to content

Instantly share code, notes, and snippets.

@don
Last active August 29, 2015 14:18
Show Gist options
  • Save don/029f5694fbf374db1502 to your computer and use it in GitHub Desktop.
Save don/029f5694fbf374db1502 to your computer and use it in GitHub Desktop.
Code for ETE 2015 presentation
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
NSUUID *uuid = [[NSUUID alloc]
initWithUUIDString:@"01122334-4556-6778-899A-ABBCCDDEEFF0"];
CLBeaconRegion *region = [[CLBeaconRegion alloc]
initWithProximityUUID:uuid identifier:@"iBeacon"];
region.notifyOnEntry = TRUE;
region.notifyOnExit = TRUE;
region.notifyEntryStateOnDisplay = TRUE;
[locationManager requestAlwaysAuthorization];
[locationManager startMonitoringForRegion:region];
- (void)locationManager:(CLLocationManager *)manager
didDetermineState:(CLRegionState)state
forRegion:(CLRegion *)region
{
if(state == CLRegionStateInside)
{
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
[locationManager startRangingBeaconsInRegion:beaconRegion];
}
else if(state == CLRegionStateOutside)
{
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
[locationManager stopRangingBeaconsInRegion:beaconRegion];
}
}
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
CLBeacon *beacon = [beacons firstObject];
switch (beacon.proximity) {
case CLProximityImmediate:
[[self rangeLabel] setText:@"Immediate"];
break;
case CLProximityNear:
[[self rangeLabel] setText:@"Near"];
break;
case CLProximityFar:
[[self rangeLabel] setText:@"Far"];
break;
case CLProximityUnknown:
[[self rangeLabel] setText:@"Unknown"];
break;
default:
[[self rangeLabel] setText:@"Error"];
}
}
onButtonData: function(data) {
var message;
var a = new Uint8Array(data);
switch(a[0]) {
case 0:
message = "No buttons are pressed";
break;
case 1:
message = "Right button is pressed";
break;
case 2:
message = "Left button is pressed";
break;
case 3:
message = "Both buttons are pressed";
break;
default:
message = "Error";
}
buttonState.innerHTML = message;
},
{
"name": "Robosmart",
"id": "78:C5:E5:9A:15:AA",
"advertising": {},
"rssi": -65,
"services": [
"1800", "1801", "180a",
"f000ffc0-0451-4000-b000-000000000000",
"ff10", "ff20", "ff40"
],
"characteristics": [
{
"service": "ff10",
"characteristic": "ff11",
"properties": [
"Read", "Write"
]
},
{
"service": "ff10",
"characteristic": "ff12",
"properties": [
"Read", "Write"
]
},
{
"service": "ff10",
"characteristic": "ff16",
"properties": [
"Read"
]
}
]
}
00 // http://www.
70 // p
68 // h
69 // i
6c // l
6c // l
79 // y
65 // e
64 // t
65 // e
00 // .com/
72 // r
2f // /
61 // a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment