Mwyann / psakey

Peugeot Connect Apps / Citroën Multicity Connect your way
59 stars 14 forks source link
car rpi smeg

This guide will let you make an Raspberry Pi Zero W act like a connected key from PSA (commercial names are Peugeot Connect Apps - Citroën Multicity Connect). The service will be/is discontinued since March 2018, although the system on the car still works perfectly.

The car's system consists of a simple Internet Explorer 6 Mobile, so it is able to display HTML pages with images, CSS support, Javascript (jQuery 1.x works). This project could lead to a new kind of connected service, open-source and community-driven.

Of course, this project isn't aimed at enabling Peugeot/Citroën commercial services for free, its purpose is to enable people to make their own services by developing (or installing) them on their own hardware.

Join our Discord server: https://discord.gg/yPcR2ca6xW

Quick install from scratch

SMEG+ Screen

More information

Before installation

This script will enable the USB gadget feature on the Raspberry Pi, thus it will disable the standard USB OTG. If you wish to connect to the Raspberry while it's plugged into your car (for testing purposes or anything), you should configure the WLAN by filling the /etc/wpa_supplicant/wpa_supplicant.conf file correctly.

If you forgot to do this after running the installation script, you have two options to get back into your RPi:

Installation

The install_psakey.sh script will take care of all the configuration you need to get you started with your PSA key installation. You can configure the path of the root of the PSAKEY website that will be served to your car by editing the install script and changing the PSAKEYROOT variable at the top.

After installation

When installation is done, you can reboot your RPi to make all changes active. Please note that the script configures the sdcard partitions to be read-only because the RPi will be powered off by losing power when operated on the car, so to avoid filesystem corruption, I force a read-only mounting, and I specify some directories to be mounted as tmpfs (on RAM). If you need to remount read-write, you can run the remount script (installed in /usr/sbin/) and it will remount the root filesystem as read-write for you. Don't forget to power off or reboot your Rpi properly to avoid problems.

If your SMEG+ displays the Hello World test correctly, then congratulations, you're good to go! You can now write HTML code for your car to display, just edit the PSAKEYROOT/index.html file on your key.

Also, some SD Cards have problems with the read-only mounting in linux and the device does not boot after the psakey install. Ektilth faced this issue with cheap noname cards and also with a Verbatim card. But a Sandisk Ultra worked fine every time for him. So if you see this error when you connect the RPI with HDMI to a monitor, try another card.

Updating kernel

If you have to update to the latest kernel, run the remount command, then update/upgrade using apt, and finally run sudo build_eem.sh again to build the newer version of the module.

Emulator

You can emulate the SMEG+ browser using Electron, so you don't have to develop in your car :-)

SMEG+ API

Of course that wouldn't be much fun if you couldn't use some JavaScript API functions of your SMEG+. I plan to write a documentation and/or JavaScript function set to use the car's API, but here are some examples (you can find more in the psakey/emulator.html file):

A great reference to look at is the official dev portal https://developer.groupe-psa.io/webportal/v1/api-reference/list/ where you can get the full list with arguments and explanations. Some of those API calls may not be available to your car model though.

Useful projects:

Here is another github project that uses psakey to display some useful informations: https://github.com/Ektilth/smegpowerup

I've provided an application example showing realtime obd2 data from an OBD2 bluetooth adapter, you can find the source code under the obd2 folder, and a video example here: https://youtu.be/RiFUbXsVagI

Building the usb_f_eem module manually

If the usb_f_eem module is missing for your kernel, you can automatically build the module from your device with build_eem.sh or cross-compile it with this quick how-to:

Download toolchain:

git clone https://github.com/raspberrypi/tools ~/tools

Setup toolchain in path:

export PATH=$PATH:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

Download and extract same kernel version from https://www.kernel.org/

Get kernel config from Raspberry:

modprobe configs

(grab /proc/config.gz via scp for example)

gunzip config.gz
mv config .config

Enable USB Gadget EEM (under Device Drivers > USB support > USB Gadget Support > Ethernet Gadget):

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

Download kernel's Module.symvers:

wget https://raw.githubusercontent.com/Hexxeh/rpi-firmware/955fa1d6e8cd8c94ad8a6680a09269d9bd2945c5/Module.symvers

Make module:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- SUBDIRS=drivers/usb/gadget/function/

Copy file drivers/usb/gadget/function/usb_f_eem.ko on the Raspberry /lib/modules/4.14.29+/kernel/drivers/usb/gadget/function/ folder, then run:

depmod