Remote car engine start using AWS Greengrass and Raspberry Pi

This project incorporates using AWS Greengrass running locally on a RaspberryPi to execute a lambda function to remotely start a car engine. I also included the use of the AWS IoT button as the remote trigger.

At a high level, to summarise, when I press the IoT Button a message is sent to the RPi via AWS IoT, which in turn triggers a Lambda function to run locally with AWS Greengrass. The Lambda function turns on a set of relays on a relay board using GPIO pins. The relays are connected directly to the battery and the starter motor solenoid, when the relays activate the starter motor starts.

Below is a short video explaining the process


To start with I built a circuit from the RaspberryPi to a relay board. The following diagram below shows the GPIO pins used for the circuit to the board.

(Diagram TBC)


Once connected I configured an AWS Greengrass group on the Raspberry Pi (the ‘core device’) using the default methodology outlined in the AWS documentation which also explains how to download Greengrass onto a core device.

Once I did this, I next downloaded the Python AWS Greengrass Core SDK to my computer (not the AWS Greengrass core device aka RaspberryPi).

I decompressed the downloaded SDK file and located the Python Lambda function (named greengrassHelloWorld.py) from the decompressed SDK (under Examples). This file was then used to write my Lambda code later.

I created a Lambda function deployment package named hello_world_python_lambda.zip by zipping up the files greengrassHelloWorld.py and the greengrasssdk folder.

Once completed, I headed over to the AWS console and to Lambda, and created a new function; Author from scratch, with runtime of Python 2.7 (Greengrass does not currently support Python 3)

Under the configuration tab, under Code Entry Type, I choose Upload a .ZIP file and choose hello_world_python_lambda.zip I just created.

I delete the example code in it, and wrote the following:

import greengrasssdk
import platform
import time
import json
import RPi.GPIO as GPIO

# Creating a greengrass core sdk client
client = greengrasssdk.client('iot-data')

relayTrigger1 = 17
relayTrigger2 = 27
relayTrigger3 = 22
relayTrigger4 = 23

def function_handler(event, context):
GPIO.setmode(GPIO.BCM)

GPIO.setup(relayTrigger1, GPIO.OUT)
GPIO.setup(relayTrigger2, GPIO.OUT)
GPIO.setup(relayTrigger3, GPIO.OUT)
GPIO.setup(relayTrigger4, GPIO.OUT)

GPIO.output(relayTrigger1, GPIO.LOW)
GPIO.output(relayTrigger2, GPIO.LOW)
GPIO.output(relayTrigger3, GPIO.LOW)
GPIO.output(relayTrigger4, GPIO.LOW)

client.publish(
topic='mk1',
payload=json.dumps({'message': 'Engine Starting'})
)
time.sleep(1)

GPIO.output(relayTrigger1, GPIO.HIGH)
GPIO.output(relayTrigger2, GPIO.HIGH)
GPIO.output(relayTrigger3, GPIO.HIGH)
GPIO.output(relayTrigger4, GPIO.HIGH)

GPIO.cleanup()
return

Currently, as is, this code will fail if I tried and deployed to GreenGrass as the GreenGrass user; ggc_user is not a member of the GPIO resource group on the Raspberry Pi.

First I double checked the correct user name by outputting all users

cut -d: -f1 /etc/passwd

It should be ggc_user. Then I checked what groups ggc_user is a member of by running the command id -Gn ggc_user

It returned nogroup

So then now, I needed to add ggc_user to my GreenGrass resource group

Finally I went back to the terminal and ran the command id -Gn ggc_user again to double check they are now in the right group.

*Connect the relay to the car*

Finally I wanted to create a remote button, using the AWS IoT button which can be bought on Amazon. To configure to IoT button you can either do it manually online or using the IoT button phone app which can be downloaded for Apple or Android. I chose the later as it is a quick install Wizard. Following the app steps, I set up up the IoT button in around 10 minutes.


Comments