BlueWave Studio forum
AUDI CAN bridge to APIs - Printable Version

+- BlueWave Studio forum (https://bluewavestudio.io/community)
+-- Forum: OpenAuto Pro (https://bluewavestudio.io/community/forum-86.html)
+--- Forum: API (https://bluewavestudio.io/community/forum-108.html)
+--- Thread: AUDI CAN bridge to APIs (/thread-3292.html)

Pages: 1 2 3 4 5 6 7


AUDI CAN bridge to APIs - peetereczek - 03-30-2022

I just kicked off some project to developt set of APIs to create bridge between OpenAuto and CAN Bus in my Audi A3 8P. If you have similiar platform and would like to participate, here is github link: https://github.com/peetereczek/openauto-audi-api

Aim is to use PiCAN 2 board (or any other can0 interface) directly from RaspberryPi to:
  • Control Day/Night theme from CAN message
  • Inject key strokes from MFA wheel
  • Fetch media and navigation metadata to be displayed on FIS <- most challenging part
  • Read OBD-II data and send them to OpenAuto digital gauges
  • Control reverse gear status from CAN message



RE: AUDI CAN bridge to APIs - GSPW - 03-30-2022

Hey there, just so you know, the Github link is down.


RE: AUDI CAN bridge to APIs - kaned84 - 03-31-2022

will it work also with audi a4 b7? it does not have can gateway...


RE: AUDI CAN bridge to APIs - peetereczek - 04-01-2022

(03-30-2022, 08:20 PM)GSPW Wrote: Hey there, just so you know, the Github link is down.

It is still private project. When I'll have significant progress, I'll make it public. Or if you want to participate actively I can invite you on GitHub

(03-31-2022, 09:09 PM)kaned84 Wrote: will it work also with audi a4 b7? it does not have can gateway...

It should. Audi A4 B7 has CAN bus for sure and messages should be very similiar to those which I'll have in my A3 8P


RE: AUDI CAN bridge to APIs - kaned84 - 04-12-2022

I can't wait for progress. also soon I will be able to help test things, still waiting for PiCan2 to arrive...


RE: AUDI CAN bridge to APIs - kaned84 - 06-22-2022

hello, any progress with this api?


RE: AUDI CAN bridge to APIs - peetereczek - 06-29-2022

Unfortunatelly not, I'm sorry. Work kicked much and not having nearly any time recently to develop it


RE: AUDI CAN bridge to APIs - chris_audi - 07-21-2022


Outdated! Please see the post on the next page:

https://bluewavestudio.io/community/thread-3292-post-18739.html#pid18739


Hello together,

so my project with raspberry pi and audi rns-e is nearly done.
I've modified some openauto pro api files to read canbus data.

Im not a programmer/coder .. i tried to merge existing scripts from https://www.janssuuh.nl/de/skin-audi-rns-full-beta/ and openauto pro api files together.
Hope it's okay to link his page. I wrote with the ownder of https://www.janssuuh.nl and it's ok for him to share the merged scripts here in the forum.

If i have more time, i will maybe write all down, but for now i will just share the scripts :-)

Im using two scripts, that will autostart with openauto pro interface:

From openauto_application.ini

[Application_6]
Name=RNS-E Tasten
Path=/usr/bin/python3 /home/pi/openauto-pro-api/api_examples/python/keystrokes_can.py
IconPath=/home/pi/.openauto/icons/rnse_button.svg
Arguments=
Autostart=true

[Application_7]
Name=CAN RFK
Path=/usr/bin/python3 /home/pi/reversecam/cam.py
IconPath=/home/pi/.openauto/icons/revcam.svg
Arguments=
Autostart=true

cam.py

In the reversecam.zip you will find the file cam.py
On my raspberry pi i have the reversecam folder here: home\pi\

What is in this script?:

- Read date and time from canbus and set it to the raspberry pi ... this ist great because the rpi normaly has no internet connection in the car
- Read reverse gear can bus massage and put the reverse camera stream in front ... i didn't got it working with openauto pro, so i've changed to picamera module.
- Close camera stream delayed after three seconds ... this can be modified in the script "sleep(3)" .. change to whatever you want
- You can turn on the camera manualy with holding the down left button for 3-5 seconds (see attached screenshot)

[attachment=1449]

There are some fragments from trying to put an argb / transparent overlay with guidelines onto the camera stream but i could'nt get that working

---------------------

On my raspberry pi i have the openauto-pro-apifolder here: home\pi\

keystrokes_can.py
- reading can bus messages from rns-e buttons and navigate openauto pro gui
- you can change this to whatever you want while having a look into: https://github.com/bluewave-studio/openauto-pro-api/blob/main/api_examples/python/KeyStrokes.py

MediaDataChanged.py
- reading the actual played artist and song from openauto pro api. This is working with bluetooth but i think it will not work with android auto and apple carplay?


In the attachments you will find the file "https://script.service.janssuuhsendcantofis.zip"
This is a kodi script to read the played media (mp3) wich kodi is playing and send this to the first and second line to the fis.
Maybe someone with coding/Programming knowledge could merge that script with openautopro api "MediaData.py" to read artist and song information from openauto pro api and send this to the fis

This kodi addon /script worked for me in kodi but im using a kufatec module to activate tv input from rns-e wich is writing all the time "VIN1" or "VIN2" to the fis Undecided


Hope my english was not that bad :-)

Chris


RE: AUDI CAN bridge to APIs - kaned84 - 08-02-2022

(07-21-2022, 04:11 PM)chris_audi Wrote: Hello together,

so my project with raspberry pi and audi rns-e is nearly done.
I've modified some openauto pro api files to read canbus data.

Im not a programmer/coder .. i tried to merge existing scripts from https://www.janssuuh.nl/de/skin-audi-rns-full-beta/ and openauto pro api files together.
Hope it's okay to link his page. I wrote with the ownder of https://www.janssuuh.nl and it's ok for him to share the merged scripts here in the forum.

If i have more time, i will maybe write all down, but for now i will just share the scripts :-)

