· 6 years ago · Mar 02, 2020, 05:24 AM
1# OpenIVN
2
3Welcome to our repo. OPENIVN represents the IP address of our backend.
4
5# Table of Contents
6- [Server Setup](#Server-Setup)
7- [Streaming](#Streaming)
8- [API Documentation](#API-Documentation)
9
10# Server Setup
11
121. Install Nginx (at least version 1.14.0)
13 ```bash
14 # install nginx
15 $ sudo apt install nginx
16
17 # check version
18 $ nginx -v
19 ```
20
21 Replace the following files with the provided data.
22
23 `/etc/nginx/nginx.conf`
24 ```bash
25 user www-data;
26 worker_processes 1;
27 pid /run/nginx.pid;
28
29 events {
30 worker_connections 1024;
31 }
32
33 http {
34 ##
35 # Basic Settings
36 ##
37 sendfile on;
38 tcp_nopush on;
39 tcp_nodelay on;
40 keepalive_timeout 65;
41 types_hash_max_size 2048;
42
43 include /etc/nginx/mime.types;
44 default_type application/octet-stream;
45
46 ##
47 # SSL Settings
48 ##
49 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
50 ssl_prefer_server_ciphers on;
51
52 ##
53 # Logging Settings
54 ##
55 access_log /var/log/nginx/access.log;
56 error_log /var/log/nginx/error.log;
57
58 ##
59 # Gzip Settings
60 ##
61 gzip on;
62 gzip_disable "msie6";
63
64 ##
65 # Virtual Host Configs
66 ##
67 include /etc/nginx/conf.d/*.conf;
68 include /etc/nginx/sites-enabled/*;
69 }
70 ```
71
72 `/etc/nginx/proxy_params`
73 ```bash
74 proxy_set_header Host $http_host;
75 proxy_set_header X-Real-IP $remote_addr;
76 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
77 proxy_set_header X-Forwarded-Proto $scheme;
78 ```
79
80 `/etc/nginx/sites-available/default`
81 ```bash
82 server {
83 listen 1609 ssl; #default_server;
84 server_name OPENIVN;
85
86 client_max_body_size 50M;
87
88 ssl on;
89 ssl_certificate #path/to/your/ssl/cert/here;
90 ssl_certificate_key #path/to/your/ssl/cert/key/here;
91
92 location / {
93 proxy_pass http://127.0.0.1:1610;
94 include /etc/nginx/proxy_params;
95 }
96
97 location /robots.txt {
98 return 200 "User-agent: *\nDisallow: /\n";
99 }
100 }
101 ```
102
1032. Clone repo
104 ```bash
105 $ git clone [REDACTED]
106 $ cd OpenIVN
107 ```
1083. Set up virtual environment
109 ```bash
110 $ python3.8 -m venv env
111 $ source env/bin/activate
112 ```
1134. Install dependencies
114 ```bash
115 $ pip install --upgrade pip setuptools wheel
116 $ pip install -e .
117 $ pip install LibreCAN/. (optional)
118 ```
1195. Run Flask development server
120 ```bash
121 $ ./bin/server.sh start-dev
122 ```
123 Might need to make the script an executable: `chmod +x bin/server.sh`
124
125 Sanity check
126 ```bash
127 $ curl http://localhost:1609/api/v1/hello_world/
128 $ curl https://OPENIVN:1609/api/v1/hello_world/
129 ```
130
131 Both requests should produce the same response:
132 ```json
133 {
134 "message_text": "Hello world!",
135 "url": "/api/v1/hello_world/"
136 }
137 ```
138
1396. Run Nginx/Gunicorn production server
140 ```bash
141 $ ./bin/server.sh start-prod
142 ```
143 Note: you will need `sudo` access to start Nginx server.
144 Might need to make the script an executable: `chmod +x bin/server.sh`
145
146 Sanity check (Note the updated localhost port - 1610)
147 ```bash
148 $ curl http://localhost:1610/api/v1/hello_world/
149 $ curl https://OPENIVN:1609/api/v1/hello_world/
150 ```
151
152 Both requests should produce the same response:
153 ```json
154 {
155 "message_text": "Hello world!",
156 "url": "/api/v1/hello_world/"
157 }
158 ```
159
160### Notes:
161* Generate a new API key for each additional device that wants to make requests to our endpoint by running `openivn/utilities/generate_api_key.py`. Add key on a new line to the file in `openivn/api.key`
162* Use HTTPS to connect to server
163* To initialize the LibreCAN git repo submodule (optional) in the OpenIVN repo do the following:
164```bash
165$ git clone
166$ git submodule init
167$ git submodule update
168```
169* To update the LibreCAN git repo submodule in the OpenIVN repo do the following:
170```bash
171$ cd OpenIVN/
172$ git submodule update --remote
173```
174
175
176# Streaming
177
178### UDP
179* Packets sent from mobile app to OpenIVN in **regular mode** will be formatted as:
180```text
181app_id, vehicle_str, timestamp, can_id, bus_id, payload
182
1831,Make_Model_2016_113,1582154787.243,359,2,727f010000190900
184```
185
186* Packets sent from mobile app to OpenIVN in **buffered mode** will be formatted as:
187 * Note that the data in { } will be repeated a variable number of times
188```text
189app_id, vehicle_str, {timestamp, can_id, bus_id, payload}
190
1911,Make_Model_2016_113,1582154787.243,359,2,727f010000190900,1582154787.255,359,2,727f010000190901,1582154787.289,359,2,727f010000190922
192```
193
194
195* Packets sent from OpenIVN to the developer will be formatted as:
196```text
197{
198 'app_id': 1,
199 'vehicle_str': 'Make_Model_2016_113',
200 'timestamp': 1582154787.243,
201 'item': item,
202 'data': trans_data
203}
204```
205
206# API Documentation
207
208### Hello World
209
210`https://OPENIVN:1609/api/v1/hello_world/`
211
212```json
213{
214 "message_text": "Hello world!",
215 "url": "/api/v1/hello_world/"
216}
217```
218
219### Get VIN
220
221`https://OPENIVN:1609/api/v1/vin/<string:vin>`
222
223```json
224{
225 "make": "Make",
226 "model": "Model",
227 "trim_options": [
228 {
229 "default": true,
230 "trim": "2017 Model ESSENTIAL FWD",
231 "trim_id": "383214"
232 },
233 {
234 "default": false,
235 "trim": "2017 Model SELECT AWD",
236 "trim_id": "383217"
237 },
238 {
239 "default": false,
240 "trim": "2017 Model LIMITED FWD",
241 "trim_id": "383215"
242 }
243 ],
244 "url": "/api/v1/vin/<VIN>",
245 "wheelbase": 100.0,
246 "year": "2017"
247}
248```
249
250### Get App List
251
252`https://OPENIVN:1609/api/v1/apps/`
253
254```json
255{
256 "apps": [
257 {
258 "author_id": "001",
259 "author_name": "George Washington",
260 "description": "Knowledge is in every country the surest basis of public happiness.",
261 "id": 1,
262 "name": "America101",
263 "streaming": 0,
264 "url": "/api/v1/apps/1/"
265 },
266 {
267 "author_id": "002",
268 "author_name": "John Adams",
269 "description": "I read my eyes out and can’t read half enough neither. The more one reads the more one sees we have to read.",
270 "id": 2,
271 "name": "Prez2",
272 "streaming": 1,
273 "url": "/api/v1/apps/2/"
274 },
275 {
276 "author_id": "003",
277 "author_name": "Thomas Jefferson",
278 "description": "On matters of style, swim with the current, on matters of principle, stand like a rock.",
279 "id": 3,
280 "name": "Declaration",
281 "streaming": 0,
282 "url": "/api/v1/apps/3/"
283 },
284 {
285 "author_id": "004",
286 "author_name": "James Madison",
287 "description": "Philosophy is common sense with big words.",
288 "id": 4,
289 "name": "Bill-o-Rights",
290 "streaming": 1,
291 "url": "/api/v1/apps/4/"
292 },
293 ],
294 "url": "/api/v1/apps/"
295}
296```
297
298### Get App
299
300`https://OPENIVN:1609/api/v1/apps/<int:app_id_slug>/`
301
302```json
303{
304 "author_id": "001",
305 "author_name": "George Washington",
306 "description": "Knowledge is in every country the surest basis of public happiness.",
307 "id": 1,
308 "name": "America101",
309 "permissions": {
310 "Acceleration Sensors": true,
311 "Battery": true,
312 "Doors": true,
313 "Engine Information": true,
314 "Engine Utilization": true,
315 "Fuel Information": true,
316 "Gyroscope": true,
317 "HVAC": true,
318 "Hood": true,
319 "Horn": true,
320 "Lights": true,
321 "Mirrors": true,
322 "Parking Brake": true,
323 "Pedal Positions": true,
324 "Position Information": true,
325 "Seat Belts": true,
326 "Speed": true,
327 "Torque": true,
328 "Trunk": true,
329 "Turn Signals": true,
330 "Windows": true,
331 "Windshield Wipers": true
332 },
333 "streaming": 0,
334 "url": "/api/v1/apps/1/"
335}
336```
337
338### Translate
339`https://OPENIVN/api/v1/translate/?make=Make&model=Model&year=2019&wheelbase=100&app_id=2&username=User`
340
341#### query params (url parameters)
342
343make
344
345model
346
347year
348
349wheelbase
350
351app_id
352
353user_id
354
355#### Form Body
356
357zip_file: translate.zip Contains <untranslated.json>
358
359```json
360{
361 "status": "Translated and saved",
362 "url": "/api/v1/translate/"
363}
364```
365
366DBCs are stored on https://OPENIVN:1609/api/v1/dbc/<dbc>