Ejemplo n.º 1
0
 def __init__(self, upPin, downPin, aPin, bPin, upPort=GPIO, downPort=GPIO, aPort=GPIO, bPort=GPIO):
     self.upPort = GPIO
     self.rollerThread = None
     if upPort!=GPIO :
         self.upPort = deviceInstance(upPort)
     self.upPin = toint(upPin)
     self.upPort.setFunction(self.upPin, GPIO.IN, GPIO.PUD_UP)
         
     self.downPort = GPIO
     if downPort!=GPIO :
         self.downPort = deviceInstance(downPort)
     self.downPin = toint(downPin)
     self.downPort.setFunction(self.downPin, GPIO.IN, GPIO.PUD_UP)
         
     self.aPort = GPIO
     if aPort!=GPIO :
         self.aPort = deviceInstance(aPort)
     self.aPin = toint(aPin)
     self.aPort.setFunction(self.aPin, GPIO.OUT)
         
     self.bPort = GPIO
     if bPort!=GPIO :
         self.bPort = deviceInstance(bPort)
     self.bPin = toint(bPin)
     self.bPort.setFunction(self.bPin, GPIO.OUT)
Ejemplo n.º 2
0
def setup():
    # initialitation Button Home Away
    GPIO.setFunction(7, GPIO.OUT)
    GPIO.setFunction(8, GPIO.OUT)
    GPIO.setFunction(11, GPIO.OUT)
    GPIO.setFunction(17, GPIO.OUT)
    GPIO.setFunction(18, GPIO.OUT)
    GPIO.setFunction(25, GPIO.OUT)
    GPIO.setFunction(27, GPIO.OUT)
    mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration 
    mcp2 = webiopi.deviceInstance("mcp2")
    mcp3 = webiopi.deviceInstance("mcp3")
    mcp4 = webiopi.deviceInstance("mcp4")

    #setting PWM
    GPIO.setFunction(9, GPIO.PWM)
    GPIO.pwmWrite(9, 0)
    GPIO.setFunction(10, GPIO.PWM)
    GPIO.pwmWrite(10, 0)	

    # Setup mcp
    for x in range(0, 8):
      mcp.setFunction(x, GPIO.OUT)

    # Setup mcp2
    for x in range(0, 8):
      mcp2.setFunction(x, GPIO.OUT)

    # Setup mcp3
    for x in range(0, 8):
      mcp3.setFunction(x, GPIO.IN)

    # Setup mcp4
    for x in range(0, 8):
      mcp4.setFunction(x, GPIO.OUT)
		
		
    # Setup mcp2 LOW
    for x in range(0, 8):
      mcp.digitalWrite(x, GPIO.HIGH)

    # Setup mcp2 LOW
    for x in range(0, 8):
      mcp2.digitalWrite(x, GPIO.HIGH)


    # Setup mcp3 active LOW
    for x in range(0, 8):
      mcp3.digitalWrite(x, GPIO.HIGH)

    # Setup mcp4
    for x in range(0, 8):
      mcp4.digitalWrite(x, GPIO.LOW)
    
    
   # retrieve current datetime
    now = datetime.datetime.now()

    # test if we are between ON time and tun the light ON
    initauto(auto,jamon,jamoff,meniton,menitoff,mcp4)
Ejemplo n.º 3
0
def destroy():
    # destroy button Home Away
    GPIO.digitalWrite(7, GPIO.LOW)
    GPIO.digitalWrite(8, GPIO.LOW)
    GPIO.digitalWrite(11, GPIO.LOW)
    GPIO.digitalWrite(17, GPIO.LOW)
    GPIO.digitalWrite(18, GPIO.LOW)
    GPIO.digitalWrite(25, GPIO.LOW)
    GPIO.digitalWrite(27, GPIO.LOW)
    GPIO.setFunction(7, GPIO.IN)
    GPIO.setFunction(8, GPIO.IN)
    GPIO.setFunction(11, GPIO.IN)
    GPIO.setFunction(9, GPIO.IN)
    GPIO.setFunction(10, GPIO.IN)
    GPIO.setFunction(17, GPIO.IN)
    GPIO.setFunction(18, GPIO.IN)
    GPIO.setFunction(25, GPIO.IN)
    GPIO.setFunction(27, GPIO.IN)

    mcp  = webiopi.deviceInstance("mcp")       # retrieve the device named "mcp" in the configuration 
    mcp2 = webiopi.deviceInstance("mcp2")
    mcp3 = webiopi.deviceInstance("mcp3")
    mcp4 = webiopi.deviceInstance("mcp4")
    
    
    # Setup mcp LOW
    for x in range(0, 8):
      mcp.digitalWrite(x, GPIO.HIGH)

    # Setup mcp2y
    for x in range(0, 8):
      mcp2.digitalWrite(x, GPIO.HIGH)

    # Setup mcp3
    for x in range(0, 8):
      mcp3.digitalWrite(x, GPIO.LOW)
    # Setup mcp3

    for x in range(0, 8):
      mcp4.digitalWrite(x, GPIO.LOW)
	
    for x in range(0, 8):
      mcp.setFunction(x, GPIO.IN)

    # Setup mcp2
    for x in range(0, 8):
      mcp2.setFunction(x, GPIO.IN)

    # Setup mcp3
    for x in range(0, 8):
      mcp3.setFunction(x, GPIO.IN)

    # Setup mcp4
    for x in range(0, 8):
      mcp4.setFunction(x, GPIO.IN)
