Arduino Data on MQTT

MQTT is an OASIS standard messaging protocol for the Internet of Things (IoT) and one of the protocols supported by akenza. 
It is designed as an extremely lightweight publish/subscribe messaging protocol that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth. MQTT is used in various industries. 
To run this project, we used akenza as an IoT platform, as it runs an open-source MQTT broker from Eclipse MosquittoBy using a combination of MQTT and API functionalities, we have been able to automatically create Digital Twins for our device.

As Hardware, we have chosen an Arduino Uno WiFi Rev2.

1. Configure the Arduino Device

1.1 Set up the WiFi Connection

To have the Arduino Uno Wifi able to connect to WiFi, we used the WiFiNINA library, available in the Library Manager of Arduino IDE.

1.1.1 Manage Username and Password

To manage Username and Password, we have created an additional header file called arudino_secrets.h 
 
#define SECRET_SSID "<your username>"
#define SECRET_PASS "<your password>"


1.1.2 WiFi Connection Code

The code to connect Arduino to WiFi is reported as below:
 
#include <WiFiNINA.h>
#include "arduino_secrets.h"

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;     // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)

WiFiClient wifiClient;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to WPA SSID: ");
  Serial.println(ssid);
  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    // failed, retry
    Serial.print(".");
    delay(5000);
  }

  Serial.println("You're connected to the network");
  Serial.println();
}

void loop()
{}


1.2 Set up the MQTT Connection to akenza

For security reasons, akenza only supports authenticated connections via MQTT. For this, we have chosen as library PubSubClient to manage our MQTT connection. This enables us to use username and passwords in our connection string. 
 
#include <PubSubClient.h>

//MQTTClient mqttClient(WiFiClient);

char host[] = "mqtt.akenza.io";
char clientid[] = "Arduino";
char username[] = "<copy from Akenza Device Api configuration>";
char password[] = "<copy from Akenza Device Api configuration>";
char outTopic[] = "<copy from Akenza Device Api configuration>";

PubSubClient client(host, 1883, callback, wifiClient);

void setup() {
  if (client.connect(host, username, password)) {
    Serial.print("Connected to ");
    Serial.println(host);
    Serial.println();
    
    boolean r = client.subscribe(outTopic);
    Serial.print("Subscribed to ");
    Serial.println(outTopic);
    Serial.println();
    } 
    else {
      // connection failed
      // mqttClient.state() will provide more information
      // on why it failed.
      Serial.print("Connection failed: ");
      Serial.println(client.state());
      Serial.println();
  }
}


Making an IoT Developer’s Life Easier With Eclipse IoT Packages

As an IoT developer, one is often tasked with putting together a solution that includes one or more open source components. I remember, even as far back as 2014, using components like Eclipse Mosquitto MQTT broker and Eclipse Paho MQTT client for a pilot project with IoT Gateway at Intel. Fast forward a few years at Red Hat, where I used components like Eclipse Kura and Eclipse Kapua for a European industrial automation project. Without realizing it then, I was using these components from Eclipse IoT open source projects.

Eclipse IoT Packages logoImage courtesy of Eclipse Foundation

Top 10 IoT Applications in 2020

What Are the Hottest Application Areas for the Internet of Things Right Now?

IoT Analytics continues to track in which verticals most IoT projects are happening. The latest 2020 analysis shows that most IoT projects still happen in Manufacturing/Industrial settings, with verticals such as Transportation/Mobility, Energy, Retail, and Healthcare having also increased their relative share in comparison to past analyses.

The 2020 analysis is based on 1,414 actual IoT projects that were explored as part of IoT Analytics' research tracking IoT platforms and the underlying data is included in the 2020 list of 620 IoT platforms. The fact that more than 1,000 publicly announced IoT projects now make use of an IoT platform highlights the importance and pervasiveness of IoT platforms in bringing IoT solutions to market.

IoT Projects for Hobbyists and Professionals

IoT Projects
Learn How to Get Started on Your Own IoT Projects Today!

Interested in getting started with your own IoT project at home? Or are you embarking on a new IoT project at work? Either way, we've got some great tutorials on getting started, opinions pieces that examine different platforms you can use, and the benefits IoT devices and tech can bring to your development projects. 

Ready to get started? Then get to reading!