Пример #1
0
def inloop(textchange = False,activity = False, offset = 0):
      
     if textchange:
       text2.regen()
     if shutterUp.y != -100 and shutterUp.colouring.colour[2] == 1:
        shutterUp.set_position(y=-100)
     if (shutterUp.colouring.colour[2] == 0):
        if shutterUp.y > 0:
          shutterUp.set_position(y=-100)
        shutterUp.set_position(y=(shutterUp.y+2))
        activity = True



     if shutterDown.y != -100 and shutterDown.colouring.colour[2] == 1:
        shutterDown.set_position(y=-100)
     if (shutterDown.colouring.colour[2] == 0):
        if shutterDown.y < -99:
          shutterDown.set_position(y=0)
        shutterDown.set_position(y=(shutterDown.y-2))
        activity = True
       
 

     if peripherals.touch_pressed:
      peripherals.touch_pressed = False     
      if peripherals.clicked(shutterUp.x,shutterUp.y):
        peripherals.controlrelays(config.shutterdown, 0)
        mqttclient.publish("scheinwerfer", '0')
        peripherals.controlrelays(config.shutterup, 1)
        shutterUp.colouring.set_colour([0,1,0])
        shutterUp.set_text(text_format= chr(0xe00f))
        shutterDown.colouring.set_colour([1,1,1])


      elif peripherals.clicked(shutterDown.x,shutterDown.y):
        peripherals.controlrelays(config.shutterup, 0)
        peripherals.controlrelays(config.shutterdown, 1)
        mqttclient.publish("scheinwerfer", '1')
        shutterUp.colouring.set_colour([1,1,1])
        shutterDown.colouring.set_colour([0,1,0])


      else:
        peripherals.controlrelays(config.shutterdown, 0)
        peripherals.controlrelays(config.shutterup, 0)
        shutterUp.colouring.set_colour([1,1,1])
        shutterDown.colouring.set_colour([1,1,1])
        
        
     if offset != 0:
         offset = graphics.slider_change(text2.text, offset)
         if offset == 0:
             text2.regen()
     text2.draw()   
         
     return activity,offset
Пример #2
0
def motion_detected(channel):
    if gpio.input(channel):
        print('motion detected')
        eg_object.motion = True
        if config.startmqttclient:
            mqttclient.publish("motion", 'ON')
    else:
        eg_object.motion = False
        if config.startmqttclient:
            mqttclient.publish("motion", 'OFF')

    eg_object.lastmotion = time.time()
Пример #3
0
def guiEvent(type, args):
    data = json.loads(args)

    mqttclient.init()

    if type == "state":
        GUI.update("state", json.dumps(mqttclient.state()))
    elif type == "connect":
        mqttclient.connect(data["broker_address"], data["username"],
                           data["password"])
    elif type == "disconnect":
        mqttclient.disconnect()
    elif type == "subscribe":
        mqttclient.subscribe(data["topic"])
    elif type == "unsubscribe":
        mqttclient.unsubscribe(data["topic"])
    elif type == "publish":
        mqttclient.publish(data["topic"], data["payload"], data["qos"])
Пример #4
0
def main():
    pinMode(A0, IN)
    mqttclient.init()

    mqttclient.onConnect(on_connect)
    mqttclient.onDisconnect(on_disconnect)
    mqttclient.onSubscribe(on_subscribe)
    mqttclient.onUnsubscribe(on_unsubscribe)
    mqttclient.onPublish(on_publish)
    mqttclient.onMessageReceived(on_message_received)
    print('Client Initialized')

    mqttclient.connect(broker_add, username, password)
    while not mqttclient.state()["connected"]:  #wait until connected
        pass  #do nothing


#	mqttclient.publish("waterLevel","0,0","1");

#countWater = 0
#resultwater = analogRead(0)
#waterCm = (((analogRead(A0)-0)*(21.81- -0)) / (1023-0))+ 0
    tempc = (((analogRead(A0) - 0) * (100 - -100)) / (1023 - 0)) + -100
    while True:
        tempc = (((analogRead(A0) - 0) * (100 - -100)) / (1023 - 0)) + -100
        #waterCm = (((analogRead(A0)-0)*(21.81- -0)) / (1023-0))+ 0
        #print waterCm
        print tempc
        tempSent = str(tempc)
        mqttclient.publish("temp", tempSent, "1")
        #mqttclient.publish("temp",'HIGH',"1");
        """
		if tempc < 20:
			mqttclient.publish("temp",tempSent,"1");
			print tempc
			delay(100);
		elif tempc > 30:
			mqttclient.publish("temp","dont","1");
			delay(100)
		"""

        delay(1000)
