def __init__(self, settings=None, settings_file=None, source_ref_file=None): super().__init__(settings, settings_file, source_ref_file) self.connect2db() # self.gateway_key = self.get_gatewaykey() try: self.partic = opc.OPCN3(spi) except Exception as e: print("Startup Error: {}".format(e))
# -*- coding: utf-8 -*- ####################### IMPORTS ######################## import spidev import opc from gpiozero import LED #################### SENSOR SETUP ###################### # spi setup spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 1 spi.max_speed_hz = 500000 # Turn off OPC-N3 opcn3 = opc.OPCN3(spi) opcn3.off() # Turn off LED led = LED(17) led.off()
'''this code is a low level test to check we wake up the OPCN3. Next try read_once_opcn3 to use more features of the library''' from usbiss.spi import SPI import opc # Open a SPI connection spi = SPI("/dev/ttyACM0") # Set the SPI mode and clock speed spi.mode = 1 spi.max_speed_hz = 500000 try: alpha = opc.OPCN3(spi) except Exception as e: print("Startup Error: {}".format(e)) # Turn on the OPC alpha.on() # Read the histogram and print to console for key, value in alpha.histogram().items(): print("Key: {}\tValue: {}".format(key, value)) # Shut down the opc alpha.off()
"""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.OPCN3(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)
import opc import time import datetime from influxdb import InfluxDBClient import mh_z19 #################### SENSOR SETUP ###################### # spi setup spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 1 spi.max_speed_hz = 500000 startTime = datetime.datetime.now() startDate = datetime.date.today() alphasense = opc.OPCN3(spi) ################### Global Variables #################### # Set InfluxDB parameters. host = "localhost" port = 8086 user = "******" password = "******" dbname = "logger_db" session = "test2" now = datetime.datetime.now() run_num = now.strftime("%Y%m%d%H%M") # How frequently we will write sensor data from the sensor to the database (s) sampling_period = 4