Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ React-native OBD-II reader designed to connect with Bluetooth Elm327 OBD reader.
# How to install
Run below link on your project root folder.
````
$ npm install react-native-obd2 --save
$ npm install @furkanom/react-native-obd2 --save
$ react-native link
````

# For version compatibility
You can edit this block to your own project and put it at the bottom of the **android/build.gradle**
````
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
````

# APIs
## ready()
This method will check a bluetooth status and prepare to use it.
````
const obd2 = require('react-native-obd2');
const obd2 = require('@furkanom/react-native-obd2');
...
obd2.ready();
````
Expand All @@ -21,7 +36,7 @@ obd2.ready();
This method brings available bluetooth device information including name and address. The result is array type of maps which consist of "name" and "address".
### Example
````
const obd2 = require('react-native-obd2');
const obd2 = require('@furkanom/react-native-obd2');
...
obd2.getBluetoothDeviceNameList()
.then((nameList) => console.log('Bluetooth device list : ' + JSON.stringify(nameList)))
Expand All @@ -42,7 +57,7 @@ The data is flow to your listeners. Therfore you have to set your listenr named

### Example
````
const obd2 = require('react-native-obd2');
const obd2 = require('@furkanom/react-native-obd2');
...
componentDidMount() {
this.obdLiveDataListener = DeviceEventEmitter.addListener('obd2LiveData', this.obdLiveData);
Expand All @@ -58,7 +73,7 @@ const obd2 = require('react-native-obd2');
Hey stop it!

## Listeners
### 'obd2bluetoothStatus'
### 'obd2bluetoothStatus'
for getting bluetooth device status.

JSON key | Type | Description
Expand Down
36 changes: 24 additions & 12 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion safeExtGet('compileSdkVersion', 26)
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
}
lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.github.pires:obd-java-api:1.0'
compile "com.facebook.react:react-native:+"
implementation 'com.facebook.react:react-native:+'
implementation "com.github.pires:obd-java-api:1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,22 @@ public static ArrayList<ObdCommand> getCommands() {

// Control
cmds.add(new ModuleVoltageCommand());
cmds.add(new EquivalentRatioCommand());
cmds.add(new DistanceMILOnCommand());
cmds.add(new DtcNumberCommand());
cmds.add(new TimingAdvanceCommand());
cmds.add(new TroubleCodesCommand());
cmds.add(new VinCommand());

// Engine
cmds.add(new LoadCommand());
cmds.add(new RPMCommand());
cmds.add(new RuntimeCommand());
cmds.add(new MassAirFlowCommand());
cmds.add(new ThrottlePositionCommand());
cmds.add(new RelativeAcceleratorPedalPositionCommand());

// Fuel
cmds.add(new FindFuelTypeCommand());
cmds.add(new ConsumptionRateCommand());
// cmds.add(new AverageFuelEconomyObdCommand());
//cmds.add(new FuelEconomyCommand());
cmds.add(new FuelLevelCommand());
// cmds.add(new FuelEconomyMAPObdCommand());
// cmds.add(new FuelEconomyCommandedMAPObdCommand());
cmds.add(new FuelTrimCommand(FuelTrim.LONG_TERM_BANK_1));
cmds.add(new FuelTrimCommand(FuelTrim.LONG_TERM_BANK_2));
cmds.add(new FuelTrimCommand(FuelTrim.SHORT_TERM_BANK_1));
cmds.add(new FuelTrimCommand(FuelTrim.SHORT_TERM_BANK_2));
cmds.add(new AirFuelRatioCommand());
cmds.add(new WidebandAirFuelRatioCommand());
cmds.add(new OilTempCommand());

// Pressure
cmds.add(new BarometricPressureCommand());
cmds.add(new FuelPressureCommand());
cmds.add(new FuelRailPressureCommand());
cmds.add(new IntakeManifoldPressureCommand());

// Temperature
cmds.add(new AirIntakeTemperatureCommand());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.github.pires.obd.reader.config;

import com.github.pires.obd.commands.PercentageObdCommand;
import com.github.pires.obd.enums.AvailableCommandNames;

/**
* Read the throttle position in percentage.
*
*/
public class RelativeAcceleratorPedalPositionCommand extends PercentageObdCommand {

/**
* Default ctor.
*/
public RelativeAcceleratorPedalPositionCommand() {
super("01 5A");
}

public RelativeAcceleratorPedalPositionCommand(RelativeAcceleratorPedalPositionCommand other) {
super(other);
}

/** {@inheritDoc} */
@Override
public String getName() {
return AvailableCommandNames.REL_THROTTLE_POS.getValue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
import com.github.pires.obd.commands.protocol.HeadersOffCommand;
import com.github.pires.obd.commands.protocol.EchoOffCommand;
import com.github.pires.obd.commands.protocol.LineFeedOffCommand;
import com.github.pires.obd.commands.protocol.ObdResetCommand;
Expand Down Expand Up @@ -121,10 +122,10 @@ private void startObdConnection() throws IOException {
// Let's configure the connection.
Log.d(TAG, "Queueing jobs for connection configuration..");
queueJob(new ObdCommandJob(new ObdResetCommand()));

//Below is to give the adapter enough time to reset before sending the commands, otherwise the first startup commands could be ignored.
try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); }

queueJob(new ObdCommandJob(new HeadersOffCommand()));
queueJob(new ObdCommandJob(new EchoOffCommand()));

/*
Expand All @@ -133,9 +134,10 @@ private void startObdConnection() throws IOException {
* TODO this can be done w/o having to queue jobs by just issuing
* command.run(), command.getResult() and validate the result.
*/
queueJob(new ObdCommandJob(new HeadersOffCommand()));
queueJob(new ObdCommandJob(new EchoOffCommand()));
queueJob(new ObdCommandJob(new LineFeedOffCommand()));
queueJob(new ObdCommandJob(new TimeoutCommand(62)));


// Get protocol from preferences
// final String protocol = prefs.getString(ConfigActivity.PROTOCOLS_LIST_KEY, "AUTO");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {
queueCommands();
}
// run again in period defined in preferences
new Handler().postDelayed(mQueueCommands, 1000);
new Handler().postDelayed(mQueueCommands, 400);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
return modules;
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
List<ViewManager> result = new ArrayList<ViewManager>();
Expand Down
23 changes: 11 additions & 12 deletions example/src/components/OBDReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import SharedPreference from 'react-native-sp';

