Exemplo n.º 1
0
import signal
from time import sleep
import mysql.connector as mariadb
from ADAFRUIT_BME280_LIBRARY import *
import time
import SI1145
import MCP3008
import MyPyDHT

log = logging.getLogger(__name__)
logging.basicConfig(filename='example.log', level=logging.DEBUG)
running = True
sensor_temp_pressure = BME280(t_mode=BME280_OSAMPLE_8,
                              p_mode=BME280_OSAMPLE_8,
                              h_mode=BME280_OSAMPLE_8)
sensor_UV = SI1145.SI1145()
mcp = MCP3008.MCP3008()


def get_data(sql, params=None):
    conn = mariadb.connect(database='weatherstation',
                           user='******',
                           password='******')
    cursor = conn.cursor()
    records = []

    try:
        log.debug(sql)
        cursor.execute(sql, params)
        result = cursor.fetchall()
        for row in result:
Exemplo n.º 2
0
#!/usr/bin/env python

import time
import SI1145
from datetime import datetime

now = datetime.now()
date = now.strftime("%d-%m-%Y")
timelog = now.strftime("%H:%M")

filename = "/data/uv-" + date + ".txt"
filestream = open(filename, 'a', 0)
filestream.write("---\n" + timelog + "\n")

sensor = SI1145.SI1145()

while True:
    print("---")
    IR = sensor.readIR()
    UV = sensor.readUV()

    log = ("IR %.2f | UV %.2f\n" % (IR, UV))
    print(log)
    filestream.write(log)

    time.sleep(60)
Exemplo n.º 3
0
humidity_ceiling = 98

def get_timestamp():
    return time.strftime('%D/%T')

def write_log(to_write):
    f = open('/tmp/sensors.log', 'a')
    f.write(to_write + '\n')
    f.close()

# GrovePi+ port numbers
hcho_sensor = 0
temperature_sensor = 4
water_sensor = 3

light_sensor = SI1145.SI1145()

while True:
    try:
        start = time.time()
        # get the timestamp for obervation
        timestamp = get_timestamp()

    	# get temperature and humidity readings
        [temp, humidity] = grovepi.dht(temperature_sensor, 1)
		
        # get hcho gas reading and voltage
	hcho = grovepi.analogRead(hcho_sensor)
	voltage = float(hcho * 5 / 1024)

	# water status
Exemplo n.º 4
0
import raspitools as rpit  #my own set of tools
import sys
import pdb

LOOP_SLEEP = 10

THINGSPEAKKEY = '8QQ12B7Q5YSZ355T'  #channel: "kasvuboksi"
THINGSPEAKURL = 'https://api.thingspeak.com/update'
LOGINTERVAL = 60  #in seconds

# Connect the Grove Moisture Sensor to analog port A0
# SIG,NC,VCC,GND
PORT_MOISTURE_1 = 0
PORT_MOISTURE_2 = 1

sunlight_i2c = SI1145.SI1145()
# Default constructor will pick a default I2C bus.
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
# from the main GPIO header and the library will figure out the bus number based
# on the Pi's revision.

# Connect the Grove Temperature & Humidity Sensor Pro to digital port D4
# This example uses the blue colored sensor.
# SIG,NC,VCC,GND
PORT_DHT = 5  # The Sensor goes on digital port
# temp_humidity_sensor_type
# Grove Base Kit comes with the blue sensor.
DHT_TYPE = 1  # 0 -> blue colored sensor, 1 -> white colored sensor

PORT_RELAY_1 = 7
grovepi.pinMode(PORT_RELAY_1, "OUTPUT")
Exemplo n.º 5
0
from datetime import datetime
import time
import thread
import SI1145
import RPi.GPIO as GPIO
import MySQLdb
import socket

lightSensor = SI1145.SI1145()
GPIO.setmode(GPIO.BCM)

moistureSensor = 4
    
lightPower = 17
waterPumpPower = 27
fertPumpPower = 22

GPIO.setup(moistureSensor, GPIO.IN)

GPIO.setup(lightPower, GPIO.OUT)
GPIO.setup(waterPumpPower, GPIO.OUT)
GPIO.setup(fertPumpPower, GPIO.OUT)

GPIO.output(lightPower, GPIO.HIGH)
GPIO.output(waterPumpPower, GPIO.HIGH)
GPIO.output(fertPumpPower, GPIO.HIGH)

dayOfWeek = datetime.now().weekday()
product_id = '456789'

class RHGP:
# ============================================================================
# specifies how often to measure values from the Sense HAT (in minutes)
MEASUREMENT_INTERVAL = 5  # minutes
# Set to False when testing the code and/or hardware
# Set to True to enable upload of weather data to Weather Underground
WEATHER_UPLOAD = True
# the weather underground URL used to upload weather data
WU_URL = "http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php"
SINGLE_HASH = "#"
HASHES = "########################################"
SLASH_N = "\n"

air_sensor = 0
temp_hum_pr = TempHumPress()  # Temprasure Humidity Pressure Sensor API
grovepi.pinMode(air_sensor, 'INPUT')
ir_uv_sensor = SI1145.SI1145()
setRGB(0, 179, 255)


def main():
    global last_temp

    # initialize the lastMinute variable to the current time to start
    last_minute = datetime.datetime.now().minute
    # on startup, just use the previous minute as lastMinute
    last_minute -= 1
    if last_minute == 0:
        last_minute = 59

    # infinite loop to continuously check weather values
    while 1:
Exemplo n.º 7
0
 def __init__(self, **kwargs):
     self.sensor = SI1145.SI1145()