OBDII data transferring for react-native Android.
npm install react-native-obd2-core
$ npm install react-native-obd2-core --save
$ react-native link
``
APIs
ready()
This method will check a bluetooth status and prepare to use it.
``
const obd2 = require('react-native-obd2-core');
...
obd2.ready();
``
getBluetoothDeviceNameList
This method brings available bluetooth device information including name and address. The result is array type of maps which consist of "name" and "address".
$3
``
const obd2 = require('react-native-obd2-core');
...
obd2.getBluetoothDeviceNameList()
.then((nameList) => console.log('Bluetooth device list : ' + JSON.stringify(nameList)))
.catch((e) => console.log('Get device name error : ' + e)));
``
$3
``
Bluetooth device list: [{name: "OBD-II", address: "10 F0 8B 3F 91"}]
``
setMockUpMode(enabled)
react-native-obd2-core provides mock up mode so that you can simply check your apps without connecting real bluetooth device as android-obd-reader did. Default value is 'false'. Therefore, react-native-obd2-core will work in real mode if you do not use this method.
startLiveData(btDeviceAddress)
Do work! do!
The data is flow to your listeners. Therfore you have to set your listenr named 'obd2LiveData'.
$3
``
const obd2 = require('react-native-obd2-core');
...
componentDidMount() {
this.obdLiveDataListener = DeviceEventEmitter.addListener('obd2LiveData', this.obdLiveData);
obd2.startLiveData('10 F0 8B 3F 91');
}
componentWillUnmount() {
this.obdStatusListener.remove();
}
``
stopLiveData()
Hey stop it!
Listeners
$3
for getting bluetooth device status.
JSON key | Type | Description
---------|------|----------------
status |String|'connected' or 'disconnected' or 'error' or 'disable' or 'ready' or 'connecting'
$3
for getting OBD-II device status
JSON key | Type | Description
---------|------|----------------
status |String|'disconnected' or 'receiving' or OBD data result
$3
for getting OBD-II data. Data structure is a dictionary as below.
``
{
'cmdID' : String,
'cmdName' : String,
'cmdResult' : String
}
```