Read serial port values using Pyserial

4

I created a plugin to monitor an Arduino presence sensor for Nagios. The plugin read serial port values in Arduino. The problem is that Nagios does not let the plugin running, it performs takes the values and shuts down. That 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)
    
asked by anonymous 26.11.2014 / 14:23

1 answer

1

This is because you are making calls to sys.exit([arg]) . This causes the program to shut down. Remove calls from sys.exit([arg]) and retest.

Reference: link

    
04.01.2015 / 17:54