Exemplo n.º 1
0
			'9': 9,
			'10': 10,
			'11': 11,
			'12': 19,
			'13': 26
			}

def initGPIO():
	for p in pins:
		pins[str(p)] = GPIO(pins[p], active_high=False)
	

def configureCayenne(MQTT_USRNAME="", MQTT_PASS="", MQTT_CLNT_ID=""):
	client = cayenne.client.CayenneMQTTClient()
	client.on_message = messageReceived
	client.begin(MQTT_USRNAME, MQTT_PASS, MQTT_CLNT_ID)
	return client

def messageReceived(message):
	if message.value == '1':
		pins[str(message.channel)].on()
	else:
		pins[str(message.channel)].off()



if __name__ == "__main__":
	initGPIO()
	client = configureCayenne("f0fbb820-2157-11e8-aeac-8375e928efd4", "44e72dda405b00be56ed7bbdd3b504061e10aa72", "4eff88f0-4b2a-11e9-a6b5-e30ec853fbf2")
	client.loop_forever()
#!/usr/bin/env python
import cayenne.client

# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME  = "******"
MQTT_PASSWORD  = "******"
MQTT_CLIENT_ID = "MQTT_CLIENT_ID"


# The callback for when a message is received from Cayenne.
def on_message(message):
    print("message received: " + str(message))
    # If there is an error processing the message return an error string, otherwise return nothing.

client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
client.loop_forever()

Exemplo n.º 3
0
def connect_cayenne_forever():
    print("Keeping the connection to Cayenne...")
    client.loop_forever()