Example #1
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"])
Example #2
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)
Example #3
0
def main():

    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.subscribe(sub2)

    while True:
        delay(1000)
Example #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
    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)
Example #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");
	
	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)
Example #6
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()