import AppEventEmitter from '../services/AppEventEmitter';

const obd2 = require('react-native-obd2');
const obd2 = require('@furkanom/react-native-obd2');
const SensorManager = require('NativeModules').SensorManager;

const Color = require('../utils/Color');
Expand All @@ -54,7 +54,7 @@ export default class OBDReader extends Component {
btSelectedDeviceAddress: '',
obdStatus: 'disconnected',
debug : '-',
obd2Data : { }
obd2Data : { }
};

this.sensorOrientation = this.sensorOrientation.bind(this);
Expand Down Expand Up @@ -164,7 +164,7 @@ export default class OBDReader extends Component {
this.setState({
isStartLiveData: true,
});

SensorManager.startOrientation(1000);
this.listenerOrientation = DeviceEventEmitter.addListener('Orientation', this.sensorOrientation);
obd2.setMockUpMode(isMockUpMode);
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class OBDReader extends Component {
.then((nameList) => {
console.log('Bluetooth device list : ' + JSON.stringify(nameList));
this.setState({btDeviceList : nameList});

})
.catch((e) => {
console.log('Get device name error : ' + e)
Expand All @@ -219,7 +219,7 @@ export default class OBDReader extends Component {

runMenu(value) {
switch(value) {
case 1 :
case 1 :
this.startLiveData();
break;
case 2 :
Expand All @@ -243,7 +243,7 @@ export default class OBDReader extends Component {

return (
<MenuContext style={{flex: 1}}>
<View style={{flex: 1}}>
<View style={{flex: 1}}>
<NavigationBar
style={{flex: 0.1, backgroundColor: Color.BG_NAVIBAR}}
tintColor={Color.WHITE}
Expand All @@ -252,10 +252,10 @@ export default class OBDReader extends Component {
<Menu onSelect={this.runMenu.bind(this)}>
<MenuTrigger>
<Text style={{
marginRight: 10,
padding: 10,
alignSelf: 'center',
fontSize: 20,
marginRight: 10,
padding: 10,
alignSelf: 'center',
fontSize: 20,
color: Color.WHITE}}>&#8942;</Text>
</MenuTrigger>
<MenuOptions>
Expand Down Expand Up @@ -287,7 +287,7 @@ export default class OBDReader extends Component {
<ScrollView>
{
cmdData.map((item, index) => (
<View
<View
style={{flexDirection:'row', alignItems: 'center'}}
key={index}
>
Expand Down Expand Up @@ -330,4 +330,3 @@ const styles = StyleSheet.create({
color: Color.BLACK
}
});

7 changes: 3 additions & 4 deletions example/src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Category from './widget/PreferenceCategory';
import CheckBoxPreference from './widget/CheckBoxPreference';
import ListPreference from './widget/ListPreference';

const obd2 = require('react-native-obd2');
const obd2 = require('@furkanom/react-native-obd2');
const Color = require('../utils/Color');
const Constant = require('../utils/Constant');

Expand Down Expand Up @@ -76,7 +76,7 @@ export default class Settings extends Component {

render() {
return(
<View>
<View>
<NavigationBar
style={{flex: 0.1, backgroundColor: Color.BG_NAVIBAR}}
tintColor={Color.WHITE}
Expand All @@ -97,7 +97,7 @@ export default class Settings extends Component {
dialogTitle='Bluetooth device list'
items={this.state.btDeviceListForUI}
selectedIndex={this.state.selectedBTDeviceIndex}
onSelected={(index) =>
onSelected={(index) =>
{
this.setState({
selectedBTDeviceIndex : index
Expand All @@ -123,4 +123,3 @@ const styles = StyleSheet.create({
borderColor: Color.SETTING_BORDER_COLOR
},
});

20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "react-native-obd2",
"version": "0.0.2",
"name": "@furkanom/react-native-obd2",
"version": "0.0.5",
"description": "OBDII data transferring for react-native Android.",
"license": "MIT",
"author": "JetBridge, LLC.",
"author": "FurkanOM",
"main": "index.js",
"keywords": [
"react-native",
Expand All @@ -13,10 +13,18 @@
],
"repository": {
"type": "git",
"url": "https://github.com/jetbridge-io/react-native-obd2"
"url": "git+https://github.com/furkanom/react-native-obd2.git"
},
"dependencies": {
"dependencies": {},
"devDependencies": {},
"bugs": {
"url": "https://github.com/furkanom/react-native-obd2/issues"
},
"devDependencies": {
"homepage": "https://github.com/furkanom/react-native-obd2#readme",
"directories": {
"example": "example"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}