Im using two scripts, that will autostart with openauto pro interface:

From openauto_application.ini

[Application_6]
Name=RNS-E Tasten
Path=/usr/bin/python3 /home/pi/openauto-pro-api/api_examples/python/keystrokes_can.py
IconPath=/home/pi/.openauto/icons/rnse_button.svg
Arguments=
Autostart=true

[Application_7]
Name=CAN RFK
Path=/usr/bin/python3 /home/pi/reversecam/cam.py
IconPath=/home/pi/.openauto/icons/revcam.svg
Arguments=
Autostart=true

cam.py

In the reversecam.zip you will find the file cam.py
On my raspberry pi i have the reversecam folder here: home\pi\

What is in this script?:

- Read date and time from canbus and set it to the raspberry pi ... this ist great because the rpi normaly has no internet connection in the car
- Read reverse gear can bus massage and put the reverse camera stream in front ... i didn't got it working with openauto pro, so i've changed to picamera module.
- Close camera stream delayed after three seconds ... this can be modified in the script "sleep(3)" .. change to whatever you want
- You can turn on the camera manualy with holding the down left button for 3-5 seconds (see attached screenshot)



There are some fragments from trying to put an argb / transparent overlay with guidelines onto the camera stream but i could'nt get that working

---------------------

On my raspberry pi i have the openauto-pro-apifolder here: home\pi\

keystrokes_can.py
- reading can bus messages from rns-e buttons and navigate openauto pro gui
- you can change this to whatever you want while having a look into: https://github.com/bluewave-studio/openauto-pro-api/blob/main/api_examples/python/KeyStrokes.py

MediaDataChanged.py
- reading the actual played artist and song from openauto pro api. This is working with bluetooth but i think it will not work with android auto and apple carplay?


In the attachments you will find the file "https://script.service.janssuuhsendcantofis.zip"
This is a kodi script to read the played media (mp3) wich kodi is playing and send this to the first and second line to the fis.
Maybe someone with coding/Programming knowledge could merge that script with openautopro api "MediaData.py" to read artist and song information from openauto pro api and send this to the fis

