# ------------------------------------------------------------ # Copyright © 2026/2027 Dr. Mohammad Alja'afreh. All rights reserved. # PSUT IoT Engineering Learning Platform # ------------------------------------------------------------ # ---- Telegraf: subscribe to YOUR greenhouse topics on the MQTT broker and # store every message in InfluxDB 2. No Python needed: only this file. # ${STUDENT_ID} and ${INFLUX_TOKEN} are read from the environment when Telegraf starts. [agent] flush_interval = "2s" # write to InfluxDB at most every 2 s omit_hostname = true # do not add a "host" tag to every point skip_processors_after_aggregators = true # the future default; silences a start-up warning # ---- Input: MQTT consumer (one subscription, many devices) [[inputs.mqtt_consumer]] servers = ["${MQTT_SERVER}"] topics = ["psut/iot/${STUDENT_ID}/greenhouse/+/telemetry"] # + = any device name qos = 1 # the broker resends until Telegraf confirms topic_tag = "" # do not store the whole topic as a tag data_format = "json_v2" # the payload is JSON # Topic levels → tags: psut / iot / / greenhouse / / telemetry [[inputs.mqtt_consumer.topic_parsing]] topic = "psut/iot/+/greenhouse/+/telemetry" tags = "_/_/student/_/node/_" # JSON keys → fields, always as floats (avoids field-type conflicts, Lab 42 Step 5) [[inputs.mqtt_consumer.json_v2]] measurement_name = "environment" [[inputs.mqtt_consumer.json_v2.tag]] path = "source" optional = true [[inputs.mqtt_consumer.json_v2.field]] path = "temperature" type = "float" [[inputs.mqtt_consumer.json_v2.field]] path = "humidity" type = "float" [[inputs.mqtt_consumer.json_v2.field]] path = "soil_moisture" type = "float" # ---- Output: InfluxDB 2 (the same bucket as Lab 42) [[outputs.influxdb_v2]] urls = ["http://127.0.0.1:8086"] token = "${INFLUX_TOKEN}" organization = "psut" bucket = "greenhouse"