def senddata():
    bmp180.blocking_read()
    temp = bmp180.temperature
    p = bmp180.pressure
    altitude = bmp180.altitude
    print(temp, p, altitude)
    client.celsiusWrite(bmp180TempChannel, temp)
    time.sleep(1)
    client.hectoPascalWrite(bmp180PressChannel, p / 100.0)
    time.sleep(4)
Beispiel #2
0
#!/usr/bin/env python
import cayenne.client
import time
import logging

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


client = cayenne.client.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, loglevel=logging.INFO)
# For a secure connection use port 8883 when calling client.begin:
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883, loglevel=logging.INFO)

i=0
timestamp = 0

while True:
    client.loop()
    
    if (time.time() > timestamp + 10):
        client.celsiusWrite(1, i)
        client.luxWrite(2, i*10)
        client.hectoPascalWrite(3, i+800)
        timestamp = time.time()
        i = i+1
import cayenne.client
import time

# 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)

i=0
timestamp = 0

while True:
    client.loop()
    
    if (time.time() > timestamp + 10):
        client.celsiusWrite(1, i)
        client.luxWrite(2, i*10)
        client.hectoPascalWrite(3, i+800)
        timestamp = time.time()
        i = i+1
Beispiel #4
0
    client = cayenne.client.CayenneMQTTClient()
    client.on_message = on_message
    client.begin(args.username, args.password, args.clientID, args.host, args.port)
    start = time.time()
    while not client.connected:
        client.loop()

    print("Test publishing data")
    client.virtualWrite(0, 0)
    client.celsiusWrite(1, 1)
    client.fahrenheitWrite(2, 2)
    client.kelvinWrite(3, 3)
    client.luxWrite(4, 4)
    client.pascalWrite(5, 5)
    client.hectoPascalWrite(6, 6)

    print("Test receiving commands")
    client.mqttPublish(client.rootTopic + '/cmd/10', 'senderror,0')
    client.mqttPublish(client.rootTopic + '/cmd/11', 'sendok,1')
    client.mqttPublish(client.rootTopic + '/cmd/12', 'done,1')
    
    start = time.time()
    while True:
        loop_start = time.time()
        client.loop()
        if done and (time.time() - loop_start >= 1):
            break
        if (time.time() - start >= 10):
            raise Exception("Timed out while waiting for commands")
        
Beispiel #5
0
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)

i = 0
timestamp = 0

while True:
    client.loop()

    if (time.time() > timestamp + 30):
        a = random.uniform(1.234, 9.876)
        client.celsiusWrite(1, a)
        time.sleep(3)

        b = random.randrange(33, 77)
        client.luxWrite(2, b)
        time.sleep(3)

        c = random.randrange(0, 100, 5)
        client.hectoPascalWrite(3, c)
        time.sleep(3)

        k = random.randint(7, 93)
        client.luxWrite(4, k)

        timestamp = time.time()

        print(timestamp)