...
The new telemetry system uses a Raspberry Pi to collect CAN messages from the vehicle along with metrics such as GPS coordinates. We use Node-Red to collect this data and also send it to FRED’s Node-Red which will store our data in the cloud and allow us to pull data from InfluxDB which is hosted by FRED. We also have a DBC file that helps us translate what each CAN message-id and data mean.
...
Setup
The link below shows how to set up Node-Red on the Raspberry Pi and generate the DBC file used to translate all the CAN messages. It also shows how to set up AWS so our scripts will work.
https://uwmidsun.atlassian.net/wiki/spaces/ELEC/pages/1395032080/Telemetry%2BSet%2BUp
To set up the connection between the Raspberry Pi’s Node-Red and FRED’s Node-Red, refer to the link here:
Connecting Device Node-Red to Cloud Node-Red
FRED
Link to FRED. This is the system we will be using that hosts Node-Red and InfluxDB on the cloud.
...
ifconfig eth0 192.168.1.254 up
ifconfig eth1 192.168.2.254 up
Long Term Storage
In terms of storing data locally on the Raspberry Pi, Node-Red can directly output the data to a CSV file locally on the Raspberry Pi. These files can be manually moved to Google Drive if necessary. The youtube tutorial below explains how to use the CSV node in Node-Red.
For our purposes, the setup should look something like this.
...
...
Aggregating Data
Since there is a flutter app that analyzes the CAN data and provides us with metrics on the vehicle, we need to be able to send WebSocket messages to the flutter app which can be set up through Node-Red. However, we also need to format these WebSocket messages as a JSON , similar to what is as shown below.
Code Block |
---|
{
"speed" : num,
"errors" : [],
"right_turn" : bool,
"left_turn" : bool,
"soc" : {
battery_percent : num,
...
},
drive_state : "",
cruise_control : bool
} |
Currently, the messages that Node-Red receives from vcan0 are like the object below, so we need to use the generated DBC file to translate these messages for the flutter app.
Code Block |
---|
{
"ext":false,
"rtr":false,
"canid":123,
"dlc":5,
"data":[1,2,3,4,5]}
} |
CAN Messages
Property | Sample Value |
---|---|
Datetime | 2020-01-20 03:14:07 |
Name | MOTOR_CONTROLLER_VC |
Sender | MOTOR_CONTROLLER |
Data | {'mc_voltage1':1234, ‘mc_current1’:1} |
GPS Data
Property | Value | Decoded |
---|---|---|
Datetime | 030620 044747.0 | June 3, 2020 4:47:47.0 |
Latitude | 3722.117666 | 37° 22.117666' |
Latitude Direction | N | North |
Longitude | 12200.011971 | 122° 00.011971' |
Longitude Direction | W | West |
Altitude (meters) | 11.6 | 11.6 |
Speed (knots = 1.852 km/h) | 0.0 | 0.0 |
Course (degrees) | 0.0 | 0.0 |
The aggregate_can_data.py script allows us to grab data from the CAN bus, decode the message with our DBC file, write to a CSV, send to FRED with MQTT, and send to DynamoDB.
The GPS.py script allows us to grab GPS data from the vehicle.
Storing Data on the Raspberry Pi
In terms of storing data locally on the Raspberry Pi, the Python script aggregate_can_data.py can directly output the data to a CSV file locally on the Raspberry Pi. These files can be manually moved to Google Drive if necessary.
...