This kodi addon /script worked for me in kodi but im using a kufatec module to activate tv input from rns-e wich is writing all the time "VIN1" or "VIN2" to the fis Undecided


Just for security reasons i scanned all attachments with virustotal:

reversecam.zip:
https://www.virustotal.com/gui/file/01db95fc00bd5d5bb50656925d4e5c04cb4910e602697f421fb7bd3f19a92948/detection

https://openauto-pro-api.zip:
https://www.virustotal.com/gui/file/7d05a85c86fddc3c8f6cb23584813373ae136820bc1656a298dcd37f26c8fce4?nocache=1

rns-e button.png:
https://www.virustotal.com/gui/file/2a0c8b74a3992d4049eada4d3d9d566cf1b16e2d80abbd117121f95b223b3d1d?nocache=1

https://script.service.janssuuhsendcantofis.zip:
https://www.virustotal.com/gui/file/0500f743ebfaab985bf993ebe71c227ca3133f1caeadcab077cbff5ee761e95f?nocache=1<

Hope my english was not that bad :-)

Chris
Great work Chris, thanks for sharing,

Did you look at janssuuh script for shutting down pi with ignition (OFF) /canbus combination?

I can not make it work... Smile maybe you will have better luck/more experience Wink


RE: AUDI CAN bridge to APIs - chris_audi - 08-29-2022

(08-02-2022, 09:33 AM)kaned84 Wrote:
(07-21-2022, 04:11 PM)chris_audi Wrote: Hello together,

so my project with raspberry pi and audi rns-e is nearly done.
I've modified some openauto pro api files to read canbus data.

Im not a programmer/coder .. i tried to merge existing scripts from https://www.janssuuh.nl/de/skin-audi-rns-full-beta/ and openauto pro api files together.
Hope it's okay to link his page. I wrote with the ownder of https://www.janssuuh.nl and it's ok for him to share the merged scripts here in the forum.

If i have more time, i will maybe write all down, but for now i will just share the scripts :-)

Im using two scripts, that will autostart with openauto pro interface:

From openauto_application.ini

[Application_6]
Name=RNS-E Tasten
Path=/usr/bin/python3 /home/pi/openauto-pro-api/api_examples/python/keystrokes_can.py
IconPath=/home/pi/.openauto/icons/rnse_button.svg
Arguments=
Autostart=true

[Application_7]
Name=CAN RFK
Path=/usr/bin/python3 /home/pi/reversecam/cam.py
IconPath=/home/pi/.openauto/icons/revcam.svg
Arguments=
Autostart=true

cam.py

In the reversecam.zip you will find the file cam.py
On my raspberry pi i have the reversecam folder here: home\pi\

What is in this script?:

- Read date and time from canbus and set it to the raspberry pi ... this ist great because the rpi normaly has no internet connection in the car
- Read reverse gear can bus massage and put the reverse camera stream in front ... i didn't got it working with openauto pro, so i've changed to picamera module.
- Close camera stream delayed after three seconds ... this can be modified in the script "sleep(3)" .. change to whatever you want
- You can turn on the camera manualy with holding the down left button for 3-5 seconds (see attached screenshot)



There are some fragments from trying to put an argb / transparent overlay with guidelines onto the camera stream but i could'nt get that working

---------------------

On my raspberry pi i have the openauto-pro-apifolder here: home\pi\

keystrokes_can.py
- reading can bus messages from rns-e buttons and navigate openauto pro gui
- you can change this to whatever you want while having a look into: https://github.com/bluewave-studio/openauto-pro-api/blob/main/api_examples/python/KeyStrokes.py

MediaDataChanged.py
- reading the actual played artist and song from openauto pro api. This is working with bluetooth but i think it will not work with android auto and apple carplay?


