iosobjective-cibeaconmesh-network

uBudu Mesh Networking receiving messages


Does anybody know how to receive messages through uBudu Mesh Network?

I'm working on an app using uBudu beacons and the general idea is to allow users to send messages to each other through these beacons. I've successfully hooked up iOS-Mesh-SDK as described here: https://github.com/Ubudu/IOS-Mesh-SDK.

There is an example of how to send mesh message to another beacon and it works perfectly, but as for retrieving these messages from beacon to user app I have no idea.

There are methods in MeshBeacon class:

- (void)abortMeshMessage;
- (void)clearMeshMessageQueue;

- (void)setMeshNotification:(BOOL)enable withCompletionBlock:(UMeshBeaconSuccessBlock)completionBlock;

but nothing about retrieving the message.

Any suggestions are highly appreciated!


Solution

  • I found maybe brute, but working solution for this problem.

    First we need to set ourselves as delegate of BeaconManager

    UBUMeshBeaconManager.sharedInstance().delegate = self
    

    In implementation of delegate method, connect to closest beacon and reset its peripheral delegate to self.

    func meshManager(meshManager: UBUMeshBeaconManager!, didUpdateVisibleAndConnectableNodes meshNodes: [AnyObject]!) {
        UBUMeshBeaconManager.sharedInstance().connectToClosestBeacon({ (meshManager, meshBeacon, userInfo) -> Void in
                meshBeacon.peripheral.delegate = self
            }, progressBlock: { (meshManager, userInfo) -> Void in
    
            }, failedBlock: { (meshManager, meshBeacon, userInfo, error) -> Void in
    
            })
    }
    

    And waiting for characteristics updates in Peripheral Delegate method. All services and characteristics will be set behind the scene by UbuduSDK.

    func peripheral(peripheral: CBPeripheral!,
                    didUpdateValueForCharacteristic characteristic: CBCharacteristic!,
                    error: NSError!) {
        var string = NSString(data: characteristic.value, encoding: NSASCIIStringEncoding)
        println(string)
    }