GPIO voltage sensors
-
Vagoussontb
- Posts: 1
- Joined: Thu Jan 29, 2026 3:03 am
GPIO voltage sensors
Looking for some help with a small project. Have a raspberry pi and some voltage sensors hooked up to gpio headers. Does anyone know what plug-in would be needed to read the voltage on those sensors? Any help would be greatly appreciated.
.
-
DoubleDoubleA
- Posts: 290
- Joined: Thu Feb 09, 2017 5:07 pm
Re: GPIO voltage sensors
What voltage sensor do you have? Is there a driver for that sensor? I feel like the sensor is probably a 3-wire, one of those being the data wire. You'd write a custom plugin to call the sensor driver, parse the driver's output for your performance data, and then send that back in the plugin return.
https://nagios-plugins.org/doc/guidelines.html
https://nagios-plugins.org/doc/guidelines.html
Re: GPIO voltage sensors
When sending GPIO data to Nagios I normally opt for the "passive" vs the active.
Adding a webhook that can send data to NRDP is always an option.
You'd have to format your payload for NRDP etc.
There is an Arduino sketch on where I walk through how to add data with a timer for Arduino on Exchange if you want to get crafty and port that to rpi.
--SN
Adding a webhook that can send data to NRDP is always an option.
Code: Select all
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import requests
import time
import sys
# -----------------------------
# CONFIGURATION
# -----------------------------
OUTPUT_PIN = 18 # BCM pin number for output
WEBHOOK_URL = "https://example.com/webhook" # Replace with your webhook endpoint
POST_TIMEOUT = 5 # seconds
# -----------------------------
# SETUP
# -----------------------------
GPIO.setmode(GPIO.BCM)
GPIO.setup(OUTPUT_PIN, GPIO.OUT, initial=GPIO.LOW)
def send_webhook(state):
"""Send a POST request to the webhook with GPIO state."""
payload = {"pin": OUTPUT_PIN, "state": "HIGH" if state else "LOW"}
try:
response = requests.post(WEBHOOK_URL, json=payload, timeout=POST_TIMEOUT)
response.raise_for_status()
print(f"Webhook sent: {payload} | Response: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error sending webhook: {e}", file=sys.stderr)
def toggle_output():
"""Toggle GPIO output and send webhook."""
current_state = GPIO.input(OUTPUT_PIN)
new_state = not current_state
GPIO.output(OUTPUT_PIN, new_state)
send_webhook(new_state)
try:
print("Press Ctrl+C to exit.")
while True:
toggle_output()
time.sleep(5) # Change interval as needed
except KeyboardInterrupt:
print("\nExiting...")
finally:
GPIO.cleanup()
There is an Arduino sketch on where I walk through how to add data with a timer for Arduino on Exchange if you want to get crafty and port that to rpi.
--SN
-
lyraellington12
- Posts: 1
- Joined: Mon Mar 30, 2026 2:31 am
Re: GPIO voltage sensors
I think it's important to add another key point: if the goal is to read analog voltage, the Raspberry Pi doesn't have a built-in ADC, so you'll usually need an additional ADC module (e.g., MCP3008 or similar). In that case, the plugin/script will read the data via SPI/I2C rather than directly from the digital GPIOs. This is easily overlooked when discussing GPIOs in general.
Also, if you're aiming for Nagios/NCPA/NRDP, standardizing the output format (performance data) right from the plugin is crucial for easier graphing later (PNP4Nagios, Grafana, etc.).
Also, if you're aiming for Nagios/NCPA/NRDP, standardizing the output format (performance data) right from the plugin is crucial for easier graphing later (PNP4Nagios, Grafana, etc.).