Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
iinnovations committed Dec 27, 2017
1 parent a63888e commit b93d722
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
73 changes: 73 additions & 0 deletions misc/adc_diff.py
@@ -0,0 +1,73 @@
#!/usr/bin/python
# Simple demo of reading the difference between channel 1 and 0 on an ADS1x15 ADC.
# Author: Tony DiCola
# License: Public Domain
import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15


# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
# - 2/3 = +/-6.144V
# - 1 = +/-4.096V
# - 2 = +/-2.048V
# - 4 = +/-1.024V
# - 8 = +/-0.512V
# - 16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 16
averages = 15
data_rate = 8

data_history = [0 for i in range(averages)]

print('Press Ctrl-C to quit...')
import numpy
while True:
# Read the difference between channel 0 and 1 (i.e. channel 0 minus channel 1).
# Note you can change the differential value to the following:
# - 0 = Channel 0 minus channel 1
# - 1 = Channel 0 minus channel 3
# - 2 = Channel 1 minus channel 3
# - 3 = Channel 2 minus channel 3
value = adc.read_adc_difference(0, gain=GAIN, data_rate=data_rate)
# Note you can also pass an optional data_rate parameter above, see
# simpletest.py and the read_adc function for more information.
# Value will be a signed 12 or 16 bit integer value (depending on the ADC
# precision, ADS1015 = 12-bit or ADS1115 = 16-bit).
print('Channel 0 minus 1: {0}'.format(value))
converted_value_volts = float(value) /32768 * 4.096/GAIN
w_m2 = converted_value_volts / 8e-6
print('\t ' + str(converted_value_volts) + 'V, ' + str(w_m2) + ' W/m2')

for i in range(averages-1):
data_history[averages-i-1] = data_history[averages-i-2]
data_history[0] = w_m2

used_values = []
for value in data_history:
if value:
used_values.append(value)

val_array = numpy.array(used_values)


mean = numpy.mean(val_array)
stdev = numpy.std(val_array)

print('\t Average: ' + str(mean) + ', stdev: ' + str(stdev))
print(used_values)
# Pause for half a second.
time.sleep(0.5)
69 changes: 69 additions & 0 deletions misc/db_conc_test.py
@@ -0,0 +1,69 @@
#!/usr/bin/python

__author__ = 'Colin Reese'
__copyright__ = 'Copyright 2016, Interface Innovations'
__credits__ = ['Colin Reese']
__license__ = 'Apache 2.0'
__version__ = '1.0'
__maintainer__ = 'Colin Reese'
__email__ = 'support@interfaceinnovations.org'
__status__ = 'Development'

# This script handles owfs read functions

import os, inspect, sys

top_folder = \
os.path.split(os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0])))[0]
if top_folder not in sys.path:
sys.path.insert(0, top_folder)


from cupid import pilib
from iiutilities import dblib


def test_conc(**kwargs):

settings = {
'database':dblib.sqliteDatabase(pilib.dirs.dbs.system),
'tablename':'logconfig',
'sessions':5,
'timeout':0,
'reads':1000
}
# settings.update(kwargs)

import threading
from time import sleep

def read_table(i):

results = {'name':threading.currentThread().getName(), 'success':0,'fail':0}

for iteration in range(settings['reads']):
"""thread worker function"""
thread_name = threading.currentThread().getName()
print(thread_name + ' reading table ' + settings['tablename'])
try:
# print('something . ')
the_table = settings['database'].read_table_smart(settings['tablename'])
except:
print('Worker ' + thread_name + ' FAIL')
results['fail'] += 1
else:
results['success'] += 1

wait_time = 0.1 + i*0.01
# print('sleeping ' + str(wait_time))
sleep(wait_time)

print(results)
return

for i in range(settings['sessions']):
threading.Thread(target=read_table, args=(i,), name='Worker ' + str(i)).start()


if __name__ == "__main__":
test_conc()
12 changes: 12 additions & 0 deletions netstats/netstats.ini
@@ -0,0 +1,12 @@
[uwsgi]
socket = /tmp/uwsginetstats.sock
master = true
processes = 4
wsgi-file = wsginetstats.py
stats = /tmp/uwsginetstatsstats.sock
memory-report = false
plugin = python
chmod-socket = 775
chown-socket = root:www-data
import = wsginetstats
logto = /var/log/uwsgi/uwsgi.netstats.log

0 comments on commit b93d722

Please sign in to comment.