Exemplo n.º 1
0
 def get_sample(self):
     bmp = bmp183()
     bmp.measure_pressure()
     pre = bmp.pressure / 100.0
     if pre == None:
         self._log.warning('failed to read Pressure')
     return 'press', (common.timestamp(), pre)
Exemplo n.º 2
0
 def __init__(self, occ):
     threading.Thread.__init__(self)
     ## @var l
     # System logger handle
     self.l = logging.getLogger('system')
     ## @var occ
     # OCC Handle
     self.occ = occ
     ## @var sensors
     # Dict with sensor instances
     self.sensors = dict(ble_sc=None, ble_hr=None, gps=None, bmp183=None)
     ## @var names
     # Dict with names of the sensors
     self.names = dict(ble_sc='', ble_hr='', gps='', bmp183='')
     ## @var addrs
     # Dict with BLE addresses of the sensors
     self.addrs = dict(ble_sc='', ble_hr='', gps='', bmp183='')
     ## @var simulate
     # Local copy of simulate variable from OCC
     self.simulate = occ.get_simulate()
     ## @var ble_state
     # BLE host state
     self.ble_state = STATE_HOST['enabled']
     ## @var no_of_connected
     # Number of connected BLE devices
     self.no_of_connected = 0
     ## @var connecting
     # Indicates if host is currently trying to establish connection
     self.connecting = False
     ## @var connected
     # Dict keeping track of which sensor is connected
     self.connected = dict(ble_sc=False, ble_hr=None, gps=False, bmp183=False)
     self.l.info("[SE] Initialising GPS")
     try:
         # Disable GPS (temporary)
         # self.sensors['gps'] = gps_mtk3339(simulate)
         # self.connected['gps'] = True
         self.sensors['gps'] = None
         self.connected['gps'] = False
     except IOError:
         self.sensors['gps'] = None
     self.l.info("[SE] Initialising bmp183 sensor")
     try:
         self.sensors['bmp183'] = bmp183(self.simulate)
         self.connected['bmp183'] = True
     except IOError:
         self.connected['bmp183'] = None
     self.running = True
Exemplo n.º 3
0
'''
    bmp183 - Adafruit BMP183 SPI interface for Raspberry Pi  
    Copyright (C) 2014 Przemo Firszt @ https://github.com/PrzemoF/bmp183

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from bmp183 import bmp183

bmp = bmp183()
bmp.measure_pressure()
print "Temperature: ", bmp.temperature, "deg C"
print "Pressure: ", bmp.pressure/100.0, " hPa"
quit()

#TODO: Log temp/pressure to data file
Exemplo n.º 4
0
#! /usr/bin/python

import time
from bmp183 import bmp183
# Init sensor
bmp = bmp183()
# Start measuring
bmp.start()
# Run printing out results for 60 seconds, every second
run = 0
try:
    while (run != 60):
        print "Temperature: ", bmp.temperature, " deg C"
        print "Pressure: ", bmp.pressure / 100.0, " hPa"
        time.sleep(1)
        run += 1
    # Stop measuring
    bmp.stop()
except:
    # Stop measuring after an error or Ctrl-C
    bmp.stop()
quit()
        # create a new table with a single column called "name"
        # cursor.execute("""CREATE TABLE tutorials (name char(40));""")

        # run a SELECT statement - no data in there, but we can try it
        # cursor.execute("""SELECT * from weatherdata""")
        # rows = cursor.fetchall()
        # print("fetch all: " + str(rows))
    except Exception as e:
        print("Uh oh, can't connect. Invalid dbname, user or password?")
        print(e)

    # Sensors
    logger.info("Getting Sensors Ready:")
    # print(cfg.configs['bmp183']['pin-sck'])
    bmp = bmp183(cfg.configs['bmp183']['pin-sck'],
                 cfg.configs['bmp183']['pin-sdo'],
                 cfg.configs['bmp183']['pin-sdi'],
                 cfg.configs['bmp183']['pin-cs'])

    # mcp = Adafruit_MCP3008.MCP3008(clk=cfg.configs['mcp3008']['pin-clk'],
    #                               cs=cfg.configs['mcp3008']['pin-cs'],
    #                               miso=cfg.configs['mcp3008']['pin-miso'],
    #                               mosi=cfg.configs['mcp3008']['pin-mosi'])
    # Hardware SPI configuration:
    SPI_PORT = 0
    SPI_DEVICE = 0
    mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

    # sensor = RPi_AS3935(address=0x00, bus=1)

    # sensor.set_indoors(True)
    # sensor.set_noise_floor(0)