Ejemplo n.º 4
0
      def __init__(self):
         #tmstamp = datetime.datetime.now()
         tmpLR = webiopi.deviceInstance("Living_room")
         celsLR = tmpLR.getCelsius()

         tmpCoolant = webiopi.deviceInstance("Coolant")
         celsCoolant = tmpCoolant.getCelsius()

         self.currMax=celsLR
         self.currMin=celsLR
         self.coolMax=celsCoolant
         self.coolMin=celsCoolant
         self.currTemp = celsLR
         self.coolTemp = celsCoolant
         tmstamp = datetime.datetime.now()
         timeON = datetime.datetime.now()
Ejemplo n.º 5
0
def getBMP085Press():
   global pressure_085
   press0 = webiopi.deviceInstance("bmp")
   pressure_085 = press0.getHectoPascal()  # получение давления
   pressure_085 = pressure_085*0.75        # перевод в мм.рт.ст
   print (pressure_085)
   return "%.2f" % pressure_085 # возврат данных давления в HTML с округлением до сотых
Ejemplo n.º 6
0
def setup():
    global adc
    global dac

    adc = webiopi.deviceInstance('ADC')
    dac = webiopi.deviceInstance('DAC')

    GPIO.setFunction(CCS_GPIO, GPIO.OUT)
    GPIO.setFunction(CVS_GPIO, GPIO.OUT)

    global settings

    settingsfile = os.path.join(os.path.dirname(__file__), 'settings.json')
    settings = ElectronicLoadSettings(settingsfile)

    setOutput(0.0, 'CC')
Ejemplo n.º 7
0
def uploadTowebiopi():
    print("Uploading data to Webiopi")
    serial = webiopi.deviceInstance("serial")
    serial = Serial("ttyAMA0", 2400)
    if (serial.available() > 0):
        data = serial.readString()
        webiopi.sleep(1)
def measure():
    global TempRead
    tmp0 = webiopi.deviceInstance("tmp0")
    # retrieves current temperature 
    TempRead = tmp0.getCelsius() 
    print("Temperature: %.2f" % TempRead)
    return (TempRead)
Ejemplo n.º 9
0
def destroy():
    webiopi.debug("Script with macros - Destroy")
    # Reset GPIO functions
    GPIO.setFunction(SWITCH, GPIO.IN)
    GPIO.setFunction(SERVO, GPIO.IN)
    GPIO.setFunction(LED0, GPIO.IN)
    GPIO.setFunction(LED1, GPIO.IN)
    gpio0 = webiopi.deviceInstance("gpio0")
    gpio0.digitalWrite(0, 1)
Ejemplo n.º 10
0
def destroy():
    webiopi.debug("Script with macros - Destroy")
    # Reset GPIO functions
    GPIO.setFunction(SWITCH, GPIO.IN)
    GPIO.setFunction(SERVO, GPIO.IN)
    GPIO.setFunction(LED0, GPIO.IN)
    GPIO.setFunction(LED1, GPIO.IN)
    gpio0 = webiopi.deviceInstance("gpio0")
    gpio0.digitalWrite(0, 1)
Ejemplo n.º 11
0
def loop():
    if (AUTO):
        tmp = webiopi.deviceInstance("tmp") # retrieve the device named "tmp" in the configuration
        mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration 

        celsius = tmp.getCelsius() # retrieve current temperature
        print("Temperature: %f" % celsius)

        # Turn ON heater when passing below the minimum temperature
        if (celsius < MIN):
            mcp.digitalWrite(HEATER, GPIO.HIGH)

        # Turn OFF heater when reaching maximum temperature
        if (celsius >= MAX):
            mcp.digitalWrite(HEATER, GPIO.LOW)

    # gives CPU some time before looping again
    webiopi.sleep(1)
Ejemplo n.º 12
0
def loop():
   global cel_0
   global num
   tmp0 = webiopi.deviceInstance("temp0")
   tmp085       = webiopi.deviceInstance("bmp")
   cnt = 0
   allTemp      = 0
   allTemp085   = 0
   allTPress085 = 0
   while cnt<60:
      # retrieve current datetime
      now = datetime.datetime.now()
      mOffSecond = HOUR_OFF * 60 * 60 + MIN_OFF * 60
      mOnSecond  = HOUR_ON  * 60 * 60 + MIN_ON  * 60
      mNumSecond = now.hour * 60 * 60 + now.minute * 60 + now.second
      if mNumSecond >= mOffSecond and mNumSecond <= mOnSecond:
         GPIO.digitalWrite(LIGHT,GPIO.LOW)
      else:
         GPIO.digitalWrite(LIGHT,GPIO.HIGH)
      #read temp 
      oneTemp     = tmp0.getCelsius()
      oneTemp085  = tmp085.getCelsius()
      onePress085 = tmp085.getHectoPascal()
      onePress085 = onePress085 * 0.75
      allTemp     = allTemp + oneTemp
      allTemp085  = allTemp085 + oneTemp085
      allPress085 = allTPress085 + onePress085
      time.sleep(5)
      cnt+=1
   avrTemp     = allTemp / 60
   avrTemp085  = allTemp085 / 60
   avrPress085 = allPress085 / 60
   f = open('/usr/share/webiopi/htdocs/ccc/txt/data_18B20.txt','a')
   data_entry = "{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),"%.2f" % avrTemp)
   f.write(data_entry)
   f.close()
   f = open('/usr/share/webiopi/htdocs/ccc/txt/data_tempBMP085.txt','a')
   data_entry = "{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),"%.2f" % avrTemp085)
   f.write(data_entry)
   f.close()
   f = open('/usr/share/webiopi/htdocs/ccc/txt/data_pressBMP085.txt','a')
   data_entry = "{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),"%.2f" % allPress085)
   f.write(data_entry)
   f.close()
