For fun I decided to log some things to AdafruitIO:

  • motion start/end
  • light level when motion is detected
  • when lights are turned on/off

Feeds are created in the preamble:

// Setup MQTT
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM  = AIO_USER;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USER, AIO_KEY);
Adafruit_MQTT_Publish photocell_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-photocell");
Adafruit_MQTT_Publish motion_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-motion");
Adafruit_MQTT_Publish control_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-control");

We make use of those feeds in loop(). For example:

 if (motion_started) {
  motion_feed.publish((const char*)"started"));
  photocell_feed.publish(light_level));
} else if (motion_ended) {
  motion_feed.publish((const char*)"ended"));
}

This guide was first published on Feb 14, 2018. It was last updated on Feb 14, 2018.

This page (Using Adafruit IO) was last updated on Jul 23, 2021.

Text editor powered by tinymce.