Skip to content

III. Smart Trash Bin: Communication

shadiamanan edited this page Aug 30, 2024 · 82 revisions

This page provides information regarding the communication protocols and services used for sensor data transfer and handling regarding our smart trash bins in "TinyAIoT" project.

Contents

Communication Protocols

The trash bin is fitted with a Time of Flight (ToF) sensor which is the distance sensor, thus, making it a smart trash bin. The Time of Flight sensor records the fill level of the trash bin and sends these measurements using LoRa Gateway which is part of the LoRaWAN network.

LoRaWAN stands for Long Range Wide Area Network and it is the name of the protocol that actually defines the system architecture and the communication parameters where as LoRa (Long Range) allows for long range communication. The LoRaWAN protocol implements communication details like data security, operations and quality of service etc. Moreover, it also functions as a standard for carrying out communication with gateways in the network, thus, also enabling interoperability.

LoRaWAN network consists of a star topology which includes three different types of devices: end devices, gateways and network server. The end devices are the various applications that send the collected data to the gateways using LoRa technology and the gateways forward the data packets received from the end devices to a network server. Our smart trash bin that has the Time of Flight sensor deployed in it acts as the End Node or the End Device in the LoRaWAN network. Then, comes the LoRa gateway which is mounted on a rooftop. This LoRa gateway receives messages sent from sensor devices installed in our smart trash bins and in turn forwards these messages containing sensor measurements to the Network Server in LoRaWAN network which is The Things Network (TTN) in our case. This overall workflow is illustrated in the following image:

The Things Network Server is a critical component for any LoRaWAN solution. It aggregates and processes the sensor data received from the LoRa gateways. It also ensures that the data meets LoRaWAN specifications and further routes it to the Application Server on the other end of the network. LoRa is one of the most promising technologies for loT applications together with it’s LoRaWAN communication protocol. LoRa together with LoRaWAN offer a number of favourable features that are well suited for "TinyAIoT" Project scenario. It offers long range communication capabilities along with low power consumption. It can scale to support thousands of devices and it is also cost effective. That is why it is a suitable choice for "TinyAIoT" project.

Measurement information sent from the ToF sensor consists of the Fill Level of the trash bin, the battery level of the attached battery and the signal level.

The sensor measurements received by The Things Network are sent to the backend database using MQTT (Message Queuing Telemetry Transport). MQTT is used because it is light weight in nature, it is reliable, secure and has efficient use of bandwidth which makes it ideal for IoT devices with limited resources like in the case of “TinyAIoT” project scenario. MQTT is a Machine-to-Machine (M2M) protocol and it is currently being globally used for IoT applications. It has been designed to be extremely light in message transport and it is useful for those connections where small messages are sent in low transmission rates. MQTT uses a publish subscribe model whereby devices subscribe to a topic and only receive relevant messages from the broker.

Hence, our backend database acts as MQTT Topic Subscriber and subscribes to relevant MQTT Topic in order to receive sensor recorded measurements from TTN where these messages are stored. Our smart trash bin acts as MQTT Publisher in "TinyAIoT" project scenario. Example command to subscribe to MQTT Topics is available in GitHub repository Commands.txt

The image below illustrates an example of a typical MQTT message with a JSON payload, as received in our project scenario. Message file is available in GitHub repository Message.json

The Things Network Configuration

Each sensor device is registered at The Things Network and then the messages sent by sensor devices are received and processed at TTN. For using TTN services, one needs to create an account on the website and then using login credentials one can navigate to the "Console" menu on left hand side of the website:



And thereby choosing relevant region and then proceeding with creating an application. A usage documentation is also available for using TTN services which does a good job at explaining the functionalities. The following images illustrate how these steps were carried out for "TinyAIoT" project:







Once an application has been created then "End Device" registration can be carried out. It can be carried out under "End Devices" menu as can be seen in the following image which was used for registering "TinyAIoT" sensor devices:



In The Things Network configuration, custom JavaScript payload formatter is defined in order to decode the messages received at TTN sent by sensor devices. The following code example illustrates how JavaScript payload formatter has been defined for "TinyAIoT" project scenario in order to decode the messages appropriately. The source code is available in the repository folder of GitHub which can be accessed here Formatter.js

function decodeUplink(input) {
 var bytes = input.bytes;
  var decoded = {};

  // Assuming 0046 is the entire payload and it's a 16-bit integer
  decoded.value = (bytes[0] << 8) | bytes[1];

  return {
    data: decoded
  };
}

In order to connect to MQTT an API key needs to be generated at The Things Network which functions as connection password. This is shown under "Integrations -> MQTT" menu on TTN as can be seen in the following image which was used for setting up the integrations for "TinyAIoT" project:



Once the sensor devices are registered successfully at TTN, then any live data sent by these sensor devices can also be seen on TTN under “Live Data” menu as illustrated in the following image which was used for our "TinyAIoT" project scenario: