I was trying to create my own iOS app for a school project based on the output that you already send with the OBD-II adapter through SerialBLE.
I am able to retreive information, but haven't been able to make a sense of it. This has taken me the whole day to get to this point, I believe I am pretty close, but would love it if you could help me out a bit.
As far as I understand, you use a struct as the following on your OBD Arduino header.
You cast the information as a (uint8_t*) and send either 12 or 20 based off if you use the float array or just one value.
The code below works perfectly, but I keep on receiving some random values.
Me and my team would greatly appreciate it if you could point us in the right direction.
And keep up the good work!
Been loving this OBD-II adapter, might get myself one for my own purposes after this senior design project!
Code: Select all
struct BLE_DATA{
uint32_t time;
uint16_t pid;
uint8_t flags;
uint8_t checksum;
float value[3];
};
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
for(CBCharacteristic *characteristic in service.characteristics)
{
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
[self.OBDAdapter readValueForCharacteristic:characteristic];
}
}
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
struct BLE_DATA myData;
[characteristic.value getBytes:&myData length:sizeof(myData)];
NSLog(@"time: %x - pid: %x",myData.time,myData.pid);
NSLog(@"val[0]: %f - val[1]: %f - val[2]: %f",myData.value[0],myData.value[1],myData.value[2]);
if(error)
{
NSLog(@"Received Error: ",error);
}
}