Skip to content

Commit eb15ebd

Browse files
authored
Merge pull request #18 from myDevicesIoT/feature/esp-support
Feature/esp support
2 parents 5a04353 + ba645c3 commit eb15ebd

18 files changed

+324
-69
lines changed

README.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
# Cayenne MQTT Arduino Library
2-
The Cayenne MQTT Arduino Library provides functions to easily connect to the Cayenne IoT project builder.
2+
The Cayenne MQTT Arduino Library provides functions to easily connect to the [Cayenne IoT project builder](https://www.cayenne-mydevices.com). This library is designed to work with Arduino, ESP8266 and ESP32 devices. With it you can send data to and receive data from Cayenne.
33

4-
This library bundles the [Eclipse Paho MQTT C/C++ client](https://github.com/eclipse/paho.mqtt.embedded-c).
4+
![alt text](https://upload.wikimedia.org/wikipedia/commons/3/38/Arduino_Uno_-_R3.jpg)
55

6-
## Repository Structure
7-
- **src** - The library source code.
8-
- **CayenneUtils** - Common code for creating and parsing Cayenne topics and payloads. This code can be used with any MQTT client.
9-
- **CayenneMQTTClient** - Platform independent Cayenne C++ library using the Paho MQTT C++ library. To create platform specific versions of this library networking and timer code for the platform are required.
10-
- **MQTTCommon** - Common Paho MQTT C code used by both the C and C++ libraries.
11-
- **Platform** - Platform specific networking and timer code, as well as test and example applications.
6+
[Arduino Uno image](https://commons.wikimedia.org/wiki/File%3AArduino_Uno_-_R3.jpg) by [SparkFun](https://www.sparkfun.com) is licensed under [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/)
7+
8+
![alt text](https://cdn-learn.adafruit.com/assets/assets/000/024/792/medium640/adafruit_products_2471_iso_assembled_01_ORIG.jpg?1429908417)
9+
10+
[Adafruit HUZZAH ESP8266 image](https://learn.adafruit.com/assets/24792) by [lady ada](https://learn.adafruit.com/users/adafruit2) is licensed under [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
11+
12+
![alt text](https://cdn.sparkfun.com//assets/parts/1/1/5/6/4/13907-01.jpg)
13+
14+
[SparkFun ESP32 Thing image](https://www.sparkfun.com/products/13907) by [SparkFun](https://www.sparkfun.com) is licensed under [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/)
15+
16+
## Requirements
17+
### Hardware
18+
* An Arduino, ESP8266 or ESP32 module, e.g. the [Arduino Uno](https://store.arduino.cc/usa/arduino-uno-rev3), [Adafruit HUZZAH ESP8266](https://www.adafruit.com/product/2471) or [SparkFun ESP32 Thing](https://www.sparkfun.com/products/13907).
19+
* A USB cable, or if using certain ESP devices, a USB to Serial FTDI cable.
20+
21+
### Software
22+
* [Arduino IDE](https://www.arduino.cc/en/Main/Software) for Windows, Linux or Mac OS.
23+
* [This library](https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/archive/master.zip).
24+
25+
## Getting Started
26+
### Environment Setup
27+
1. Download and install the [Arduino IDE](https://www.arduino.cc/en/Main/Software).
28+
2. Install the **CayenneMQTT** library from **Sketch -> Include Library -> Manage Libraries**.
29+
3. If using an ESP module, install the Board Package.
30+
1. For **ESP8266**:
31+
1. Under **File -> Preferences** add `http://arduino.esp8266.com/stable/package_esp8266com_index.json` to the **Additional Boards Manager URLs** field.
32+
2. Install the **esp8266** platform from **Tools -> Board -> Boards Manager**.
33+
2. For **ESP32**, manually install the board package by following the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.
34+
4. Connect your device to your computer using the appropriate USB cable or USB to Serial FTDI cable.
35+
5. Select your Arduino board or ESP module and and the correct port from the **Tools** menu.
36+
37+
### Cayenne Setup
38+
1. Create your Cayenne account at https://www.cayenne-mydevices.com.
39+
2. Add a new device using the **Add new...** page **MicroControllers** or **Bring Your Own Thing** options.
40+
41+
### Building Examples
42+
1. Open an included example connection sketch from **File -> Examples -> CayenneMQTT -> Connections**.
43+
2. Modify the included sketch with the Cayenne authentication info you received when adding your device.
44+
3. If using an ESP module or WiFi shield modify the sketch with your network info.
45+
3. Compile and upload the sketch to your device. For ESP devices uploading may require setting the device into bootload mode. For the Adafruit HUZZAH ESP8266 module this is done with the folowing steps:
46+
1. Hold down the **GPIO0** button.
47+
2. Click the **Reset** button.
48+
3. Let go of the **GPIO0** button.
49+
4. The red LED should light up, indicating the device is ready for uploading.
50+
5. Upload your sketch.
51+
4. Check the Cayenne dashboard to ensure it is receiving sample data from your device.
52+
53+
## Compatibility
54+
This library was tested with various Arduino boards including the Uno, Mega, Due, etc. as well as the Adafruit HUZZAH ESP8266 breakout module and an Espressif ESP32 development board. It should also work with other standard ESP8266 and ESP32 modules that are compatible with the Arduino IDE. Boards with very constrained memory like the Arduino Leonardo or Micro may have issues fitting this library alongside other libraries. For those boards you might try using a manually specified IP as shown in the [ManualConnection example sketch](https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/ManualConnection/ManualConnection.ino) in order to save space.
55+
56+
## Contributions
57+
* This library includes the [Eclipse Paho MQTT C/C++ client](https://github.com/eclipse/paho.mqtt.embedded-c).
1258

1359
## Cayenne MQTT Libraries
14-
- **[Cayenne-MQTT-C](https://github.com/myDevicesIoT/Cayenne-MQTT-C)** - C version of the Cayenne MQTT Library.
15-
- **[Cayenne-MQTT-CPP](https://github.com/myDevicesIoT/Cayenne-MQTT-CPP)** - C++ version of the Cayenne MQTT Library.
16-
- **[Cayenne-MQTT-Arduino](https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino)** - Arduino version of the Cayenne MQTT Library.
17-
- **[Cayenne-MQTT-mbed](https://github.com/myDevicesIoT/Cayenne-MQTT-mbed)** - mbed version of the Cayenne MQTT Library. This is also available on the mbed developer site [here](https://developer.mbed.org/teams/myDevicesIoT/code/Cayenne-MQTT-mbed/).
60+
Additional libraries are available for connecting to Cayenne on other platforms and devices. These can be found at https://github.com/myDevicesIoT.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
This example shows how to connect to Cayenne using an ESP32 and send/receive sample data.
3+
4+
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
5+
6+
Steps:
7+
1. If you have not already installed the ESP32 Board Package install it using the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.
8+
2. Select your ESP32 board from the Tools menu.
9+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
10+
4. Set the network name and password.
11+
5. Compile and upload the sketch.
12+
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
13+
*/
14+
15+
//#define CAYENNE_DEBUG
16+
#define CAYENNE_PRINT Serial
17+
#include <CayenneMQTTESP32.h>
18+
19+
// WiFi network info.
20+
char ssid[] = "ssid";
21+
char wifiPassword[] = "wifiPassword";
22+
23+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
24+
char username[] = "MQTT_USERNAME";
25+
char password[] = "MQTT_PASSWORD";
26+
char clientID[] = "CLIENT_ID";
27+
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
32+
}
33+
34+
void loop() {
35+
Cayenne.loop();
36+
}
37+
38+
// Default function for sending sensor data at intervals to Cayenne.
39+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
40+
CAYENNE_OUT_DEFAULT()
41+
{
42+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
43+
Cayenne.virtualWrite(0, millis());
44+
// Some examples of other functions you can use to send data.
45+
//Cayenne.celsiusWrite(1, 22.0);
46+
//Cayenne.luxWrite(2, 700);
47+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
48+
}
49+
50+
// Default function for processing actuator commands from the Cayenne Dashboard.
51+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
52+
CAYENNE_IN_DEFAULT()
53+
{
54+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
55+
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
56+
}
57+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
3+
4+
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
5+
6+
Steps:
7+
1. If you have not already installed the ESP8266 Board Package install it using the instructions here: https://github.com/esp8266/Arduino#installing-with-boards-manager.
8+
2. Select your ESP8266 board from the Tools menu.
9+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
10+
4. Set the network name and password.
11+
5. Compile and upload the sketch.
12+
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
13+
*/
14+
15+
//#define CAYENNE_DEBUG
16+
#define CAYENNE_PRINT Serial
17+
#include <CayenneMQTTESP8266.h>
18+
19+
// WiFi network info.
20+
char ssid[] = "ssid";
21+
char wifiPassword[] = "wifiPassword";
22+
23+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
24+
char username[] = "MQTT_USERNAME";
25+
char password[] = "MQTT_PASSWORD";
26+
char clientID[] = "CLIENT_ID";
27+
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
32+
}
33+
34+
void loop() {
35+
Cayenne.loop();
36+
}
37+
38+
// Default function for sending sensor data at intervals to Cayenne.
39+
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
40+
CAYENNE_OUT_DEFAULT()
41+
{
42+
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
43+
Cayenne.virtualWrite(0, millis());
44+
// Some examples of other functions you can use to send data.
45+
//Cayenne.celsiusWrite(1, 22.0);
46+
//Cayenne.luxWrite(2, 700);
47+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
48+
}
49+
50+
// Default function for processing actuator commands from the Cayenne Dashboard.
51+
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
52+
CAYENNE_IN_DEFAULT()
53+
{
54+
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
55+
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
56+
}
57+

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=CayenneMQTT
2-
version=1.1.0
2+
version=1.2.0
33
author=myDevices
44
maintainer=myDevices
55
sentence=Connect a device to the Cayenne dashboard using MQTT.

src/CayenneArduinoDefines.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
The MIT License(MIT)
33
44
Cayenne Arduino Client Library
5-
Copyright © 2016 myDevices
5+
Copyright (c) 2016 myDevices
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
88
documentation files(the "Software"), to deal in the Software without restriction, including without limitation
@@ -52,7 +52,7 @@ Logging code adapted from Blynk library BlynkDebug.h. Copyright info below.
5252
char buffer[12];
5353
CAYENNE_PRINT.print('[');
5454
CAYENNE_PRINT.print(millis());
55-
CAYENNE_PRINT.print(F("] "));
55+
CAYENNE_PRINT.print(CAYENNE_FLASH("] "));
5656
const char* p = message;
5757
size_t n = 0;
5858
while (1) {
@@ -127,4 +127,4 @@ Logging code adapted from Blynk library BlynkDebug.h. Copyright info below.
127127
#include "DetectDevice.h"
128128
#include "CayenneHandlers.h"
129129

130-
#endif
130+
#endif

0 commit comments

Comments
 (0)