Ejemplo n.º 13
0
def loop():

    tmpLR = webiopi.deviceInstance("Living_room")
    celsLR = tmpLR.getCelsius()
    tmpCoolant = webiopi.deviceInstance("Coolant")
    celsCoolant = tmpCoolant.getCelsius()

    global statClass
    statClass.saveTemp(celsLR,celsCoolant)

    if (REQTEMP>=16):
        correct = HYSTER
    else:
        correct = EKONOM

    if (celsLR>(REQTEMP+correct)):
        GPIO.digitalWrite(KOTEL, GPIO.LOW) # off Heater

    if (celsLR<(REQTEMP-correct) and (ignition()==0) ):
        GPIO.digitalWrite(KOTEL, GPIO.HIGH) # on Heater
        statClass.timeON = datetime.datetime.now()

    #qw =  (datetime.datetime.now()- statClass.timeON).seconds


    if (ignition()==1 and (datetime.datetime.now()- statClass.timeON).seconds>60):
        statClass.addOnMinute()
        statClass.timeON =datetime.datetime.now()

    # toggle light ON all days at the correct time
    #if (now.minute != datetime.datetime.now().minute ):
    #    if (GPIO.digitalRead(KOTEL) == GPIO.LOW):
    #        GPIO.digitalWrite(KOTEL, GPIO.HIGH)

    #    else:
    #        (GPIO.digitalRead(KOTEL) == GPIO.HIGH)
    #        GPIO.digitalWrite(KOTEL, GPIO.LOW)

    #    global now
    #    now = datetime.datetime.now()

    # gives CPU some time before looping again
    webiopi.sleep(3)
Ejemplo n.º 14
0
def setup():
    global tmp, celsius, BPM, flag
    flag = 0
    BPM = 0
    tmp = webiopi.deviceInstance(
        "temp2")  # retrieve the device named "mcp" in the configuration
    #GPIO.setFunction(HR, GPIO.IN) #Set the pin to be an Input
    #GPIO.setup(HR, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(HR, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(HR, GPIO.RISING, callback=HR_callback)
    webiopi.debug("HR script - Setup")
Ejemplo n.º 15
0
def loop():
    if (AUTO):
        dht = webiopi.deviceInstance("dht0")

        celsius = dht.getCelsius() # get current temperature
        if (celsius < MIN):
            GPIO.digitalWrite(LIGHT, GPIO.HIGH)
        if (celsius > MAX):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)

    webiopi.sleep(1)
Ejemplo n.º 16
0
 def logTowebiopi(self, uploading=None):
     if uploading is not None:
         self.uploading = uploading
     if self.uploading:
         port.flushInput()
         print "Logging to Webiopi"
         serial = webiopi.deviceInstance("serial")
         serial = Serial("ttyAMA0", 2400)
         if (serial.available() > 0):
             data = serial.readString()
             webiopi.sleep(1)
         self.master.after(1, self.logTowebiopi)
 def logTowebiopi(self, uploading=None):
     if uploading is not None:
         self.uploading = uploading
         print "Please choose an option to log data to... "
     if self.uploading:
         port.flushInput()  #Empty serial buffer
         print "Logging to Webiopi"
         serial = webiopi.deviceInstance("serial")
         serial = Serial("ttyAMA0", 2400)
         if (serial.available() > 0):  #Uploads to Webiopi
             data = serial.readString()
             webiopi.sleep(1)
         self.master.after(1, self.logTowebiopi)
Ejemplo n.º 18
0
def setup():
    webiopi.debug("Script with macros - Setup")
    # Setup GPIOs
    GPIO.setFunction(SWITCH, GPIO.IN)
    GPIO.setFunction(SERVO, GPIO.PWM)
    GPIO.setFunction(LED0, GPIO.PWM)
    GPIO.setFunction(LED1, GPIO.OUT)
    
    GPIO.pwmWrite(LED0, 0.5)        # set to 50% ratio
    GPIO.pwmWriteAngle(SERVO, 0)    # set to 0 (neutral)
    GPIO.digitalWrite(LED1, GPIO.HIGH)
    
    gpio0 = webiopi.deviceInstance("gpio0")
    gpio0.digitalWrite(0, 0)
Ejemplo n.º 19
0
def setup():
    webiopi.debug("Script with macros - Setup")
    # Setup GPIOs
    GPIO.setFunction(SWITCH, GPIO.IN)
    GPIO.setFunction(SERVO, GPIO.PWM)
    GPIO.setFunction(LED0, GPIO.PWM)
    GPIO.setFunction(LED1, GPIO.OUT)

    GPIO.pwmWrite(LED0, 0.5)  # set to 50% ratio
    GPIO.pwmWriteAngle(SERVO, 0)  # set to 0 (neutral)
    GPIO.digitalWrite(LED1, GPIO.HIGH)

    gpio0 = webiopi.deviceInstance("gpio0")
    gpio0.digitalWrite(0, 0)
