예제 #1
0
def strikeSense():
    GPIO.setmode(GPIO.BCM)

    global sensor
    sensor = RPi_AS3935(address=0x03, bus=1)
    print("Calibrating lightning sensor...")
    sensor.reset()
    sensor.set_indoors(False)
    sensor.set_noise_floor(0)
    time.sleep(2)
    sensor.calibrate(tun_cap=0x0F)
    time.sleep(2)
    print("Calibration complete: ✓")

    def handle_interrupt(channel):
        time.sleep(0.003)
        reason = sensor.get_interrupt()
        if reason == 0x01:
            print("Noise level too high - adjusting")
            nf = sensor.raise_noise_floor()
            print("Noise floor: " + str(nf))
        elif reason == 0x04:
            print("Noise event detected - masking")
            sensor.set_mask_disturber(True)
        elif reason == 0x08:
            distance = sensor.get_distance()
            print("Sensor: AS3935")
            print("Address: 0x03")
            print("Lightning detected")
            print(str(distance) + "km away. (%s)" % now)

            strikeTime()
            strikePayload.update( { 'distance' : distance } )
            strikePayload.update( { 'stationId' : IdGen() } )

            json_s_payload = json.dumps(strikePayload, indent = 4)

            try:
                r = requests.post('http://192.168.1.137:8081/strike', data=json_s_payload)
                print(r.status_code, r.reason)

            except:
                pass

            strikePayload = {}

    pin = 17

    GPIO.setup(pin, GPIO.IN)
    GPIO.add_event_detect(pin, GPIO.RISING, callback=handle_interrupt)

    while True:
        time.sleep(1.0)
예제 #2
0
# BMP180 Setup (compatible with BMP085)

bmp180 = BMP180.BMP085()

################

# ad3935 Set up Lightning Detector

# turn I2CBus 2 on
tca9545.write_control_register(TCA9545_CONFIG_BUS2)
time.sleep(0.003)
#tca9545.write_control_register(TCA9545_CONFIG_BUS0)
#time.sleep(0.003)

as3935 = RPi_AS3935(address=0x03, bus=1)

as3935.set_indoors(False)
as3935.set_noise_floor(0)
#as3935.calibrate(tun_cap=0x0F)
as3935.calibrate(tun_cap=0x05)

as3935LastInterrupt = 0
as3935LightningCount = 0
as3935LastDistance = 0
as3935LastStatus = ""

as3935Interrupt = False
# turn I2CBus 0 on
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
time.sleep(0.003)
예제 #3
0
# -*-coding: utf-8 -*-
#!/usr/bin/env python
from RPi_AS3935 import RPi_AS3935
import RPi.GPIO as GPIO
import time
from datetime import datetime

GPIO.setmode(GPIO.BCM) #Inicia el GPIO
pin = 17 #Pin a usar para el IRQ
sensor = RPi_AS3935(address=0x03, bus=1) #Dirección del sensor
noise = 0
a = True
#----------Calibración----------#
sensor.reset() #Resetea el sensor
sensor.set_indoors(True) #Selección de interior o exterior
sensor.set_noise_floor(0) #Establece el nivel de ruido inicial
sensor.calibrate(tun_cap=0x09) #Número de capacitancia dividido entre 8
sensor.set_min_strikes(1) #Cantidad mínima de rayos para comenzar a sensar

#---------Archivo de escritura--------#
f = open("datos2.txt","a") #Apertura de archivo de datos
#---------Función de ajuste de Ruido------------#
def noise_calibration():
    global sensor,noise
    reason =sensor.get_interrupt()
    if reason == 0x01: #Ruido
        print ("Noise level too high - adjusting")
        sensor.raise_noise_floor() #ajusta el ruido elevando el voltaje
        noise = sensor.get_noise_floor() #se guarda nivel de ruido
        print (noise)
예제 #4
0
Licensed under the GNU General Public License (GPL) version 2 or greater.
Copyright 2014 Vanguard Computer Technology Labs, Inc.

