├── .gitignore ├── LICENSE ├── README.md ├── scripts ├── create_torque_log_table.sql └── dbdump_to_csv.sh └── web ├── auth_app.php ├── auth_functions.php ├── auth_user.php ├── creds-sample.php ├── data └── torque_keys.csv ├── del_session.php ├── export.php ├── get_columns.php ├── get_sessions.php ├── merge_sessions.php ├── parse_functions.php ├── plot.php ├── session.php ├── static ├── css │ ├── background.png │ ├── bootstrap.css │ ├── bootstrap.min.css │ ├── chosen-sprite.png │ ├── chosen-sprite@2x.png │ ├── chosen.css │ ├── chosen.min.css │ └── torque.css └── js │ ├── bootstrap.min.js │ ├── chosen.jquery.min.js │ ├── excanvas.js │ ├── excanvas.min.js │ ├── jquery.colorhelpers.js │ ├── jquery.flot.animator.js │ ├── jquery.flot.animator.min.js │ ├── jquery.flot.axislabels.js │ ├── jquery.flot.canvas.js │ ├── jquery.flot.categories.js │ ├── jquery.flot.crosshair.js │ ├── jquery.flot.downsample.js │ ├── jquery.flot.errorbars.js │ ├── jquery.flot.fillbetween.js │ ├── jquery.flot.grow.js │ ├── jquery.flot.hiddengraphs.js │ ├── jquery.flot.image.js │ ├── jquery.flot.js │ ├── jquery.flot.multihighlight-delta.js │ ├── jquery.flot.navigate.js │ ├── jquery.flot.pie.js │ ├── jquery.flot.resize.js │ ├── jquery.flot.resize.min.js │ ├── jquery.flot.selection.js │ ├── jquery.flot.smoother.js │ ├── jquery.flot.stack.js │ ├── jquery.flot.symbol.js │ ├── jquery.flot.threshold.js │ ├── jquery.flot.time.js │ ├── jquery.flot.tooltip.js │ ├── jquery.flot.tooltip.min.js │ ├── jquery.flot.updater.js │ ├── jquery.flot.valuelabels.js │ ├── jquery.min.js │ ├── jquery.peity.min.js │ └── torquehelpers.js ├── timezone.php ├── upload_data.php └── url.php /.gitignore: -------------------------------------------------------------------------------- 1 | creds.php 2 | torque_data 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) {{{2014}}} {{{Matt Nicklay}}} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repo contains everything needed to setup an interface for uploading ODB2 data logged from your car in real-time using the [Torque Pro](https://play.google.com/store/apps/details?id=org.prowl.torque) app for Android. 2 | 3 | The interface allows the user to: 4 | 5 | * View a Google Map showing your trips logged via Torque 6 | * Create time series plots of OBD2 data 7 | * Easily export data to CSV or JSON 8 | 9 | # Demo # 10 | 11 | [Check out the demo!](http://data.mattnicklay.com/torque/session.php?id=1404557450999) 12 | 13 | # Requirements # 14 | 15 | These instructions assume you already have a LAMP-like server (on a Linux/UNIX based host) or have access to one. Specifically, you'll need the following: 16 | 17 | * MySQL database 18 | * Apache webserver 19 | * PHP server-side scripting 20 | 21 | If in doubt, I'd recommend using Ubuntu 12.04 LTS. 22 | 23 | # Server Setup # 24 | 25 | First clone the repo: 26 | 27 | ```bash 28 | git clone https://github.com/econpy/torque 29 | cd torque 30 | ``` 31 | 32 | ### Configure MySQL ### 33 | 34 | To get started, create a database named `torque` and a user with permission to insert and read data from the database. In this tutorial, we'll create a user `steve` with password `zissou` that has access to all tables in the database `torque` from `localhost`: 35 | 36 | ```sql 37 | CREATE DATABASE torque; 38 | CREATE USER 'steve'@'localhost' IDENTIFIED BY 'zissou'; 39 | GRANT USAGE, FILE TO 'steve'@'localhost'; 40 | GRANT ALL PRIVILEGES ON torque.* TO 'steve'@'localhost'; 41 | FLUSH PRIVILEGES; 42 | ``` 43 | 44 | Then create a table in the database to store the logged data using the `create_torque_log_table.sql` file provided in the `scripts` folder of this repo: 45 | 46 | ```bash 47 | mysql -u yoursqlusername -p < scripts/create_torque_log_table.sql 48 | ``` 49 | 50 | 51 | ### Configure Webserver ### 52 | 53 | Move the contents of the `web` folder to your webserver and set the appropriate permissions. For example, using an Apache server located at `/var/www`: 54 | 55 | ```bash 56 | mv web /var/www/torque 57 | cd /var/www/torque 58 | find . -type d -exec chmod 755 {} + 59 | find . -type f -exec chmod 644 {} + 60 | ``` 61 | 62 | Rename the `creds-sample.php` file to `creds.php`: 63 | 64 | ```bash 65 | mv creds-sample.php creds.php 66 | ``` 67 | 68 | Then edit/enter your MySQL username and password in the empty **$db_user** and **$db_pass** fields: 69 | 70 | ```php 71 | ... 72 | $db_host = "localhost"; 73 | $db_user = "steve"; 74 | $db_pass = "zissou"; 75 | $db_name = "torque"; 76 | $db_table = "raw_logs"; 77 | ... 78 | ``` 79 | 80 | 81 | # Settings in Torque App # 82 | 83 | To use your database/server with Torque, open the app on your phone and navigate to: 84 | 85 | ``` 86 | Settings -> Data Logging & Upload -> Webserver URL 87 | ``` 88 | 89 | Enter the URL to your **upload_data.php** script and press `OK`. Test that it works by clicking `Test settings` and you should see a success message like the image on the right: 90 | 91 |
92 | 93 | The final thing you'll want to do before going for a drive is to check the appropriate boxes on the `Data Logging & Upload` page under the `REALTIME WEB UPLOAD` section. Personally, I have both **Upload to webserver** and **Only when ODB connected** checked. 94 | 95 | At this point, you should be all setup. The next time you connect to Torque in your car, data will begin syncing into your MySQL database in real-time! 96 | -------------------------------------------------------------------------------- /scripts/create_torque_log_table.sql: -------------------------------------------------------------------------------- 1 | USE `torque`; 2 | 3 | DROP TABLE IF EXISTS `raw_logs`; 4 | CREATE TABLE `raw_logs` ( 5 | `v` varchar(1) NOT NULL, 6 | `session` varchar(15) NOT NULL, 7 | `id` varchar(32) NOT NULL, 8 | `time` varchar(15) NOT NULL, 9 | `kff1005` float NOT NULL DEFAULT '0', 10 | `kff1006` float NOT NULL DEFAULT '0', 11 | `kff1001` float NOT NULL DEFAULT '0' COMMENT 'Speed (GPS)', 12 | `kff1007` float NOT NULL DEFAULT '0' COMMENT 'GPS Bearing', 13 | `k4` float NOT NULL DEFAULT '0' COMMENT 'Engine Load', 14 | `k2f` float NOT NULL DEFAULT '0' COMMENT 'Fuel Level', 15 | `k11` float NOT NULL DEFAULT '0' COMMENT 'Throttle Position', 16 | `k5` float NOT NULL DEFAULT '0' COMMENT 'Engine Coolant Temp', 17 | `kc` float NOT NULL DEFAULT '0' COMMENT 'Engine RPM', 18 | `kd` float NOT NULL DEFAULT '0' COMMENT 'Speed (OBD)', 19 | `kf` float NOT NULL DEFAULT '0' COMMENT 'Intake Air Temp', 20 | `kff1226` float NOT NULL DEFAULT '0' COMMENT 'Horsepower', 21 | `kff1220` float NOT NULL DEFAULT '0' COMMENT 'Accel (X)', 22 | `kff1221` float NOT NULL DEFAULT '0' COMMENT 'Accel (Y)', 23 | `k46` float NOT NULL DEFAULT '0' COMMENT 'Ambiant Air Temp', 24 | KEY `session` (`session`,`id`), 25 | KEY `id` (`id`) 26 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 27 | -------------------------------------------------------------------------------- /scripts/dbdump_to_csv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Default MySQL database and table names 4 | DBNAME=torque 5 | TABLE=raw_logs 6 | 7 | # Location of your MySQL options file 8 | OPTFILE=$HOME/.my.cnf 9 | 10 | # Define full path of current directory 11 | CURDIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 12 | 13 | # Make a `torque_data` directory if it doesn't already exist 14 | mkdir -p $CURDIR/torque_data 15 | OUTDIR=$CURDIR/torque_data 16 | 17 | # Create a temporary directory where MySQL should be able to write 18 | TMPDIR=/tmp/torque_data 19 | mkdir -p $TMPDIR 20 | chmod a+rwx $TMPDIR 21 | TMPFILE=$TMPDIR/tempfile.csv 22 | 23 | # Define the name of the output CSV file 24 | FNAME=$OUTDIR/$(date +%Y.%m.%d)-$DBNAME.csv 25 | 26 | # Create an empty file and set up column names 27 | mysql --defaults-file=$OPTFILE $DBNAME -B -e "SELECT COLUMN_NAME FROM information_schema.COLUMNS C WHERE table_name = '$TABLE';" | awk '{print $1}' | grep -iv ^COLUMN_NAME$ | sed 's/^/"/g;s/$/"/g' | tr '\n' ',' > $FNAME 28 | 29 | # Append newline to mark beginning of data vs. column titles 30 | echo "" >> $FNAME 31 | 32 | # Dump data from DB into temp file 33 | mysql --defaults-file=$OPTFILE $DBNAME -B -e "SELECT * INTO OUTFILE '$TMPFILE' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' FROM $TABLE;" 34 | 35 | # Merge data file and file with column names 36 | cat $TMPFILE >> $FNAME 37 | 38 | # Delete temp file 39 | rm -rf $TMPFILE 40 | 41 | echo "File saved to:" $FNAME 42 | -------------------------------------------------------------------------------- /web/auth_app.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/auth_functions.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/auth_user.php: -------------------------------------------------------------------------------- 1 | 58 | 59 | 60 | 61 | 62 | 63 |Value | Change |
---|