Ejemplo n.º 20
0
def loop():
    global tmp, celsius, flag, Count, Pulse, BPM
    Count = Count + 1
    tmp = webiopi.deviceInstance("temp2")
    celsius = "%.2f" % (tmp.getCelsius())  # retrieve current temperature
    print(celsius)
    print(BPM)
    #print("Temperature: %0.2f" % celsius)
    #GPIO.add_event_detect(HR, GPIO.RISING, callback=hr_callback, bouncetime=000)
    # gives CPU some time before looping again
    webiopi.sleep(1)
    if (Count > 10):
        print(Pulse)
        BPM = Pulse * 3
        Count = 0
        Pulse = 0
Ejemplo n.º 21
0
def setup():
    global DIO
    webiopi.debug("Thermometer script - Setup")
    
    # Setup digital IO ports for RGB LED
    DIO = webiopi.deviceInstance("digio")
    DIO.setFunction(REDPORT, OUT)
    DIO.setFunction(GREENPORT, OUT)
    DIO.setFunction(BLUEPORT, OUT)

    # Blink white 5 x
    for i in range(5):
        white()
        webiopi.sleep(0.5)
        black()
        webiopi.sleep(0.5)
Ejemplo n.º 22
0
def loop():

    thermometer = webiopi.deviceInstance("temp")
    
    temperature = thermometer.getCelsius()
    
    if temperature > 27:
        red()
    elif temperature > 26.5:
        yellow()
    elif temperature > 26:
        green()
    elif temperature > 25.5:
        cyan()
    elif temperature > 25:
        blue()
    else:
        magenta()
        
    webiopi.sleep(0.5)        
Ejemplo n.º 23
0
def loop():
    global current

    temp = webiopi.deviceInstance("temp1")

    current.temp = temp.getCelsius()
    current.humidity = temp.getHumidity()

#    webiopi.debug(current.temp)

    runner.updateTime(config, current)

    updateGPIO(LIGHT, current.day)
    updateGPIO(PUMP, current.pump)

    updateGPIO(FAN, current.fan)
    updateGPIO(FANHIGH, current.fanHigh)

    updateGPIO(BRUM, current.brum)
    updateGPIO(BRUMFAN, current.brumFan)
    
    logger.log(current)

    webiopi.sleep(5)
Ejemplo n.º 24
0
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

# This script shows the solution for regular PWM devices.

# Imports
import webiopi

# Enable debug output
webiopi.setDebug()

# Retrieve PWM device assuming you want to use device named "mypwm" from config
PWMDEVICE = webiopi.deviceInstance("mypwm")

# assuming you want to control PWM channel 0, otherwise change number
PWMPORT = 0


# Called by WebIOPi at script loading
def setup():
    global PWMDEVICE
    webiopi.debug("PWM script - Setup")
    PWMDEVICE.pwmWriteFloat(PWMPORT, 0.0)  # set to 0% ratio


# Called by WebIOPi at server shutdown
def destroy():
    global PWMDEVICE
Ejemplo n.º 25
0
import webiopi
from webiopi import deviceInstance
import datetime
import time
from time import strftime
import sys

DHTPIN = 17
num = 0
cel_2 = 30
while True:
    if (num == 2):
        print("begin")
        tmp0 = webiopi.deviceInstance("temp0")
        cel_0 = tmp0.getCelsius()
        cel_0 = 21
        if cel_0 != cel_2:
            data_entry = "{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),
                                            "%.2f" % cel_0)
            print(data_entry)
            cel_2 = cel_0
        num = 0
    num += 1
    time.sleep(1)  # gives CPU some time before looping again
Ejemplo n.º 26
0
rvc = port.readline()
root = Tk()
root.title("Data Logger Control Panel")
label_1 = Label(text="Hello")
label_1.pack()
root.mainloop()

while True:
    if (rvc):
        print("Serial # = " + repr(rvc))
        print("Uploading to Plotly")
        stream.write({'x': datetime.datetime.now(), 'y': rvc})
        time.sleep(0.1)  # delay between stream posts

        print("Logging to File...")
        now = datetime.datetime.now()
        timenow = now.strftime("%Y-%m-%d %H:%M")
        logfile = open("templog.txt", "a")
        logfile.write(timenow)
        logfile.write(" ")
        logfile.write(rvc)
        logfile.close

        print("Uploading data to Webiopi")
        serial = webiopi.deviceInstance("serial")
        serial = Serial("ttyAMA0", 2400)
        if (serial.available() > 0):
            data = serial.readString()
            webiopi.sleep(1)
Ejemplo n.º 27
0
# imports
import webiopi
import time
from webiopi import deviceInstance
#L298N port define
ena = 8
enb = 13
in1 = 9
in2 = 10
in3 = 11
in4 = 12
# Enable debug output
webiopi.setDebug()
#instantiate device
pca = webiopi.deviceInstance("pwm0")
pca.pwmCount()
max = pca.pwmMaximum()
speed = 3095

#set the speed of two motors
def set_speed(motorspeed):
    pca.pwmWrite(ena,motorspeed)

    pca.pwmWrite(enb,motorspeed)
#robot go ahead
@webiopi.macro
def go_forward():
        set_speed(speed)
	
        pca.pwmWrite(in1,max) #IN1
        pca.pwmWrite(in2,0)   #IN2
Ejemplo n.º 28
0
def getTmp0():
   global celsius_0
   tmp0 = webiopi.deviceInstance("temp0")
   celsius_0 = tmp0.getCelsius()  # получение температуры
   print (celsius_0)
   return "%.2f" % celsius_0 # возврат данных температуры в HTML с округлением до сотых
import os
pygame.mixer.init()
from webiopi import deviceInstance

