Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mac OSX discover leaky_broadcast
//
// AppDelegate.m
// leakyFaucetDesktop
//
// Created by WozniBob on 12/22/14.
// Copyright (c) 2014 Bob_Burns. All rights reserved.
//
#import "AppDelegate.h"
#import <IOBluetooth/IOBluetooth.h>
#define BROADCAST_UUID @"0x0046"
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (nonatomic, strong) CBCentralManager *myCentralManager;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 120
target: self
selector: @selector(doScan:)
userInfo: nil
repeats: YES];
NSArray *services = @[[CBUUID UUIDWithString:BROADCAST_UUID]];
_myCentralManager = [[CBCentralManager alloc] initWithDelegate:(id)self queue:nil options:nil];
[_myCentralManager scanForPeripheralsWithServices:services options:nil];
}
- (void)doScan:(NSTimer *)t{
NSLog(@"scanning...");
NSArray *services = @[[CBUUID UUIDWithString:BROADCAST_UUID]];
[_myCentralManager scanForPeripheralsWithServices:services options:nil];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
}
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *) advertisementData
RSSI:(NSNumber *)RSSI
{
NSString *localName = [advertisementData objectForKey:
CBAdvertisementDataLocalNameKey];
if ([localName length] > 0) {
NSLog(@"Found the leak monitor: %@", localName); // found peripheral so stop scanning
[_myCentralManager stopScan];
}
NSDictionary *myADData = [advertisementData objectForKey:CBAdvertisementDataServiceDataKey];
CBUUID *myUID = [CBUUID UUIDWithString:BROADCAST_UUID];
NSData *data = [[NSData alloc] init];
data = [myADData objectForKey:myUID];
Byte bytes = 0x4c;
NSData *leakData = [NSData dataWithBytes:&bytes length:sizeof(bytes)];
NSLog(@"my data:%@", data);
if ([data isEqualToData:leakData]) {
NSLog(@"we got a leak!");
}
NSLog(@"range: %i",[RSSI unsignedIntValue]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.