In the attachments you will find the file "https://script.service.janssuuhsendcantofis.zip"
This is a kodi script to read the played media (mp3) wich kodi is playing and send this to the first and second line to the fis.
Maybe someone with coding/Programming knowledge could merge that script with openautopro api "MediaData.py" to read artist and song information from openauto pro api and send this to the fis

This kodi addon /script worked for me in kodi but im using a kufatec module to activate tv input from rns-e wich is writing all the time "VIN1" or "VIN2" to the fis Undecided


Just for security reasons i scanned all attachments with virustotal:

reversecam.zip:
https://www.virustotal.com/gui/file/01db95fc00bd5d5bb50656925d4e5c04cb4910e602697f421fb7bd3f19a92948/detection

https://openauto-pro-api.zip:
https://www.virustotal.com/gui/file/7d05a85c86fddc3c8f6cb23584813373ae136820bc1656a298dcd37f26c8fce4?nocache=1

rns-e button.png:
https://www.virustotal.com/gui/file/2a0c8b74a3992d4049eada4d3d9d566cf1b16e2d80abbd117121f95b223b3d1d?nocache=1

https://script.service.janssuuhsendcantofis.zip:
https://www.virustotal.com/gui/file/0500f743ebfaab985bf993ebe71c227ca3133f1caeadcab077cbff5ee761e95f?nocache=1<

Hope my english was not that bad :-)

Chris
Great work Chris, thanks for sharing,

Did you look at janssuuh script for shutting down pi with ignition (OFF) /canbus combination?

I can not make it work... Smile maybe you will have better luck/more experience Wink

Hello kaned84,

you can try this one. Didn't tested this in the car yet, but it worked with a virtual can bus on my raspberry pi:


Update 21.09.2022: Updated shutdown script:
from __future__ import print_function
import os
import sys
import binascii
import datetime
import subprocess
import re
import time
import string
import can
from time import strftime, localtime, sleep, gmtime

#############################################
                                            #
# set here, what you want to have active    #
# PLEASE ONLY USE 'true' or 'false'         #
                                            #
shutdown_by_ignition_off = 'true'           # read ignition off message to shutdown the raspberry pi.
shutdown_by_pulling_key = 'true'            # read pulling key message to shutdown the raspberry pi.
                                            #
shutdown_delay = '5'    # in seconds        #
                                            #
#############################################

can_interface = 'can0'
bus = can.interface.Bus(can_interface, bustype='socketcan')
message = bus.recv()

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

def shutdown():
	try:
		for message in bus:
			tmstmp = message.timestamp
			canid = str(hex(message.arbitration_id).lstrip('0x').upper())
			msg = binascii.hexlify(message.data).decode('ascii').upper()
			if canid == '271':
				if msg[0:2] == '11' and shutdown_by_ignition_off == 'true': 
					eprint("ignition off message detected - system will shutdown in", shutdown_delay, "seconds")
					sleep(int(shutdown_delay)) # one second delay to read the eprint message, if startet from terminal
					eprint("system is shutting down now")
					os.system('sudo shutdown -h now')
				elif msg[0:2] == '10' and shutdown_by_pulling_key == 'true':
					eprint("pulling key message detected - system will shutdown in", shutdown_delay, "seconds")
					sleep(int(shutdown_delay)) # one second delay to read the eprint message, if startet from terminal
					eprint("system is shutting down now")
					os.system('sudo shutdown -h now')
 							
	except Exception as e:
		eprint("Error in function shutdown", str(e))

shutdown()

while True:
    sleep(0.5)


How to start the script: "python3 shutdown.py"
Best way should be to put this into the "openauto_application.ini" like you can see here: https://bluewavestudio.io/community/thread-3292-post-18490.html#pid18490

Feel free to contact me if you have any problems.

I hope i can finish merging all scripts into one script very soon. My idea was to have one script where you can activate some components of the sctipt you want to use. Example: Read date and time from canbus and set on py, reversecamera, shutdown on can message, controll openauto pro with rns-e buttons, send name from played song to fis


Answered in this thread too:
AUDI A4- SHUTDOWN THE PI VIA CAN BUS (IGNITION OFF) COMMAND?