# *********************************************************************************
# Setup
# *********************************************************************************

# Initial setup and constants
webiopi.setDebug()
GPIO = webiopi.GPIO
OFF = GPIO.HIGH
ON = GPIO.LOW

# Relay modual setup
relay1 = deviceInstance("relay1")
relay2 = deviceInstance("relay2")
relay3 = deviceInstance("relay3")
relayMax = 25 

#Sound Setup
soundMain = str(os.path.dirname(os.path.realpath(__file__))) + "/Sound/"
typeOne = "Type1/"
typeTwo = "Type2/"
typeThree = "Type3/"
typeFour = "Type4/"
class SoundStat:
  onBool = False
  def __init__(self):
    pass
Ejemplo n.º 30
0
import webiopi

serial = webiopi.deviceInstance("serial0")

webiopi.setDebug()

@webiopi.macro
def D0_TurnOn():
	webiopi.debug("Script Started...")
	serial.writeBytes([0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x6C, 0x01, 0x9F, 0x00, 0x02, 0x02, 0x44, 0x30, 0x05, 0x69])
	webiopi.debug("serial written")

@webiopi.macro
def D0_TurnOff():
	webiopi.debug("D0_TurnOff...")
	serial.writeBytes([0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x6C, 0x01, 0x9F, 0x00, 0x02, 0x02, 0x44, 0x30, 0x04, 0x6A])
	webiopi.debug("serial written")

@webiopi.macro
def D1_TurnOn():
	webiopi.debug("D0_TurnOff...")
	serial.writeBytes([0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x6C, 0x01, 0x9F, 0x00, 0x02, 0x02, 0x44, 0x31, 0x05, 0x68])
	webiopi.debug("serial written")

@webiopi.macro
def D1_TurnOff():
	webiopi.debug("D0_TurnOff...")
	serial.writeBytes([0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x6C, 0x01, 0x9F, 0x00, 0x02, 0x02, 0x44, 0x31, 0x04, 0x69])
	webiopi.debug("serial written")

def setup():
Ejemplo n.º 31
0
import webiopi
import time
from subprocess import *
import json
from time import sleep, strftime
from datetime import datetime
from webiopi import deviceInstance
from array import *
from random import randint

GPIO = webiopi.GPIO

tsl = deviceInstance("tsl")

#Raspberry Pi GPIO pin numbers assigned to variables
LCD_RS = 7
LCD_E = 8
LCD_D4 = 11
LCD_D5 = 9
LCD_D6 = 10
LCD_D7 = 25

#Other LCD variables (code used thanks to RaspberryPiIVBeginners from youtube.com)
LCD_WIDTH = 16
LCD_CHR = True
LCD_CMD = False

LCD_LINE_1 = 0x80
LCD_LINE_2 = 0xC0

E_PULSE = 0.00005
Ejemplo n.º 32
0
import webiopi
from webiopi import deviceInstance
import sqlite3
import sys
import time

GPIO = webiopi.GPIO
tempSensor = deviceInstance("tmp")
SCRIPT_PATH = "/home/pi/HydroP/python/"

dbconn = sqlite3.connect(SCRIPT_PATH + "hydro.db")
dbconn.row_factory = sqlite3.Row
dbcursor = dbconn.cursor()

dbcursor.execute("SELECT status, interval FROM devices WHERE name = 'TEMP4' VALUES (?, ?);", (status, interval))


while (status == 1):

	temp = tempSensor.getFahrenheit()
	rightNah = time.gmtime()
	dbcursor.execute("INSERT INTO temperatures('device', 'timestamp', 'temperature') VALUES (?, ?, ?);", ("TEMP4", rightNah, temp))
	dbconn.commit()
	webiopi.sleep(interval)
Ejemplo n.º 33
0
def setup():
    global tempsensor
    global pressensor
    tempsensor = webiopi.deviceInstance(DEVICENAMETEMP)
    pressensor = webiopi.deviceInstance(DEVICENAMEPRES)
Ejemplo n.º 34
0
def destroy():
    mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration 
    mcp.digitalWrite(HEATER, GPIO.LOW) # turn off to avoid over heating
Ejemplo n.º 35
0
import webiopi
import datetime
from webiopi import deviceInstance
temp = deviceInstance("temp0")
GPIO = webiopi.GPIO

LIGHT = 17 # GPIO pin using BCM numbering

HOUR_ON  = 8  # Turn Light ON at 08:00
HOUR_OFF = 18 # Turn Light OFF at 18:00


# setup function is automatically called at WebIOPi startup
def setup():
    # set the GPIO used by the light to output
    GPIO.setFunction(LIGHT, GPIO.OUT)

    # retrieve current datetime
    now = datetime.datetime.now()

    # test if we are between ON time and tun the light ON
    if ((now.hour >= HOUR_ON) and (now.hour < HOUR_OFF)):
        GPIO.digitalWrite(LIGHT, GPIO.HIGH)

# loop function is repeatedly called by WebIOPi
def loop():
    # retrieve current datetime
    now = datetime.datetime.now()
    print( now.hour, HOUR_ON)
    print(temp.getCelsius())
Ejemplo n.º 36
0
HOT = 79.0

# RGB LED GPIO pins
RED = 11
GREEN = 9
BLUE = 10

# Switch GPIO
# Next version of WebIOPi should support interrupts (better approach)
SWITCH = 18

# Display State: Current Temperature or Temperature Range
displayCurrent = False

# Set temperature sensor (specified in WebIOPi config)
t = webiopi.deviceInstance("ServerRoom")

