示例#1
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)
示例#2
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)
示例#3
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)
示例#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");
	
	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)