As Hardware, we have chosen an Arduino Uno WiFi Rev2.
1. Configure the Arduino Device
1.1 Set up the WiFi Connection
1.1.1 Manage Username and Password
#define SECRET_PASS “<your password>”
1.1.2 WiFi Connection Code
#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
//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();
}
}