# Initialize temperature range variables
tLow = t.getFahrenheit()
tHigh = t.getFahrenheit()

# WH1602B-CTI Colors at 3.3V
Colors = {'Red':         (0.0,1.0,1.0),
          'Green':       (1.0,0.0,1.0),
          'Blue':        (1.0,1.0,0.0),
          'Purple':      (0.0,1.0,0.0),
          'Chartreuse':  (0.0,0.0,1.0),
          'Cyan':        (1.0,0.0,0.0),
          'Aquamarine':  (1.0,0.0,0.5),
          'Turquoise':   (1.0,0.5,0.0),
          'Violet':      (0.0,1.0,0.5),
Ejemplo n.º 37
0
import webiopi

pca =  webiopi.deviceInstance("pwm0")

def ServoMin():
    pca.pwmWriteAngle(15, -45.0)

# setup function is automatically called at WebIOPi startup
def setup():
    global state
    state={'red':0,'green':0,'blue':0,'bright':0}
    update("started")
    #state=#load old state written in JSON


# loop function is repeatedly called by WebIOPi
def loop():
    pass

# destroy function is called at WebIOPi shutdown
def destroy():
    #save state to reload later
    pass

def apply(red,green,blue,bright):
    finale_red   = red*bright/10000.0
    finale_green = green*bright/10000.0
    finale_blue  = blue*bright/10000.0
    pca.pwmWriteFloat(0,green)
    pca.pwmWriteFloat(1,blue)
    pca.pwmWriteFloat(2,red)
Ejemplo n.º 38
0
HOT = 79.0

# RGB LED GPIO's
RED = 11
GREEN = 9
BLUE = 10

# Switch GPIO
# Next version of WebIOPi should support interrupts (better approach)
SWITCH = 18

# Display State: Current Temperature or Temperature Range
displayCurrent = False

# Set temperature sensor (specified in WebIOPi config)
t = deviceInstance("ServerRoom")

# Initialize temperature range variables
tLow = t.getFahrenheit()
tHigh = t.getFahrenheit()

# Hour Counter
hourCounter = datetime.datetime.now().hour

# Critical flag
criticalSent = False

# Web Service URI
# *** YOU MUST CHANGE TO THE IP OF YOUR WEB SERVER ***
URI = 'http://(IP.ADDRESS):8000/'
Ejemplo n.º 39
0
import webiopi
from webiopi import deviceInstance
import sqlite3
import sys
import time

GPIO = webiopi.GPIO
tempSensor = deviceInstance("tmp")
SCRIPT_PATH = "/home/pi/HydroP/python/"

dbconn = sqlite3.connect(SCRIPT_PATH + "hydro.db")
dbconn.row_factory = sqlite3.Row
dbcursor = dbconn.cursor()

dbcursor.execute(
    "SELECT status, interval FROM devices WHERE name = 'TEMP3' VALUES (?, ?);",
    (status, interval))

while (status == 1):

    temp = tempSensor.getFahrenheit()
    rightNah = time.gmtime()
    dbcursor.execute(
        "INSERT INTO temperatures('device', 'timestamp', 'temperature') VALUES (?, ?, ?);",
        ("TEMP3", rightNah, temp))
    dbconn.commit()
    webiopi.sleep(interval)
Ejemplo n.º 40
0
def setup():
    g0 = webiopi.deviceInstance("g0") # retrieve the device named "mcp" in the configuration 
    g0.setFunction(1, GPIO.OUT)
Ejemplo n.º 41
0
import webiopi
import datetime
from webiopi import deviceInstance
temp = deviceInstance("temp0")
GPIO = webiopi.GPIO

LIGHT = 17  # GPIO pin using BCM numbering

HOUR_ON = 8  # Turn Light ON at 08:00
HOUR_OFF = 18  # Turn Light OFF at 18:00


# setup function is automatically called at WebIOPi startup
def setup():
    # set the GPIO used by the light to output
    GPIO.setFunction(LIGHT, GPIO.OUT)

    # retrieve current datetime
    now = datetime.datetime.now()

    # test if we are between ON time and tun the light ON
    if ((now.hour >= HOUR_ON) and (now.hour < HOUR_OFF)):
        GPIO.digitalWrite(LIGHT, GPIO.HIGH)


# loop function is repeatedly called by WebIOPi
def loop():
    # retrieve current datetime
    now = datetime.datetime.now()
    print(now.hour, HOUR_ON)
    print(temp.getCelsius())
Ejemplo n.º 42
0
def getBMP085Temp():
   global celsius_085
   tmp085 = webiopi.deviceInstance("bmp")
   celsius_085 = tmp085.getCelsius()  # получение температуры
   print (celsius_085)
   return "%.2f" % celsius_085 # возврат данных температуры в HTML с округлением до сотых
Ejemplo n.º 43
0
 def __init__(self):
     self.meteo = webiopi.deviceInstance("bmp")
     self.type = "meteo"
Ejemplo n.º 44
0
import webiopi
from webiopi import deviceInstance
import datetime
import time
from time import strftime
import sys

num = 0

while True:
    if (num == 2):
        print("begin")
        tmp085 = webiopi.deviceInstance("bmp")
        cel_0 = tmp085.getHectoPascal()
        data_entry = "{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),
                                        "%.2f" % cel_0)
        print(data_entry)
        num = 0
    num += 1
    time.sleep(1)  # gives CPU some time before looping again
Ejemplo n.º 45
0
 def __init__(self):
     self.meteo = webiopi.deviceInstance("bmp") 
     self.type = "meteo"
Ejemplo n.º 46
0
import webiopi
import time
from subprocess import *
import json
from time import sleep, strftime
from datetime import datetime
from webiopi import deviceInstance
from array import *
from random import randint
GPIO = webiopi.GPIO

tsl = deviceInstance("tsl")


#Raspberry Pi GPIO pin numbers assigned to variables
LCD_RS = 7
LCD_E = 8
LCD_D4 = 11
LCD_D5 = 9
LCD_D6 = 10
LCD_D7 = 25

#Other LCD variables (code used thanks to RaspberryPiIVBeginners from youtube.com)
LCD_WIDTH = 16
LCD_CHR = True
LCD_CMD = False

LCD_LINE_1 = 0x80
LCD_LINE_2 = 0xC0

E_PULSE = 0.00005
Ejemplo n.º 47
0
#do CPU ad GPU temperature calculations
def get_cpu_temp():
    cTemp = os.popen('vcgencmd measure_temp').readline()
    rawC = cTemp.replace("temp=","").replace("'C\n","")
    rawC2 = float(rawC)
    return float(1.8*rawC2)+32
 
def get_gpu_temp():
    gTemp = os.popen("/opt/vc/bin/vcgencmd measure_temp").readline()
    rawG = gTemp.replace("temp=","").replace("'C\n","")
    rawG2 = float(rawG)
    return float(1.8*rawG2)+32

# Set temperature sensor (specified in WebIOPi config)
t = deviceInstance("Shop")

# Initialize temperature range variables
tShopLow = t.getFahrenheit()
tShopHigh = t.getFahrenheit()
tGpuHigh = float(get_gpu_temp())
tGpuLow = float(get_gpu_temp())
tCpuHigh = float(get_cpu_temp())
tCpuLow = float(get_cpu_temp())

# Called by WebIOPi at script loading
def setup():
    webiopi.debug("Script with macros - Setup")
    # Setup GPIOs
    GPIO.setFunction(RED, GPIO.PWM)
    GPIO.setFunction(GREEN, GPIO.PWM)
Ejemplo n.º 48
0
# ADC pin for temperature
# ADC pin for humidity

#Variables
# ADC high and low thresholds for moisture sensors
M1LOW = 200
M1HIGH = 800
M2LOW = 0
M2HIGH = 400
M3LOW = 0
M3HIGH = 800
M4LOW = 200
M4HIGH = 400
M5LOW = 0
M5HIGH = 400
mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration

# setup function is automatically called at WebIOPi startup
def setup():
	# set the GPIO direction for each pin.
	GPIO.setFunction(P1, GPIO.OUT)
	GPIO.setFunction(S1, GPIO.OUT)
	GPIO.setFunction(S2, GPIO.OUT)
	GPIO.setFunction(S3, GPIO.OUT)
	GPIO.setFunction(S4, GPIO.OUT)
	GPIO.setFunction(S5, GPIO.OUT)
	GPIO.setFunction(LOWWATER, GPIO.IN, GPIO.PUD_DOWN)


# loop function is repeatedly called by WebIOPi 
def loop():
Ejemplo n.º 49
0
def setup():
    global sensor
    sensor = webiopi.deviceInstance(DEVICENAME)
Ejemplo n.º 50
0
def loop():
    if (AUTO):
        tmp  = webiopi.deviceInstance("tmp")   # retrieve the device named "tmp" in the configuration
        mcp  = webiopi.deviceInstance("mcp")   # retrieve the device named "mcp" in the configuration 
        mcp2 = webiopi.deviceInstance("mcp2")
        mcp3 = webiopi.deviceInstance("mcp3")
        mcp4 = webiopi.deviceInstance("mcp4")

		
        celsius = tmp.getCelsius() # retrieve current temperature
        print("Temperature: %f" % celsius)
        now = datetime.datetime.now()
        print "jam sekarang = %d:%d:%d"%(now.hour,now.minute,now.second)
        print "set point : %d"%TEMP
#        getsetpoint()
        match(auto,jamon,jamoff,meniton,menitoff,mcp4)

        if (now.second<2):
           print "auto = %d,%d,%d,%d,%d,%d,%d,%d"%(auto[0],auto[1],auto[2],auto[3],auto[4],auto[5],auto[6],auto[7])
	   print "jam on = %d,%d,%d,%d,%d,%d,%d,%d"%(jamon[0],jamon[1],jamon[2],jamon[3],jamon[4],jamon[5],jamon[6],jamon[7])
	   print "jam off = %d,%d,%d,%d,%d,%d,%d,%d"%(jamoff[0],jamoff[1],jamoff[2],jamoff[3],jamoff[4],jamoff[5],jamoff[6],jamoff[7])
	   print "menit on = %d,%d,%d,%d,%d,%d,%d,%d"%(meniton[0],meniton[1],meniton[2],meniton[3],meniton[4],meniton[5],meniton[6],meniton[7])
	   print "menit off = %d,%d,%d,%d,%d,%d,%d,%d"%(menitoff[0],menitoff[1],menitoff[2],menitoff[3],menitoff[4],menitoff[5],menitoff[6],menitoff[7])
		

            

            
        #motor dengan sensor temperature
        if int (GPIO.digitalRead(25)) == 1 :

          if (celsius <= 29-T):
              GPIO.pwmWrite(9, 0)

          if (T < celsius < (T+0.05)):
              GPIO.pwmWrite(9, 0.05)
          if ((T+0.05) <= celsius < (T+0.1)):
              GPIO.pwmWrite(9, 0.1)

          if ((T+0.1)<= celsius < (T+0.15)):
              GPIO.pwmWrite(9, 0.15)
          if ((T+0.15) <= celsius < (T+0.2)):
              GPIO.pwmWrite(9, 0.2)

          if ((T+0.2) <= celsius < (T+0.25)):
              GPIO.pwmWrite(9, 0.25)
          if ((T+0.25) <= celsius < (T+0.3)):
              GPIO.pwmWrite(9, 0.3)

          if ((T+0.3) <= celsius < (T+0.35)):
              GPIO.pwmWrite(9, 0.35)
          if ((T+0.35) <= celsius < (T+0.4)):
              GPIO.pwmWrite(9, 0.4)

          if ((T+0.4) <= celsius < (T+0.45)):
              GPIO.pwmWrite(9, 0.45)
          if ((T+0.45) <= celsius < (T+0.5)):
              GPIO.pwmWrite(9, 0.5)

          if ((T+0.5) <= celsius < (T+0.55)):
              GPIO.pwmWrite(9, 0.55)
          if ((T+0.55) <= celsius < (T+0.6)):
              GPIO.pwmWrite(9, 0.6)

          if ((T+0.6) <= celsius < (T+0.65)):
              GPIO.pwmWrite(9, 0.65)
          if ((T+0.65) <= celsius < (T+0.7)):
              GPIO.pwmWrite(9, 0.7)

          if ((T+0.7) <= celsius < (T+0.75)):
              GPIO.pwmWrite(9, 0.75)
          if ((T+0.75) <= celsius < (T+0.8)):
              GPIO.pwmWrite(9, 0.8)

          if ((T+0.8) <= celsius < (T+0.85)):
              GPIO.pwmWrite(9, 0.85)
          if ((T+0.85) <= celsius < (T+0.99)):
              GPIO.pwmWrite(9, 0.9)


          if (celsius >= (T+1)):
              GPIO.pwmWrite(9, 1)




    # retrieve current datetime
    now = datetime.datetime.now()
    if (now.second==0):
        match(auto,jamon,jamoff,meniton,menitoff,mcp4)

 # setting button Home Away
  #HOME
    if int (GPIO.digitalRead(7)) == 1 and int (GPIO.digitalRead(11)) == 0 :
      for x in range(0, 8):
         mcp.digitalWrite(x, GPIO.LOW)
         mcp2.digitalWrite(x, GPIO.LOW)
         mcp4.digitalWrite(x, GPIO.HIGH)
      GPIO.digitalWrite(7,GPIO.LOW)
    #Away
    elif int (GPIO.digitalRead(11)) == 1 and int (GPIO.digitalRead(7)) == 0:
      mcp4.digitalWrite(0, GPIO.LOW)
      for x in range(0, 8):
         mcp.digitalWrite(x, GPIO.HIGH)
         mcp2.digitalWrite(x, GPIO.HIGH)
      for x in range(1, 8):
         mcp4.digitalWrite(x, GPIO.LOW)
      GPIO.digitalWrite(7,GPIO.LOW)

    if int (GPIO.digitalRead(8)) == 1 :
      for x in range(0, 8):
         mcp.digitalWrite(x, GPIO.HIGH)
         mcp2.digitalWrite(x, GPIO.HIGH)
         mcp4.digitalWrite(x, GPIO.LOW)
      webiopi.sleep(0.2)
      for x in range(0, 8):
         mcp.digitalWrite(x, GPIO.LOW)
         mcp2.digitalWrite(x, GPIO.LOW)
         mcp4.digitalWrite(x, GPIO.HIGH)          


    # gives CPU some time before looping again
    webiopi.sleep(1)
	def __command__(self, channel, diff):
		d = [0x00, 0x00]
		d[0] |= 1 << 6					# start
		d[0] |= (not diff) << 5			# SGL
		d[0] |= (channel & 0x01) << 4	# Ch
		d[0] |= (1) << 3				# MBSF
		return d

	def __analogRead__(self, channel, diff):
		data = self.__command__(channel, diff)
		r = self.xfer(data)
		return ((r[0] & self.MSB_MASK) << 8) | r[1]

GPIO = webiopi.GPIO
pwm0 = deviceInstance("pwm0")

PIN_L1 = 6
PIN_L2 = 5
PIN_R1 = 13
PIN_R2 = 19
PIN_SUB1 = 20
PIN_SUB2 = 21

Foot = 0
ServoTop = 0
ServoLower = -3

g_mode = 0
g_percentage = 50
g_percentageSUB = 100
Ejemplo n.º 52
0
def setup():
    mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration 
    mcp.setFunction(HEATER, GPIO.OUT)
import webiopi
import time
import threading
import pygame
import glob
import random
pygame.mixer.init()
from webiopi import deviceInstance

# Enable debug output
webiopi.setDebug()

# Device setup
GPIO = webiopi.GPIO
relay = deviceInstance("relay")
#io = deviceInstance("io")
pwm = deviceInstance("pwm")
OFF = GPIO.HIGH
ON = GPIO.LOW

#Sound Setup
soundMain = "/home/pi/Hsounds/"
typeOne = "Type1/"
typeTwo = "Type2/"
typeThree = "Type3/"
typeFour = "Type4/"
class SoundStat:
  onBool = False
  def __init__(self):
    pass