4.4 Lambda Overview

Lambda is one way of how the Greengrass gateway can interact with end devices and the cloud. A Lambda is configured or edited in the cloud and deployed on the Raspberry Pi board. The function comes with a Software Development Kit (SDK), which provides the Application Programming Interface used for cloud connection and topic-specific subscriptions and publications. The messages between the Raspberry Pi and the cloud are sent through the MQTT protocol, but the Greengrass core takes care of the procedures and, therefore, these details are more transparent.

The Lambda can be written in several programming languages and versions of programming languages. The one used in this application is written in Python™ 2.7. Since Module 3 of the tutorial provided by AWS for Greengrass, is based on Python 2.7, it will be easier to understand and get familiarized with the structure and the procedures of the Lambda.

The flow diagram of the Lambda is described below:

Figure 4-12. Lambda Workflow
  1. The Lambda will create a Greengrass client responsible for cloud communication.
  2. It will invoke a tool responsible for BLE connection and communication, and it will enter its virtual user interface. Other BLE-oriented tools that are available on Raspbian can be used.
  3. It will connect to the BLE end device using its MAC address. The tool does not provide device scanning and the MAC address is different for every device, so the user is responsible for providing it. More information on how to obtain the MAC address can be found in Command State.
  4. Once the connection has been established, it will read the bytes available in the temperature, pressure, and humidity characteristics using the char-read-hnd command, followed by the handler number. It will then pack the data and publish it to the cloud with the topic ‘BLE/data’. This step is in a loop. The actions are executed once every five seconds. The topic name and the time between executions are the user’s choice and can be changed. The read of the characteristics is done through a handler, which is assigned when the characteristics are created. More information on how to obtain the handler can be found in Command State.