Do you know the MQTT protocol?
The MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.
For this project I use the MQTT protocol under Cayenne developer ambient. When you make an object that have sensor or actuator, you can make also a protocol for communication between that object, and for example your smartphone. The last step, the communication with smartphone, or computer, require a platform that show the value, or the buttons to activate the actuator. Cayenne give you a free platform to experiments your prototipe.
MQTT is the preferred transport and API for sending data to the Cayenne Cloud, or for devices that receive commands from Cayenne. The Cayenne Cloud acts as a broker, managing the various sensor and actuator client devices that wish to send and receive data using the Cayenne Cloud.Cayenne MQTT is straightforward and easy to use, offering several different ways of connecting your data to Cayenne.
The hardwares of the project are:
- Adafruit BMP 085 (for this sensor you must install the Arduino library Adafruit_BMP_085.h) https://github.com/adafruit/Adafruit_BMP280_Library
- 2 x photoresistor
This sensor use a I2C communication, and a SPI communication. For this project I use a I2C Arduino UNO communication port.
THIS SENSOR WORK AT 3,5V!
See the sensor pin and connect:
- VCC of the BMP085 sensor to 3.3V (NOT 5.0V!);
- GND to Ground;
- Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5;
- Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4;
- EOC is not used, it signifies an end of conversion;
- XCLR is a reset pin, also not used here;
After install the BMP085 library by https://github.com/adafruit/Adafruit-BMP085-Libra...
Restart the Arduino IDE and select the BMP085 test. See the result on the serial. If all it's ok you can see Temperature, Barometric pressure, and altitude.
Now download the Cayenne Library, install on Arduino IDE. After open the Example of Cayenne MQTT library, and modify the Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = "MQTT_USERNAME"; char password = "MQTT_PASSWORD"; char clientID = "CLIENT_ID";
upload the code on your Arduino. All of the required information we need can be found on the Cayenne dashboard’s Choose SDK and connect your device screen. Refer to this screen and copy & paste your MQTT Username, MQTT Password and Client ID into the sketch file.
The example sketch file includes placeholders for these values, so we just need to update them with the values provided to us on our dashboard. TIP: The credentials shown here are unique for your account and the current device being added. When programming new devices, always be sure to copy & paste from the Cayenne dashboard screen so that the correct values are used for your device.
Click on Add new... --> Bring You Own Thing --> Copy the MQTT username, password and clientID
Modify the USER, PASSWORD and ID variable. Open your Arduino IDE and copy the file and upload on your Arduino UNO.
Open the serial monitor for debug.
Now make your Cayenne dashboard. Connect the Arduino UNO + Ethernet Shield to internet and you see the serial messages. When you see the connection message, try to open Cayenne Dashboard, and see the values on the screen. After you can modify the icons of Cayenne widget, or show the diagram, or make a new dashboard with the different data.