Ejemplo n.º 1
0
def uploadData():
    client.loop()
    print(temp.name())
    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    #for i in range(0, 10):
    celsius = temp.value()
    fahrenheit = celsius * 9.0 / 5.0 + 32.0
    print("%d degrees Celsius, or %d degrees Fahrenheit" \
        % (celsius, fahrenheit))
    time.sleep(1)

    # Read values of the light sensor
    lightLux = light.value()
    print(light.name() + " raw value is %d" % light.raw_value() + \
        ", which is roughly %d" % light.value() + " lux")
    time.sleep(1)

    # Wait for Ait quality sensor to warm up - it takes about 3 minutes
    print("Sensor is warming up for 3 minutes...")
    for i in range(1, 4):
        time.sleep(60)
        print(i, "minute(s) passed.")
    print("Sensor is ready!")
    # Read values of Air quality sensor
    airValue = airSensor.getSample()
    ppm = airSensor.getPPM()
    print("raw: %4d" % airValue, " ppm: %5.2f   " % ppm, airQuality(airValue))

    #Uploading data to Cayenne
    print("Uploading data to Cayenne ...")
    client.celsiusWrite(1, celsius)
    client.luxWrite(2, lightLux)
    client.virtualWrite(3, airValue)
Ejemplo n.º 2
0
def dht():
    print("\nInitializing DHT sensor...\n")
    time.sleep(2)
    while True:
        client.loop()
        
        humidity, temperature=Adafruit_DHT.read_retry(11,17)
        if humidity is not None and temperature is not None:
            client.celsiusWrite(1, temperature)
            client.luxWrite(2, humidity)
            print('Temp:{0:0.1f}*C Humidity: {1:0.1f}%'.format(temperature,humidity))
            time.sleep(2)
        else:
            print("\nFailed to get reading...\n")
Ejemplo n.º 3
0
def main():

    # Cayenne authentication info
    MQTT_USERNAME = "******"
    MQTT_PASSWORD = "******"
    MQTT_CLIENT_ID = "cd803190-47fd-11ea-84bb-8f71124cfdfb"

    client = cayenne.client.CayenneMQTTClient()

    client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)

    # Initialise all variables
    starttime = time.time()
    temp, hum, nh3, no2, light, proxim, pressure, curTime = output()
    oldTemp, oldHum, oldNh3, oldNo2, oldLight, oldProxim, oldPressure = temp, hum, nh3, no2, light, proxim, pressure

    while True:
        # Send values to Cayenne
        client.loop()

        client.celsiusWrite(1, temp)
        client.virtualWrite(2, hum)
        client.virtualWrite(3, no2)
        client.virtualWrite(4, nh3)
        client.luxWrite(5, light)
        # client.virtualWrite(6, proxim)

        # Filter inaccurate pressure readings
        if (pressure < 700):
            client.virtualWrite(7, oldPressure)
        else:
            client.virtualWrite(7, pressure)
            oldPressure = pressure

        save()

        # Calculate how long the program has been running for
        timeDiff = time.localtime(time.time() - starttime - 3600)
        runTime = time.strftime("%H:%M", timeDiff)

        display(light, curTime, runTime)

        # Have the program send values once every minute
        time.sleep(60.0 - ((time.time() - starttime) % 60.0))

        # Update values
        oldTemp, oldHum, oldNh3, oldNo2, oldLight, oldProxim = temp, hum, nh3, no2, light, proxim
        temp, hum, nh3, no2, light, proxim, pressure, curTime = output()
Ejemplo n.º 4
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
Ejemplo n.º 6
0
    # length fits to parameter names, parse and store
    if len(sensor_data_arr) == len(sensor_parameter):
        # parse
        sensor_data_dict = {
            sensor_parameter[i]: float(sensor_data_arr[i])
            for i in range(len(sensor_parameter))
        }
        # store
        sensor_data_panda = sensor_data_panda.append(sensor_data_dict,
                                                     ignore_index=True)

        # upload readings to myDevices Cayenne
        client.loop()
        client.celsiusWrite(1, sensor_data_dict["air_temperature"])
        client.virtualWrite(2, sensor_data_dict["air_humidity"], "rel_hum",
                            "p")
        client.celsiusWrite(3, sensor_data_dict["soil_temperature"])
        client.virtualWrite(4, sensor_data_dict["soil_humidity"], "res", "ohm")
        client.luxWrite(5, sensor_data_dict["luminance"])
        clear_output()
        print(sensor_data_arr)
    else:
        clear_output()
        print(sensor_data_str)
        print("Sensor array length does match expected number of parameters.")

#     except:
#         print("Interrupt")
#         ser.close()
#         break
ser.close()
Ejemplo n.º 7
0
    #Change the pin back to input
    GPIO.setup(ldr, GPIO.IN)

    #Count until the pin goes high
    while (GPIO.input(ldr) == 0):
        count += 1

    return count


while True:
    client.loop()

    lux = rc_time(ldr)
    print(lux)
    if (lux > 7000):
        lamp_out = 1

    if (lux <= 7000):
        lamp_out = 0

    if (time.time() > timestamp + 10):
        client.celsiusWrite(1, temp_in)
        client.luxWrite(2, lux)
        client.celsiusWrite(3, temp_out)
        client.umidWrite(5, 67)
        client.digitalWrite(6, movimento)
        client.digitalWrite(7, porta)
        client.tankWrite(8, tankL)
        client.digitalWrite(10, lamp_out)
        timestamp = time.time()
Ejemplo n.º 8
0
try:
    while True:
        # Always call this method every time to send data properly
        client.loop()

        # Read data from DHT11 and BH1750
        result = dht_pin.read()
        if result.is_valid():
            temp = result.temperature
        if BH1750.readLight() is not None:
            light = BH1750.readLight()

        # Setup data for sending to cloud server via MQTT
        client.celsiusWrite(1, temp)
        client.luxWrite(2, light)

        # Turn light On-Off according to environment light
        if light < 25:
            light_state = False
        else:
            light_state = True
        GPIO.output(16, light_state)

        # Notify user when light state change
        if light_state is not light_last_state:
            print("Environment light: %.2f" % light)
            if light_state is False:
                print("Below light level treshold")
                print("Turn light on")
            else:
Ejemplo n.º 9
0
import cayenne.client
import time

# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = "******"
MQTT_PASSWORD = "******"
MQTT_CLIENT_ID = "741b6b30-7962-11e8-861b-e79eceb83d4e"

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

# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = Adafruit_DHT.DHT11

# Example using a Raspberry Pi with DHT sensor
# connected to GPIO23.
pin = 14

while True:
    client.loop()

    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(
            temperature, humidity))
        client.celsiusWrite(1, temperature)
        client.luxWrite(2, humidity)
    else:
        print('Failed to get reading. Try again!')
Ejemplo n.º 10
0
            global done
            done = True

    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):
Ejemplo n.º 11
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)