Hardware

The recommended hardware platform is the Heltec Automation Wireless Stick, Wireless Stick Lite, and Wireless Shell. These devices are essentially an ESP32 with an integrated LoRa modem. They provide WiFi, BLE, LoRa, and LoRaWAN connectivity.

If you prefer to use an ESP32 development board, that would work too.

Example projects are provided that use easily installed and community maintained
Arduino libraries.

Features

  • HTTPS connections
  • Token based authentication

InfluxDB Project

#include <WiFiMulti.h>
#include <InfluxDbClient.h> // click to install: http://librarymanager/All#ESP8266-Influxdb

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define WIFI_SSID         ""     // WiFi name
#define WIFI_PASSWORD     ""     // WiFi password
#define INFLUXDB_URL      ""     // The address of your instance, like 'https://awesome.ufire.net:9999'
#define INFLUXDB_ORG      ""     // Organization name. It can't have any spaces in it for this library.
#define INFLUXDB_BUCKET   ""     // Bucket name, // InfluxDB UI -> Load Data -> Buckets -> Make or select a bucket
#define DEVICE            ""     // The name of this device
#define INFLUXDB_TOKEN    ""     // InfluxDB UI -> Load Data -> Tokens -> Make or select a token
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN);
WiFiMulti wifiMulti;
Point sensor("wifi_status");      // Data point

void setup() {
  Serial.begin(115200);

  // Setup wifi
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);

  Serial.print("Connecting to WiFi");
  while (wifiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();

  // Add tags
  sensor.addTag("device", DEVICE);
  sensor.addTag("SSID", WiFi.SSID());

  // Check server connection
  if (client.validateConnection()) {
    Serial.print("Connected to InfluxDB: ");
    Serial.println(client.getServerUrl());
  } else {
    Serial.print("InfluxDB connection failed: ");
    Serial.println(client.getLastErrorMessage());
  }
}

void loop() {
  sensor.clearFields();                                              // clear the fields to fill with new information
  sensor.addField("rssi", WiFi.RSSI());                              // Report RSSI of currently connected network
  Serial.print((String)"Writing " + sensor.toLineProtocol());        // Print what what we're writing

  // Write point
  if (client.writePoint(sensor)) {
    Serial.println(" OK");
  } else {
    Serial.println();
    Serial.println((String)"InfluxDB write failed: " + client.getLastErrorMessage());
  }

  delay(10000);
}

MQTT Project

#include <ArduinoMqttClient.h>      // click to install: http://librarymanager/All#ArduinoMqttClient
#include <WiFiClientSecure.h>

WiFiClientSecure  wifiClient;
MqttClient        mqttClient(wifiClient);

char         ssid[]      = "";               // your network SSID (name)
char         pass[]      = "";             // your network password 
char         mqtt_user[] = "";              // MQTT username
char         mqtt_pass[] = "";            // MQTT password
const char   broker[]    = "####.ufire.net";    // uFire.net address
int          port        = 8883;                   // MQTT SSL port
const char   topic[]     = "test";                 // topic to publish to
const long   interval    = 1000;                   // interval to publish messages
int          count       = 0;                      // message count

unsigned long previousMillis = 0;


void setup() {
  Serial.begin(115200);

  Serial.print("Attempting to connect to WPA SSID: ");
  Serial.println(ssid);
  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("Connected");
  Serial.print("Attempting to connect to the MQTT broker: ");
  Serial.println(broker);

  mqttClient.setUsernamePassword(mqtt_user, mqtt_pass);
  if (!mqttClient.connect(broker, port)) {
    Serial.print("MQTT connection failed. Error code ");
    Serial.println(mqttClient.connectError());
    while (1);
  }

  Serial.println("Connected to MQTT broker!");
}

void loop() {
  mqttClient.poll();

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    Serial.println((String)"Sending message to topic " + topic + " message #" + count);
    mqttClient.beginMessage(topic);
    mqttClient.print("message # ");
    mqttClient.print(count);
    mqttClient.endMessage();

    count++;
  }
}