When I attended Makerfaire Bay Area last week , I heard a talk by the folks at myDevices, who build an IoT platform called– Cayenne, which has an online IoT dashboard that takes most of the complication out of creating hardware-oriented programming, originally it worked with just the Raspberry Pi, and is now available for the Arduino as well. In addition, you also have a feature were you can use MQTT to post sensor data to Cayenne IoT dashboard, this means we can use the Intel Edison to post sensor data as shown in the picture below. For more info about Cayenne check out the documentation at https://mydevices.com/cayenne/docs/
Initially as part of design challenge proposal, I had planned to use Intel’s cloud analytics, but I soon found out that the application was sunset’ed, and I had planned to use to use either use AWS IoT or IBM Watson IoT. But after hearing about Cayenne, and spending some time at the Cayenne booth at the Makerfaire, and getting to look at their dashboard, I plan to change directions slightly and use Cayenne.
As part of the Circuit I have the Intel Edison connected to Temperature, Light and Air Quality sensor data to Cayenne
- Grove Air Quality sensor (version 1.3) connected to A0 on the grove connector shield
- Temperature sensor connected to A1
- Light sensor connected to A2
To setup your cayenne dashboard create an account at - https://mydevices.com/ , and then add your own device using "Bring Your Own Thing API selection" icon, and make a note of the following
- MQTT Username
- MQTT Password
- Client ID
Before we run the python program below, we will have to install the cayenne-mqtt package using pip
pip install cayenne-mqtt
Here is the python code use to upload sensor data to cayenne. And once you run the python program below, after updating the MQTT_USERNAME, MQTT_PASSWORD and MQTT_CLIENT_ID you should see your new sensor appear in the dashboard. You can then create a new project in Cayenne and added the sensor to the project. (* as part of the dashboard picture above you can see there is an on/off button, which i plan to trigger/control a couple of things on the Intel Edison, which is going to be part of a future blog post)
#!/usr/bin/env python # Create by Carmelito to post data to Cayenne Dashboard using MQTT # Cayenne https://github.com/myDevicesIoT/Cayenne-MQTT-Python # Grove temperature sensor- https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovetemp.py # Grove light sensor - https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovelight.py # Grove Air quality sensor v1.3- https://software.intel.com/en-us/iot/hardware/sensors/air-quality-sensor import cayenne.client import time from upm import pyupm_grove as grove from upm import pyupm_gas as TP401 #for the Air quality sensor # Cayenne authentication info. This should be obtained from the Cayenne Dashboard. MQTT_USERNAME = "xxxxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxxx" MQTT_PASSWORD = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" MQTT_CLIENT_ID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" client = cayenne.client.CayenneMQTTClient() client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID) # Give a qualitative meaning to the value from the Ait quality sensor def airQuality(value): if(value < 50): return "Fresh Air" if(value < 200): return "Normal Indoor Air" if(value < 400): return "Low Pollution" if(value < 600): return "High Pollution - Action Recommended" return "Very High Pollution - Take Action Immediately" # New Grove Air Quality Sensor on AIO pin 0 airSensor = TP401.TP401(0) # 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!") #temperature sensor object using AIO pin 1 on the Grove connector shield temp = grove.GroveTemp(1) #light sensor object using AIO pin 2 light = grove.GroveLight(2) while True: 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) # 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) #timestamp = time.time() #Sleep for time.sleep(5)
Reference:
Setting up Cayenne on the Intel Edison - https://github.com/myDevicesIoT/Cayenne-MQTT-Python
Cayenne docs - https://mydevices.com/cayenne/docs/
Grove Air quality sensor v1.3- https://software.intel.com/en-us/iot/hardware/sensors/air-quality-sensor
Top Comments