"""

from RPi_AS3935 import RPi_AS3935
import RPi.GPIO as GPIO
import time
from datetime import datetime
GPIO.setmode(GPIO.BCM)
## Rev 1 Raspberry Pi: bus=0
## Rev 2 and later Raspberry Pi: bus=1
## All: address=<i2c add>

sensor = RPi_AS3935(address=0x03, bus=1)

## Uncomment to reset all registers to factory default values.
sensor.reset()

sensor.calibrate(tun_cap=0x0d)
time.sleep(0.002)
sensor.set_indoors(True)
sensor.set_noise_floor
## uncomment/set to filter out false positives
sensor.set_min_strikes(1)

def handle_interrupt(channel):
    time.sleep(0.003)
    global sensor
    reason = sensor.get_interrupt()
예제 #5
0
    def __init__(self, engine, config_dict):
        super(AS3935, self).__init__(engine, config_dict)
        loginf("service version is %s" % VERSION)
        svc_dict = config_dict.get('AS3935', {})
        addr = int(svc_dict.get('address', 0x03))
        loginf("address=0x%02x" % addr)
        bus = int(svc_dict.get('bus', 1))
        loginf("bus=%s" % bus)
        indoors = to_bool(svc_dict.get('indoors', True))
        loginf("indoors=%s" % indoors)
        noise_floor = int(svc_dict.get('noise_floor', 0))
        loginf("noise_floor=%s" % noise_floor)
        calib = int(svc_dict.get('calibration', 0x6))
        loginf("calibration=0x%02x" % calib)
        self.pin = int(svc_dict.get('pin', 17))
        loginf("pin=%s" % self.pin)
        self.data_binding = svc_dict.get('data_binding', None)
        loginf("data_binding=%s" % self.data_binding)
        pkt_binding = svc_dict.get('binding', 'archive')
        loginf("binding=%s" % pkt_binding)

        self.data = []

        # if a binding was specified, then use it to save strikes to database
        if self.data_binding is not None:
            # configure the lightning database
            dbm_dict = weewx.manager.get_manager_dict(
                config_dict['DataBindings'],
                config_dict['Databases'],
                self.data_binding,
                default_binding_dict=get_default_binding_dict())
            with weewx.manager.open_manager(dbm_dict, initialize=True) as dbm:
                # ensure schema on disk matches schema in memory
                dbcol = dbm.connection.columnsOf(dbm.table_name)
                memcol = [x[0] for x in dbm_dict['schema']]
                if dbcol != memcol:
                    raise Exception('as3935: schema mismatch: %s != %s' %
                                    (dbcol, memcol))

        # configure the sensor
        self.sensor = RPi_AS3935(address=addr, bus=bus)
        self.sensor.set_indoors(indoors)
        self.sensor.set_noise_floor(noise_floor)
        self.sensor.calibrate(tun_cap=calib)

        # configure the gpio
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.pin, GPIO.IN)

        # add a gpio callback for the lightning strikes
        try:
            # be sure nothing is registered already...
            GPIO.remove_event_detect(self.pin)
        except:
            pass
        # ... then add our handler
        GPIO.add_event_detect(self.pin,
                              GPIO.RISING,
                              callback=self.handle_interrupt)

        # on each new record, read then clear data since last record
        if pkt_binding.lower() == 'loop':
            self.bind(weewx.NEW_LOOP_PACKET, self.new_loop_packet)
        else:
            self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
예제 #6
0
    print(">>>>>>>>>>>>>>>>>>><<<<<<<<<<<")
    TCA9545_I2CMux_Present = False

import RPi.GPIO as GPIO
import time
from datetime import datetime

GPIO.setmode(GPIO.BCM)

# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
# for Python 3
if (config.enable_MySQL_Logging == True):
    if (sys.version_info >= (3, 0)):
        sensor = RPi_AS3935.RPi_AS3935(address=0x02, bus=1)
    else:
        # original
        sensor = RPi_AS3935(address=0x02, bus=1)

#set values for lightning
# format: [NoiseFloor, Indoor, TuneCap, DisturberDetection, WatchDogThreshold, SpikeDetection]
# default: [2,1,7,0,3,3]
NoiseFloor = config.AS3935_Lightning_Config[0]
Indoor = config.AS3935_Lightning_Config[1]
TuneCap = config.AS3935_Lightning_Config[2]
DisturberDetection = config.AS3935_Lightning_Config[3]
WatchDogThreshold = config.AS3935_Lightning_Config[4]
SpikeDetection = config.AS3935_Lightning_Config[5]

try:
from RPi_AS3935 import RPi_AS3935

sensor = RPi_AS3935(0x03, 1)

sensor.calibrate()

sensor.get_distance()
예제 #8
0
#!/usr/bin/env python
from RPi_AS3935 import RPi_AS3935

import RPi.GPIO as GPIO
import time
from datetime import datetime

GPIO.setmode(GPIO.BCM)

# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
sensor = RPi_AS3935(address=0x00, bus=0)

sensor.set_indoors(True)
sensor.set_noise_floor(0)
sensor.calibrate(tun_cap=0x0F)


def handle_interrupt(channel):
    time.sleep(0.003)
    global sensor
    reason = sensor.get_interrupt()
    if reason == 0x01:
        print "Noise level too high - adjusting"
        sensor.raise_noise_floor()
    elif reason == 0x04:
        print "Disturber detected - masking"
        sensor.set_mask_disturber(True)
    elif reason == 0x08:
        now = datetime.now().strftime('%H:%M:%S - %Y/%m/%d')
예제 #9
0
from random import randint

app = Flask(__name__, static_url_path='/static')
app.config['SECRET_KEY'] = 'super secret key!'
socketio = SocketIO(app)

GPIO.setmode(GPIO.BCM)

config = ConfigParser.RawConfigParser()
config.read('settings.cfg')

editable_fields = ['disturber', 'noise-floor', 'min-strikes', 'indoors']

date_format = config.get('interface', 'date_format')

sensor = RPi_AS3935(address=int(config.get('as3935', 'address'), 0),
                    bus=config.getint('pi', 'bus'))
sensor.calibrate(tun_cap=int(config.get('as3935', 'tuning_cap'), 0))

event_history = list()
debug_mode = config.getboolean('interface', 'debug_mode')


def register_strike(channel):
    timestamp = datetime.datetime.now().strftime(date_format)
    time.sleep(0.004)

    global sensor, event_history
    reason = sensor.get_interrupt()

    if reason == 0x08:
        data = {