示例#1
0
CLIENT_ID = "d6accfc0-6541-11e9-bdb5-dfd20f02ea3f"

intensityChannel = 1
illuminationLedChannel = 2
indicatorLedChannel = 3

# create adc and the led object
adc = ADC(0)
illuminationLed = Pin(16, Pin.OUT)
global count, ledValue
count = 0
ledValue = 0
# switch LED off
illuminationLed.value(ledValue)

cayenne = Cayenne(CLIENT_ID)
cayenne.mqttConnect()

print("Successfully connected to myDevices MQTT broker")


def senddata():
    global count, ledValue
    lightIntensity = adc.read()
    print("Light intensity value from ADC: %d" % lightIntensity)
    print("Count: %d" % count)
    print("led value: %d" % ledValue)
    intensityString = "voltage,mv=%d" % lightIntensity
    cayenne.publish(str(intensityChannel), intensityString)
    time.sleep(2)
    count += 1
示例#2
0
addrOled    = 60  #0x3c
hSize       = 48  # Hauteur ecran en pixels | display heigh in pixels
wSize       = 64  # Largeur ecran en pixels | display width in pixels
oledIsConnected = False
tempChannel=7
humidityChannel=8

# create the dht11 object
if sys.platform == "esp8266":
    print("cayenneDHT11 running on ESP8266")
    dht11 = dht.DHT11(Pin(2))
else:
    print("cayenneDHT11 running on ESP32") 
    dht11 = dht.DHT11(Pin(16))
cayenne=Cayenne()
cayenne.mqttConnect()

print("Successfully connected to myDevices MQTT broker")
def senddata():
  print("Measuring...")
  dht11.measure()
  temp = dht11.temperature()
  tempString='temp,c=%6.3f'%temp
  print("Publishing: temperature: %s"%tempString)
  cayenne.publish(str(tempChannel),tempString)
  time.sleep(5)
  humidity=dht11.humidity()
  humidityString='rel_hum,p=%6.3f'%humidity
  print("Publishing humidity: %s"%humidityString)
  cayenne.publish(str(humidityChannel),humidityString)
示例#3
0
    14: 'Bond',
    15: 'MASH',
    16: 'StarWars',
    17: 'GoodBad',
    18: 'TopGun',
    19: 'A-Team',
    20: 'Flinstones',
    21: 'Jeopardy',
    22: 'Smurfs',
    23: 'MahnaMahna',
    24: 'LeisureSuit',
    25: 'MissionImp'
}

TOPIC_BASE = ("v1/%s/things/" % username)
cayenne = Cayenne()
cayenne.mqttConnect()


def play_tone(freq, msec):
    #    print('freq = {:6.1f} msec = {:6.1f}'.format(freq, msec))
    print("Freq: %6.1f, duration: %6.1f" % (freq, msec))
    if freq > 0:
        speaker.freq(int(freq))  # Set frequency
        speaker.duty(512)  # 50% duty cycle
    time.sleep(msec * 0.001)  # Play for a number of msec
    speaker.duty(0)  # Stop playing
    time.sleep(0.05)  # Delay 50 ms between notes


def getSongNumber(topic, msg):
示例#4
0
TOPIC_BASE = ("v1/%s/things/" % username)

intensityChannel = 1
illuminationLedChannel = 2
indicatorLedChannel = 3

# create adc and the led object
adc = ADC(0)
illuminationLed = Pin(16, Pin.OUT)
global count, ledValue
count = 0
ledValue = 0
# switch LED off
illuminationLed.value(ledValue)

cayenne = Cayenne(CLIENT_ID)
cayenne.mqttConnect()

print("Successfully connected to myDevices MQTT broker")


def ledSwitch(topic, msg):
    print(topic, msg)


def subscribeCayenne(clientID, channel):
    topic = TOPIC_BASE + clientID + '/cmd/%d' % channel
    print("Subscribing to topic %s, please wait 5 s" % topic)
    time.sleep(0.5)
    client.subscribe(topic)
    print("Subscribe sent")
示例#5
0
from cayenne import Cayenne
client_id = 'd6accfc0-6541-11e9-bdb5-dfd20f02ea3f'
cayenne = Cayenne(client_id)