Example #1
0
def init():
    try:
        ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
        usb = usbiss.USBISS('/dev/ttyACM0', 'spi', spi_mode=2, freq=500000)
        alphasense = opc.OPCN2(usb)
        alphasense.on()
        time.sleep(10.0)
        return True
    except:
        return False
Example #2
0
 def reset(self):
     self.spi = spidev.SpiDev()
     self.spi.open(0, 0)
     # Set the SPI mode and clock speed
     self.spi.mode = 1
     self.spi.max_speed_hz = 500000
     try:
         self.alpha = opc.OPCN2(self.spi)
     except Exception as e:
         print("Startup Error: {}".format(e))
     self.alpha.on()
     sleep(2)
Example #3
0
def init_opc ():
    print ("initializing OPC reader...")
    try:
        spi = usbiss.USBISS("/dev/opc", 'spi', spi_mode = 2, freq = 500000)
        sleep(2)
        opc_reader = opc.OPCN2(spi)
        sleep (2)
        opc_reader.on ()
        sleep (2)
        print ("success.")
        return opc_reader
    except:
        print ("Failed to init OPC")
        return None
Example #4
0
def get_alpha(spi):
    # Set the SPI mode and clock speed
    spi.mode = 1
    spi.max_speed_hz = 500000

    try:
        alpha = opc.OPCN2(spi, debug=True)

        if alpha is None:
            raise Exception('Could not connect!')

        print('Connected to', alpha)
        return alpha

    except Exception as e:
        exit_error(e, 'Could not start alpha controller')
Example #5
0
 def __init__(self):
     threading.Thread.__init__(self)
     # Open a SPI connection on CE0
     self.spi = spidev.SpiDev()
     self.spi.open(0, 0)
     # Set the SPI mode and clock speed
     self.spi.mode = 1
     self.spi.max_speed_hz = 500000
     self.SFR = 0
     self.PM25 = 0
     self.PM1 = 0
     self.PM10 = 0
     self.samplingPeriod = 0
     try:
         self.alpha = opc.OPCN2(self.spi)
     except Exception as e:
         print("Startup Error: {}".format(e))
# Initialize the K-30 carbon dioxide sensor.
import serial
import time
ser = serial.Serial('/dev/ttyAMA0')
print('    K-30 Serial Connected!')
ser.flushInput()
time.sleep(1)

# Initialize the OPC-N2 particle monitor.
import spidev
import opc
spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
spi.max_speed_hz = 500000
alpha = opc.OPCN2(spi)
print('    OPC-N2 connected!')
# Turn sensor on.
time.sleep(1)
alpha.on()

import atexit


@atexit.register
def cleanup():
    alpha.off()


# Read data from both sensors every 1 second.
while True:
Example #7
0
# In connection case get the values of particle sensor and sending by Xbee transceiver
# in the opposite case print negative case
if (a):
    with silence():
        # Create the saving file if the hardware is ready
        #Create the saving values and create news each the time change
        t0 = datetime.datetime.now()
        Name = "OPCN2_" + str(t0.year) + "_" + str(t0.month) + "_" + str(
            t0.day) + "_" + str(t0.hour) + "_" + str(t0.minute) + "_" + str(
                t0.second) + ".txt"
        FileSave = open(Name, 'w')
        # Again configure the hardware (global object)
        ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
        usb = usbiss.USBISS('/dev/ttyACM0', 'spi', spi_mode=2, freq=500000)
        alphasense = opc.OPCN2(usb)
        alphasense.on()
        time.sleep(10.0)
        while True:
            # Contruct the data to send. Use the frame construction and
            # send using Xbee
            Hist = alphasense.histogram()
            Hist['Time'] = str(datetime.datetime.now())
            d0 = str(Hist['PM1']) + " "
            d1 = str(Hist['PM2.5']) + " "
            d2 = str(Hist['PM10']) + " "
            d3 = str(Hist['Time'])
            D = d0 + d1 + d2 + d3
            Dat0 = range(0, len(D))
            for k in range(0, len(D)):
                Dat0[k] = ord(D[k])
Example #8
0
# Get arguments
if len(sys.argv) != 2:
    print('Usage: {} dev-path'.format(sys.argv[0]))
    sys.exit(1)

# Port
port = sys.argv[1]

# Sample period
period = 10

# Open connection to USB-ISS in SPI mode.
usb = usbiss.USBISS(port, 'spi', spi_mode=2, freq=500000)

# Give the USB connection to py-opc
alpha = opc.OPCN2(usb)

# Toggle to tur on properly
alpha.off()
sleep(1)

alpha.on()
sleep(1)

# log data
lastUpdated = 0

# data
latitude = str(37.295912)
longitude = str(126.975706)
Example #9
0
"""Run these tests at the command line/terminal via

    $ python3 tests/manual_tests.py
"""
import usbiss
from usbiss.spi import SPI
import opc
from time import sleep

spi = SPI("/dev/ttyACM0")

spi.mode = 1
spi.max_speed_hz = 500000

alpha = opc.OPCN2(spi, debug=True)

print("Running manual OPC-N2 tests...")

sleep(1)

# turn on
print("Turning ON: {}".format(alpha.on()))

sleep(1)

print("Reading histogram")
print(alpha.histogram())
sleep(1)

print(alpha.histogram())
sleep(1)
Example #10
0
# for debugging
#log.addHandler(logging.StreamHandler())

# for urbanova
rundir = '/run/aqnet/opcn2/'
try:
    os.makedirs(rundir)
except OSError:
    if not osp.isdir(rundir):
        raise

spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
spi.max_speed_hz = 500000
alphasense = opc.OPCN2(spi)

alphasense.on()

#import atexit
#@atexit.register
#def cleanup():
#    opc.off()

#while True:
#    try:
#        data = opc.histogram()
#        now = time.time()

#        jsondata = {}
#        for k,v in data.items():