Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Small Things for Monitoring

Jan-Piet Mens
November 17, 2016

Small Things for Monitoring

Jan-Piet Mens

November 17, 2016

More Decks by Jan-Piet Mens

Other Decks in Technology


  1. @jpmens: consultant, part- time admin, small-scale fiddler, loves DNS, plain

    text, and things that work. Dreamed up OwnTracks & wrote jo
  2. CLI utilities mosquitto_sub -v [-h localhost] [-p 1883] [--cafile file]

    [--cert file --key file] [-u username [-P password]] -t 'topic/#' subscribe publish mosquitto_pub ... [-r] -t topic -m payload
  3. Python API: PUB #!/usr/bin/env python import paho.mqtt.publish as mqtt mqtt.single('conf/hello',

    'Hello MQTT') $ mosquitto_sub -h localhost -v -t 'conf/#' conf/hello Hello MQTT payload topic
  4. Python API: SUB callbacks #!/usr/bin/env python import paho.mqtt.client as paho

    def on_connect(mosq, userdata, rc): mqttc.subscribe("conf/+", 0) def on_message(mosq, userdata, msg): print "%s %s" % (msg.topic, str(msg.payload)) mqttc = paho.Client(userdata=None) mqttc.on_connect = on_connect mqttc.on_message = on_message mqttc.connect("localhost", 1883, 60) mqttc.loop_forever()
  5. Python API: SUB $ mosquitto_pub -t 'conf/thirsty' -m 'Beertime?' $

    mosquitto_pub -t 'conf/catering' -m 'Coffee is ready' $ ./sub.py conf/thirsty Beertime? conf/catering Coffee is ready
  6. The hardware … EUR 22.83 Flash/RAM 16 / 64 USB

    2 LAN/WAN 1 / 1 WiFi 802.11 b/g/n GL-Inet AR150
  7. ESP8266 Low-cost micro controller full TCP/IP stack A bit like

    an Arduino (same IDE, or Lua) but with on-board WiFi (!) and really inexpensive Different form factors
  8. Wemos D1 mini EUR 4.00 Flash/RAM 4MB / 64 KB

    Voltage 3.3V Digital I/O 11 Analog 1
  9. Homie-ESP8266 #include <Homie.h> HomieNode buttonNode("button", "button"); void loopHandler() { int

    buttonValue = debouncer.read(); /* ... */ if (Homie.setNodeProperty(buttonNode, "open", buttonValue ? "true" : "false", true)) { } } void setup() { debouncer.attach(PIN_BUTTON); Homie.setFirmware("button-homie", "1.0.0"); Homie.registerNode(buttonNode); Homie.setLoopFunction(loopHandler); Homie.setup(); } void loop() { Homie.loop(); debouncer.update(); } https://github.com/marvinroger/homie-esp8266
  10. Le bouton devices/cea191e0/$nodes button:button devices/cea191e0/$online true devices/cea191e0/$name Le bouton devices/cea191e0/$localip devices/cea191e0/$fwname button-homie devices/cea191e0/$fwversion 1.0.0 devices/cea191e0/$signal 100 devices/cea191e0/button/open true
  11. MQTT in the wild Graylog, beaver, Ansible, RabbitMQ, collectd, openHAB,

    Github, Wireshark, Flukso, RemakeElectric, Jenkins, Diamond, OwnTracks