def main():
    time.sleep(1)
    led = [0, 0, 0]
    while not exitapp:

        p = power_consumption[0] + power_consumption[1] + power_consumption[2]
        basemax = max(maximum[0], maximum[1], maximum[2])
        print "Maximum base:" + str(basemax)
        for i in [0, 1, 2]:
            print phases[i]["uri"], "Current:" + str(power_consumption[i])
            led[i] = map_value_to_leds(basemax, power_consumption[i], 7)
            print led[i]
        arduinoGauge.write(led[0], led[1], led[2])
        time.sleep(0.5)
        setText("Total Power:    " + str(p) + " W")
        setRGB(60, 60, 60)
        time.sleep(10)
        for i in [0, 1, 2]:
            setText("Phase " + str(i + 1) + "         " +
                    str(power_consumption[i]) + " W")
            setRGB(R[i], G[i], B[i])
            time.sleep(5)
Exemplo n.º 2
0
def main():
    time.sleep(1)

    while not exitapp:

        basemax = max(maximum[0], maximum[1], maximum[2])
        print "Maximum base:" + str(basemax)
        for i in [0, 1, 2]:
            print phases[i]["uri"], "This 5 min estimate:" + str(
                power_consumption[i]) + "Wh", "This hour estimate:" + str(
                power_consumption[i] * 12) + "Wh", map_value_to_leds(basemax, power_consumption[i], 7)
        arduinoGauge.write(map_value_to_leds(basemax, power_consumption[0], 7),
                           map_value_to_leds(basemax, power_consumption[1], 7),
                           map_value_to_leds(basemax, power_consumption[2], 7))
        time.sleep(0.5)
        setText("Total Power:    " + str(power) + " Wh")
        setRGB(60, 60, 60)
        time.sleep(10)
        for i in [0, 1, 2]:
            setText("Phase " + str(i + 1) + "         " + str(power_consumption[i]) + " Wh")
            setRGB(R[i], G[i], B[i])
            time.sleep(5)
            current[i] = data[0] / 1000
            power_consumption[i] = (current[i] * 230)
            maximum[i] = data[1] * 230 / 1000


def threaded_function(arg):
    global power_consumption, current, maximum
    while not exitapp:
        getData()


print("Username: \n\t%s\n" % properties.username).encode("utf8", "replace")
print "Sensors:"

arduinoGauge.connect()
arduinoGauge.write(1, 2, 3)

sparkworks.connect(properties.username, properties.password)
for room in properties.the_power_room:
    print '\t%s' % room.decode('utf-8')

room = sparkworks.select_rooms(properties.the_power_room)
phases = sparkworks.current_phases(room[0])

print "\t%s" % phases[0]["uri"]
print "\t%s" % phases[1]["uri"]
print "\t%s" % phases[2]["uri"]
print "Collecting data, please wait..."
getData()

thread = Thread(target=threaded_function, args=(10, ))
def main():
    global text, new_text, dev, ph, timestamp
    time.sleep(1)
    led = [0, 0, 0]
    led_part = [0, 0, 0]
    t = 0
    ph = 0
    new_t = 0
    while not exitapp:
        #detect Button that choose houre
        try:
            if (grovepi.digitalRead(ButtonH)):
                setText("New Houre")
                t = t + 1
                if t == 24:
                    setText("Take new data")
                    t = 0
                time.sleep(.5)
                print "houre" + str(t)
        except IOError:
            print "Button Error"
        #detect button that choose phase
        try:
            if (grovepi.digitalRead(ButtonPh)):
                setText("click...")

                ph = ph + 1
                if ph >= 4:
                    ph = 0
                print "Ph" + str(ph)
                time.sleep(.5)
        except IOError:
            print "Button Error"

        #Show Total Power (dev=0)
        if t == 0:
            getData()

            basemax = max(maximum[0], maximum[1], maximum[2])
            new_text = "Getting data..."
            t = 1

        else:
            if new_t != t:
                new_t = t
                p = power_consumption[0][t - 1] + power_consumption[1][
                    t - 1] + power_consumption[2][t - 1]

                timevalue = datetime.datetime.fromtimestamp((timestamp /
                                                             1000.0) - 3600 *
                                                            (t - 1))
                strtime = timevalue.strftime('%Y-%m-%d %H:%M:%S')
                print strtime
                #print p

                for i in [0, 1, 2]:
                    print phases[i]["uri"], " Current: " + str(
                        float("{0:.2f}".format(current[i][t - 1] / 1000))
                    ) + " A  " + "Power: " + str(
                        float("{0:.2f}".format(
                            power_consumption[i][t - 1] * 230 / 1000))) + " W"
                    led[i] = map_value_to_leds(
                        basemax, power_consumption[i][t - 1] * 230 / 1000, 11)
                    print led[i]
                    time.sleep(.1)
                arduinoGauge.write(led[0], led[1], led[2])

#time.sleep(0.1)
            if ph == 0:
                new_text = strtime + ": " + str(float(
                    "{0:.2f}".format(p))) + "W"
                setRGB(60, 60, 60)
            else:
                new_text = "ph" + str(ph) + ":" + str(
                    float("{0:.2f}".format(
                        power_consumption[ph - 1][t - 1] * 230 / 1000))) + "W"
                setRGB(R[ph - 1], G[ph - 1], B[ph - 1])
                #time.sleep(.1)

        if text != new_text:
            text = new_text
            print "LCD show:", text
            setText(text)
            data = updateData(phases[i])
            power_consumption[i] = data[0]
            maximum[i] = data[1]


def threaded_function(arg):
    global power_consumption, power, maximum
    while not exitapp:
        getData()


print("Username: \n\t%s\n" % properties.username).encode("utf8", "replace")
print "Sensors:"

arduinoGauge.connect()
arduinoGauge.write(3, 2, 1)

sparkworks.connect(properties.username, properties.password)
main_site = sparkworks.main_site()
phases = sparkworks.current_phases(main_site)

print "\t%s" % phases[0]["uri"]
print "\t%s" % phases[1]["uri"]
print "\t%s" % phases[2]["uri"]
print "Collecting data, please wait..."
getData()

thread = Thread(target=threaded_function, args=(10, ))
thread.start()

Exemplo n.º 6
0
    data = updateData(total_power)
    power = data[0]
    print power, power_consumption


def threaded_function(arg):
    global power_consumption, power, maximum
    while not exitapp:
        getData()


print ("Username: \n\t%s\n" % properties.username).encode("utf8", "replace")
print "Sensors:"

arduinoGauge.connect()
arduinoGauge.write(0, 0, 0)

sparkworks.connect(properties.username, properties.password)
main_site = sparkworks.main_site()
phases = sparkworks.power_phases(main_site)
total_power = sparkworks.total_power(main_site)

print "\t%s" % phases[0]["uri"]
print "\t%s" % phases[1]["uri"]
print "\t%s" % phases[2]["uri"]
print ""
print "\t%s" % total_power["uri"]
print ""

print "Collecting data, please wait..."
getData()