This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Nordik UART app with Multiple service reception

I need to receive both UART Service data and HRS service data on the app.

Currently I have seen on Nordik Connect app , both the services can be found and can connect and receive data.

I need to do same with my app using nordik UART App code.

I have changed UART profile to HRS profile and code was working, i was receiving Nordik HRS service data.

But i want both services should be used and receives data. so i have prepare separate UARTService_HRS for hrs profile in the same code.also added needed changed.but it gives error null pointer exception on BLEGattService.

Please help

  • but with same features it giving problem to iOS UART App. when both receiver characteristics notification is on, then transmission is very slow sometimes takes 2 seconds sometimes 10 seconds. doesn't understand how to handle this with ios

  • Adding delay isn't a very good solution. You can try: after you write to one service, you wait for the call back before you write to the second one.

  • but my current problem is when 2 characteristics from different services i have started notification on, my transmission on transmission characteristics goes on toss. can you help me understand how to get over it.

    I am developing App for iPhone UART service App.

    I have two services. Nordik UART Service and HRM service

    When I notify receiver characteristics of both services,my transmission characteristics taking delay of 2 to 10 seconds to transmit data.

    when i notify only single receiver characteristics, transmission works fine.but i start notify second receiver characteristics, transmission delayed.

    Please go through my below code for reception and transmission. How do i manage multiple services with multiple characteristics, i could not allow to have transmission delay.

    //Service Discovery Code:

    + (CBUUID *) uartServiceUUID
    {
        return [CBUUID UUIDWithString:@"6e400001-b5a3-f393-e0a9-e50e24dcca9e"];
    }
    + (CBUUID *) txCharacteristicUUID
    {
        return [CBUUID UUIDWithString:@"6e400002-b5a3-f393-e0a9-e50e24dcca9e"];
    }
    + (CBUUID *) rxCharacteristicUUID
    {
        return [CBUUID UUIDWithString:@"6e400003-b5a3-f393-e0a9-e50e24dcca9e"];
    }
    + (CBUUID *) torqueInformationServiceUUID
    {
        return [CBUUID UUIDWithString:@"0000180D-0000-1000-8000-00805f9b34fb"];
    }
    + (CBUUID *) torquerxCharacteristicUUID
    {
        return [CBUUID UUIDWithString:@"00002A37-0000-1000-8000-00805f9b34fb"];
    }
    - (UARTPeripheral *) initWithPeripheral:(CBPeripheral*)peripheral delegate:(id<UARTPeripheralDelegate>) delegate
    {
        if (self = [super init])
        {
            _peripheral = peripheral;
            _peripheral.delegate = self;
            _delegate = delegate;
    //        myperipheral=peripheral;
        }
        return self;
    }
    - (void) didConnect
    {
    [_peripheral discoverServices:@[self.class.uartServiceUUID,self.class.torqueInformationServiceUUID]];
        NSLog(@"Did start service discovery.");    
    }
    
    - (void) didTSConnect
    {
          NSLog(@" discovery start ,,,.........");  
    }
    - (void) peripheral:(CBPeripheral )peripheral didDiscoverServices:(NSError)error
    {
        if (error)
        {
            NSLog(@"Error discovering services: %@", error)        
            return;
        }
        for (CBService *service in peripheral.services)
        {
            NSLog(@"Discovered service: %@", service.UUID);
            [peripheral discoverCharacteristics:nil forService:service];
        } 
         NSLog(@"Discovered service: %@", tsservice.UUID);
      }
    - (void) peripheral:(CBPeripheral )peripheral didDiscoverCharacteristicsForService:(CBService )service error:(NSError *)error
    {
       if (error)
        {
            NSLog(@"Error discovering characteristics: %@", error);
            receptionStartFlag=false;
            return;  
        }
        for (CBCharacteristic *d in service.characteristics)
            {   
              if ([service.UUID isEqual:self.class.uartServiceUUID])
                {
                    if ([d.UUID isEqual:self.class.rxCharacteristicUUID])
                    {
                        NSLog(@"Found RX characteristic");
                        self.rxCharacteristic = d;                
                        rxChar=_rxCharacteristic;                
                        [self.peripheral setNotifyValue:YES forCharacteristic:d];
                        [self.peripheral readValueForCharacteristic:d];                
                    }
                    else   if ([d.UUID isEqual:self.class.txCharacteristicUUID])
                    {
                        NSLog(@"Found TX characteristic");
                        self.txCharacteristic = d;
                        txChar=_txCharacteristic;
                        [self.peripheral setNotifyValue:YES forCharacteristic:d];
                    }
                }   
            }
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0),                     ^{
        for (CBCharacteristic *d in service.characteristics)
          {
           if ([service.UUID isEqual:self.class.torqueInformationServiceUUID])
             {
                if ([d.UUID isEqual:self.class.torquerxCharacteristicUUID])
                   {
                       NSLog(@"Found  TSRX characteristic");
                       self.rxCharacteristic = d;
                       rxChar=rxCharacteristic;
                      [self.peripheral setNotifyValue:YES forCharacteristic:d];
                      [self.peripheral readValueForCharacteristic:d];
                   }
                                              
               }
             }
            });
        
    }
    
    - (void) peripheral:(CBPeripheral )peripheral didUpdateValueForCharacteristic:
    (CBCharacteristic )characteristic error:(NSError *)error
       {
        if (error)
          {
            NSLog(@"Error receiving notification for characteristic %@: %@", 
            characteristic, error);
            return;
          }
        
        //actual reception 
        NSData *dataRec=self.rxCharacteristic.value;
        
        Byte byteData[[dataRec length]];//(Byte*)malloc(len);
        
        [dataRec getBytes:&byteData];
    }
    
    //**Transmission Code**
    
    int8_t bytes2[] ={128,00,00,00,00,00,00,00,00,00,00,00,00};
                NSData *data2 = [NSData dataWithBytes:bytes2 length:sizeof(bytes2)];
                
                if ((txChar.properties & CBCharacteristicPropertyWrite) != 0)
                {
                    [myperipheral writeValue:data2 forCharacteristic:txChar
                                        type:CBCharacteristicWriteWithResponse];
                }
                else if ((txChar.properties & CBCharacteristicPropertyWrite) != 0)
                {
                    [myperipheral writeValue:data2 forCharacteristic:txChar 
                     type:CBCharacteristicWriteWithResponse];
                }
                else
                {
                    NSLog(@"No write property on TX characteristic, %lu.", (unsigned 
                    long)txChar.properties);
                }
    
  • If you don't have a sniffer trace, I can't help you on this case. You should also print a log in your peripheral. The log should print out when it receive the notification enabling (CCCD writing) and when it start sending each notification.

Related