Пример #5
0
def main():
    pinMode(A0, IN)
    mqttclient.init()

    mqttclient.onConnect(on_connect)
    mqttclient.onDisconnect(on_disconnect)
    mqttclient.onSubscribe(on_subscribe)
    mqttclient.onUnsubscribe(on_unsubscribe)
    mqttclient.onPublish(on_publish)
    mqttclient.onMessageReceived(on_message_received)
    print('Client Initialized')

    mqttclient.connect(broker_add, username, password)
    while not mqttclient.state()["connected"]:  #wait until connected
        pass  #do nothing


#	mqttclient.publish("waterLevel","0,0","1");

#countWater = 0
#resultwater = analogRead(0)
    waterCm = (((analogRead(A0) - 0) * (21.81 - -0)) / (1023 - 0)) + 0
    while True:

        waterCm = (((analogRead(A0) - 0) * (21.81 - -0)) / (1023 - 0)) + 0
        print waterCm
        waterI = int(waterCm)
        waterSent = str(waterI)
        mqttclient.publish("waterLevel", waterSent, "1")
        """
		if waterCm < 2:
			mqttclient.publish("waterLevel","1,0","1");
			print waterCm
			delay(100);
			#countWater = countWater + 1
		elif waterCm > 15:
			mqttclient.publish("waterLevel","0,0","1");
			delay(100)
		#countWater = countWater + 1
		"""
        delay(1000)
Пример #6
0
def main():
	pinMode(A0,IN)
	mqttclient.init()

	mqttclient.onConnect(on_connect)
	mqttclient.onDisconnect(on_disconnect)
	mqttclient.onSubscribe(on_subscribe)
	mqttclient.onUnsubscribe(on_unsubscribe)
	mqttclient.onPublish(on_publish)
	mqttclient.onMessageReceived(on_message_received)
	print('Client Initialized')

	mqttclient.connect(broker_add,username,password)
	while not mqttclient.state()["connected"]:		#wait until connected
 		pass											#do nothing
 	
 	
#	mqttclient.publish("waterLevel","0,0","1");
	
	humidityp = analogRead(A0)
	print humidityp
	humidityp = (((analogRead(A0)-0)*(100- -0))/(1023-0))+ -0
	while True:
		humidityp = (((analogRead(A0)-0)*(100- -0))/(1023-0))+ -0
		print humidityp
		humiditySent = str(humidityp)
		mqttclient.publish("humidity",humiditySent,"1")
		"""
		if humidityp > 70:
			mqttclient.publish("temp","heat","1");
			print tempc
			delay(100);
		elif humidityp < 60:
			mqttclient.publish("temp","dont","1");
			delay(100)
		"""
		delay(1000)
Пример #7
0
def cliEvent(type, args):
    if type == "invoked" and args[0] == "mqttclient":
        if len(args
               ) < 2 or len(args) > 1 and args[1] == "-?" or args[1] == "/?":
            print_cli_usage()
            CLI.exit()
        elif len(args) > 1 and args[1] != "-?" and args[1] != "/?":
            mqttclient.init()

            if len(args) > 2 and len(args) < 6 and args[1] == "connect":
                username = ""
                password = ""

                if len(args) > 3:
                    username = args[3]

                    if len(args) == 5:
                        password = args[4]

                mqttclient.connect(args[2], username, password)
            elif len(args) == 2 and args[1] == "disconnect":
                mqttclient.disconnect()
            elif len(args) == 3 and args[1] == "subscribe":
                mqttclient.subscribe(args[2])
            elif len(args) == 3 and args[1] == "unsubscribe":
                mqttclient.unsubscribe(args[2])
            elif len(args) == 5 and args[1] == "publish":
                mqttclient.publish(args[2], args[3], args[4])
            elif len(args) == 2 and args[1] == "display-last-message":
                messages = mqttclient.state()["messages"]

                if len(messages) > 0:
                    print messages[-1]

                print ""
                CLI.exit()
            elif len(args) == 2 and args[1] == "display-all-messages":
                messages = mqttclient.state()["messages"]

                for message in messages:
                    print message

                print ""
                CLI.exit()
            elif len(args) == 2 and args[1] == "display-last-event":
                events = mqttclient.state()["events"]

                if len(events) > 0:
                    print events[-1]

                print ""
                CLI.exit()
            elif len(args) == 2 and args[1] == "display-all-events":
                events = mqttclient.state()["events"]

                for event in events:
                    print event

                print ""
                CLI.exit()
            else:
                print_cli_usage()
                CLI.exit()
    elif type == "interrupted":
        CLI.exit()