iOS: Writing to Bluetooth LE device with NSTimer -


i'm trying write char bluetooth le device, , far has worked, when inside diddiscovercharacteristicsforservice method.

- (void)peripheral:(cbperipheral *)peripheral diddiscovercharacteristicsforservice:(cbservice *)service error:(nserror *)error {     if (error) {         [self cleanup];         return;     }      (cbcharacteristic *characteristic in service.characteristics) {         if ([characteristic.uuid isequal: char_uuid]) {             nslog(@"discovered characteristic: %@", characteristic);             [peripheral setnotifyvalue:yes forcharacteristic:characteristic];             _discoveredcharacteristic = characteristic;              char c;             count++;             if (count%2 == 1)             {                 c = 0x0;             }             else             {                 c = 0x7;             }              nsdata *data = [nsdata datawithbytes: &c length: 1];             [_discoveredperipheral writevalue:data forcharacteristic:_discoveredcharacteristic                                          type:cbcharacteristicwritewithresponse];              nslog(@"writing value %@ characteristic %@", data, _discoveredcharacteristic.uuid);         }     }  timer = [nstimer scheduledtimerwithtimeinterval:2                                                  target:self selector:@selector(targetmethod:)                                                userinfo:nil repeats:yes];         _repeatingtimer = timer;     } 

but when move writevalue part method triggered timer, no longer writes value device. why this? doing wrong?

- (void)targetmethod:(nstimer*)thetimer{     char c;     count++;     if (count%2 == 1)     {         c = 0x0;     }     else     {         c = 0x7;     }      nsdata *data = [nsdata datawithbytes: &c length: 1];     [_discoveredperipheral writevalue:data forcharacteristic:_discoveredcharacteristic                                  type:cbcharacteristicwritewithresponse];      nslog(@"writing value %@ characteristic %@", data, _discoveredcharacteristic.uuid); } 

i new both ios , bluetooth.

i being dumb, , closing connection peripheral after writing.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -