Read serial port values using Pyserial

Asked

Viewed 2,578 times

4

I created a plugin to monitor an Arduino presence sensor for Nagios. The plugin read values from the serial port in Arduino. The problem is that Nagios does not let the plugin running, it executes takes the values and closes. This way it does not read the data correctly.

#!/usr/bin/python
import os, sys
import serial

    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0)
    while True:
        if state == "0":
          print "OK - Sem Alertas"
          sys.exit(0)
        elif (str(ser.read()) == '2'):
          print "WARNING " 
          sys.exit(1)
        elif (str(ser.read()) == '1'):
          print "CRITICAL - Intrusos Detectados" 
          sys.exit(2)
        else:
          print "UKNOWN - Parametro Desconhecido"
          sys.exit(3)

1 answer

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.