Skip to content

justiniso/datadog-iot-esp-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monitor ESP IoT devices with Datadog (ESP8266 / ESP32)

IMG_6175

This is a demo library for sending metrics to Datadog from ESP-based IoT devices (ESP32 / ESP8266 / ESP12). The Datadog IoT Agent cannot run on ESP-based microprocessors, but these ESP-based microprocessors are widely used in IoT devices. They usually require a centralized hub running MQTT to collect statistics, but the hub-based architecture presents some challenges in certain applications:

  • A second device is needed
  • It is more expensive to run a hub than cheap ESP chips
  • Hubs are a single point of failure for all telemetry

By sending telemetry directly from the ESP microprocessors, the decentralized architecture is far better suited for certain applications (e.g. security).

Usage

Usage in application code is simple. You can initialize the Datadog client once and submit metrics. Due to the high cost of establishing a new connection, it is generally recommended to pre-aggregate events before flushing them to Datadog on some cadence (e.g. once every 5 minutes).

See the examples directory for an example using the client. This example will send a single Datadog metric every 10 seconds:

#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif

#include <DatadogClient.h>

#define DD_API_KEY "REPLACEME"
#define WIFI_SSID "REPLACEME"
#define WIFI_PASS "REPLACEME"

DatadogClient dd(DD_API_KEY);

void setup()
{
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  dd.begin();
}

void loop()
{
  dd.metric("demo.esp.test", METRIC_TYPE_GAUGE, 100, "\"tag1:demo\",\"tag2:demo2\"");
  delay(10000);
}

About

Demo library for submitting metrics to Datadog from ESP IoT devices (ESP32 / ESP8266 / ESP12)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages