def main(config_path):
    """main entry point, load and validate config and call generate"""
    time.sleep(30)  # wait for network after boot
    try:
        with open(config_path) as handle:
            logging.basicConfig(filename='powerPi.log',
                                filemode='w',
                                level=logging.DEBUG)
            logging.info("Powering up\npowerPi v0.0\n%s\n\n",
                         time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

            config = json.load(handle)

            # Set up RPi GPIO pin
            leds = config.get("leds")
            setupGPIO(leds)
            led_strip = rgbled.rgbled(leds.get("red_pin"),
                                      leds.get("green_pin"),
                                      leds.get("blue_pin"))

            # Set up MQTT
            mqtt_cfg = config.get("mqtt", {})
            listen(mqtt_cfg)

            while (1):
                time.sleep(5)

            # generate(host, port, username, password, topic, sensors, interval_ms, verbose)
    except IOError as error:
        print("Error opening config file '%s'" % config_path, error)
Beispiel #2
0
	def wrapper(self):
		logger.info("Starting")
		self.configure()

		request = urllib2.Request(source)
		auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
		request.add_header("Authorization", "Basic %s" % auth)

		GPIO.setwarnings(False)
		GPIO.setmode(GPIO.BOARD)

		GPIO.setup(11, GPIO.OUT)
		self._pwm = PCA9685(0x40, 11)
		self._pwm.frequency(10000)
		self._pwm.enable(True)

		self.curr_r = 0xfff
		self.curr_g = 0xfff
		self.curr_b = 0xfff

		self.led = rgbled(self._pwm, 1, 2, 0)
		self.led.set(0xfff, 0xfff, 0xfff)

		atexit.register(shutdown, self)
		while True:
			try:
				data = urllib2.urlopen(request)
				data = json.load(data)

				logger.info(data)

				next_r = 1.0 - data["rgb"]["red"] / 255.0
				next_g = 1.0 - data["rgb"]["green"] / 255.0
				next_b = 1.0 - data["rgb"]["blue"] / 255.0

				next_r *= 0xfff
				next_g *= 0xfff
				next_b *= 0xfff

				elapsed = time.time() - self.last_config
				if elapsed > rate_reconfig:
					self.configure()

				self.fade(next_r, next_g, next_b)
			except urllib2.HTTPError:
				pass
			except urllib2.URLError:
				pass
			except Exception as ex:
				logger.error(ex)

			time.sleep(self.hold_time)
Beispiel #3
0
# randomly change LED values
from rgbled import rgbled
from random import randint
import time
import math

led = rgbled(22,26,24,100)

try:
    t_end =time.time()+5
    while time.time()<t_end:
    # while True:
        r = randint(0,100)
        g = randint(0,100)
        b = randint(0,100)
        led.changeto(r,g,b,0.5)
        time.sleep(0.25)
    led.off(0.8)
    led.cleanup()    
    

except KeyboardInterrupt:
    led.off(0.8)
    led.cleanup()

    
Beispiel #4
0
# Main Code goes here, wlan is a working network.WLAN(STA_IF) instance.
print("ESP OK")


event_sinks = set()
eventlist = []


def add_to_eventlist(event, e_type=""):
    global eventlist
    if event_sinks:
        eventlist.append((event, e_type))


led = rgbled(26, 25, 33, add_to_eventlist)  # phy 7, 8, 9

loop = asyncio.get_event_loop()


def on_off_switch(pin):
    if any(c > 0 for c in led.colors()):
        led.changeto(0, 0, 0, 0)
    else:
        led.changeto(255, 255, 255, 0)


def toggle_rainbow():
    if led.looping:
        led.looping = False
    else:
Beispiel #5
0
from rgbled import rgbled
from random import randint
import time

led = rgbled(22, 26, 24)

try:
    while True:
        r = randint(0, 100)
        g = randint(0, 100)
        b = randint(0, 100)
        led.changeto(r, g, b, 0.8)
        time.sleep(2)

except KeyboardInterrupt:
    led.off(0.8)
    led.cleanup()
Beispiel #6
0
# change LED values based on sine cos and tan
from rgbled import rgbled
from random import randint
import time
import math

led = rgbled(22, 26, 24, 50)
gatedoutput = lambda n, minn, maxn: max(min(maxn, n), minn)

try:
    for x in range(360):
        r = math.sin(math.radians(x)) * 100
        g = math.cos(math.radians(x)) * 100
        b = math.tan(math.radians(x)) * 100
        #led.changeto(r,g,b,0.5)

        gr = gatedoutput(r, minn, maxn)
        gg = gatedoutput(g, minn, maxn)
        gb = gatedoutput(b, minn, maxn)
        print(gr, gg, gb)
        led.changeto(gr, gg, gb, 0.5)
        time.sleep(0.0125)

    led.off(0.8)
    led.cleanup()

except KeyboardInterrupt:
    led.off(0.8)
    led.cleanup()
Beispiel #7
0
from rgbled import rgbled
from random import randint
import time

led = rgbled(11,9,10)

try:
    while True:
        r = randint(0,100)
        g = randint(0,100)
        b = randint(0,100)
        led.changeto(r,g,b,0.8)
        time.sleep(2)
        
except KeyboardInterrupt:
    led.off(0.8)
    led.cleanup()