Hello Shramik_salgaunkar… well… its not a freebee. Cayenne is used to direct potential customers to myDevices and for branding. But yes, for hobbiests, it is free. I’m not complaining. And I would love to add Cayenne/myDevices in my book. It would get more traffic to flow to myDevices.
Let me illustrate to you my experience.
Go to Cayenne Features - Developer | myDevices.com. On the left, click on “Downloads”. Under Cayenne Arduino Libraries, click on the link, “Downloading…”. The link points to the same originating page. You recirculate. What in the world was the intent of this link? Hasn’t anyone brought this issue to Cayenne’s attention? So what do to?
A savvy techie might know about Github.
Github… a search for Cayenne yields this: GitHub - myDevicesIoT/Cayenne-MQTT-ESP: Cayenne MQTT ESP8266, ESP32 & NodeMCU Library. This looks promising… a lot better than three years ago. But not quite what you want. So you move on and find this… GitHub - myDevicesIoT/Cayenne-MQTT-Arduino: Cayenne MQTT Arduino Library. Just a note, the ESP8266-01 is the ESP-01 with preinstalled AT commands.
Following the instructions on this GitHub page requires the installation of the CayenneMQTT library. After that, the Cayenne setup. And following that, the example: File → Examples → CayenneMQTT → Connections. Since we’re using the ESP8266-01 as a sheild, I would assume the ESP8266Shield example. Moving along, we find the following in the sketch:
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
We can’t have this. We have only one serial port. If we’re sending debug strings on the same port for ESP, we can mess things up. It must be commmented out with an explanation why and allow the Newbie the option to activate it.
Next we have:
#define EspSerial Serial1
This won’t work. NANO had only one serial. Hence, #define EspSerial Serial. The steps above are really a little hazy. Good comments here would go a long way because the compiler will catch it.
Next we compile for the first time. We get this:
C:\Users\fred2\OneDrive\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTESP8266Shield.h:31:10: fatal error: ESP8266SerialLibrary.h: No such file or directory
#include “ESP8266SerialLibrary.h”
CayenneMQTT doesn’t have it. Oh, but it does… in Extra directory → libraries → ESP8266SerialLibrary.zip It was also explained up in the comments. Ohhhh… now I get it. Perhaps we should put that library in as a standard? Why make it an extra? There may be a reason and I’d like to know it.
So lets install the zip library.
We compile again and get this:
C:\Users\fred2\OneDrive\Documents\Arduino\libraries\CayenneMQTT\examples\Connections\ESP8266Shield\ESP8266Shield.ino:43:2: note: in expansion of macro ‘EspSerial’
EspSerial.begin(115200);
We definitely have to change that Serial1 port to Serial. Doing that allows the compiling to complete successfully. But a comment at this line would have helped.
So lets upload to NANO (with the TX/RX disconnect to ESP-01), fire it up and see what happens on the dashboard. By the way, if you don’t disconnect ESP-01, it won’t upload.
Well, naturally it isn’t going to connect because the username, password, etc etc isn’t installed. The steps gave a vague idea. So now we need to move from Github and back to Cayenne. So there’s a bit of a disconnect between Cayenne Docs and Github. Alright. We put in a new project per the Docs. We pick Arduino NANO and decide on the only option that makes sense, Arduino ESP8266 WIFI. Clicking on it brings up the sketch with the username, etc, etc, preinstalled. However, with bad luck, we could have used WIFI Shield. This programme doesn’t use the CayenneMQTTESP8266Sheild.h library. Also, it uses two ports a little differently. For a newbie, he could be spinning his wheels for some time with this. So going back to the Arduino ESP8255 WIFI, we find it to be a carbon copy of the sketch we’ve been working on.
We upload again. And fire it up.
It connects!!!
Now what? The Github doesn’t say much. So it’s back to the Cayenne docs again.
We start up at Downloads. We know this is broken and simply move on to Getting Started.
We’ve already stumbled on this when we secured the necessary credentials. We continue with the instructions skipping Choose Device and head for Arduino. This is pretty much a rehash of Github. However, when we get to libraries… it gets tricky. Cayenne by myDevices library no longer exists. CayenneMQTT does along with other Cayenne libraries. Now we have confussion. These Docs do not reflect what went on in GitHub and the present libraries. If the Newbie was not aware of Github, he could be spinning his wheels right about now surfing the internet and support pages.
Lets continue with Docs. At Sensors we find what we need. We are going to light up an LED. We pick a light switch. Assign it to NANO, channel 1 with a button. Pulling up the sketch we are hit with yet another surprise.
Whereas the original sketch that allowed for connection shows this:
#include <CayenneMQTTESP8266Shield.h>
The new sketch for the NANO with a ESP shield shows this instead:
#include <CayenneMQTTEthernet.h>
Of course, the ssid and password no longer exist.
The rest of the new sketch shows this:
#define VIRTUAL_CHANNEL undefined
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
}
//End of sketch
Whereas the sketch that allowed us to hookup was this:
#define EspSerial Serial
ESP8266 wifi(&EspSerial);
void setup()
{
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(10);
Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}
void loop()
{
Cayenne.loop();
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
//End of sketch
Obviously, there’s some hacking to do. But what needs to get hacked?
At this point, the demo has become a complete mess. Experimentation may yield something that may work, or partially work. But the frustration starts to take a liftoff.
In closing, I would like to say that the demo for Arduino with an ESP shield must be a stand alone document. It should be able to guide the Newbie through from start to finish to make his first connection in a reasonable amount of time with as little stress as possible. Arduino UNO and NANO are very common as well as ESP-01. Everyone has one. Why not work it properly? NANO 33 IoT is fairly new.
I haven’t tried the other modes of connections. I do have ESPs that can be programmed to control on their own (sufficient I/Os) without Arduino and MKR1000. But I wanted to use a $5 NANO hooked up to a $3 ESP-01 to demonstrate a fully functional WIFI/Internet microcontroller. And I can do that quite easily with Blynk.
If you like, please direct me to a person in myDevices who might be of assistance. I would be more than happy to work with that person to iron this out. In exchange, if favourable, assistance to me to put Cayenne in my book. Otherwise, lets call it a day.