Hello @rsiegel ,
I Successfully added ESP8266-12E development board to cayenne.But LED button is not responding, It continuously searching to connect. I programmed successfully ESP12E using OTA.
The code is given below ( it is same as Acrobatic/Cayenne Youtube your sponsored video Remote monitoring using MQTT.)
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT serial
char ssid[] = "iBall-Baton";
char password[] = "****************";
char username[] = "mqtt-username";
char mqtt_password[] = "mqtt-password";
char client_id[] = "clientID";
void setup() {
// put your setup code here, to run once:
Cayenne.begin(username,mqtt_password,client_id, ssid, password);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
Cayenne.loop();
}
CAYENNE_IN(0)
{
digitalWrite(2, !getValue.asInt());
}
Your thoughts on this will be greatly appreciated.
Here is how I accomplished this, this was tested on Arduino and not ESP8266, but I donāt think that should make a difference. I edited it so that it still has your ESP connectivity code, but youāll need to add back your Username/Password/Client ID (I edited them out for privacy reasons).
In my case the LED is on digital pin 9, and the actuator widget on my cayenne dashboard was added to channel 1.
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT serial
char ssid[] = "iBall-Baton";
char password[] = "****************";
char username[] = "mqtt-username";
char mqtt_password[] = "mqtt-password";
char client_id[] = "clientID";
int ledPin = 9;
void setup() {
Serial.begin(9600);
Cayenne.begin(username,mqtt_password,client_id, ssid, password);
pinMode(ledPin, OUTPUT);
}
void loop() {
Cayenne.loop();
}
//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(1)
{
digitalWrite(ledPin, getValue.asInt());
}
I uploaded the sketch . But still the same result.
While adding Button in Enter Setting is it necessary to add cayenne code .
given below.
**
* @file SimplePublish.c
*
* Simplified example app for using the Cayenne MQTT C library to publish example data.
*/
#include "CayenneMQTTClient.h"
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char* username = "MQTT_USERNAME";
char* password = "MQTT_PASSWORD";
char* clientID = "CLIENT_ID";
Network network;
CayenneMQTTClient mqttClient;
// Connect to the Cayenne server.
int connectClient(void)
{
// Connect to the server.
int error = 0;
printf("Connecting to %s:%d\n", CAYENNE_DOMAIN, CAYENNE_PORT);
if ((error = NetworkConnect(&network, CAYENNE_DOMAIN, CAYENNE_PORT)) != 0) {
return error;
}
if ((error = CayenneMQTTConnect(&mqttClient)) != MQTT_SUCCESS) {
NetworkDisconnect(&network);
return error;
}
printf("Connected\n");
// Send device info. Here we just send some example values for the system info. These should be changed to use actual system data, or removed if not needed.
CayenneMQTTPublishData(&mqttClient, NULL, SYS_VERSION_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, CAYENNE_VERSION);
CayenneMQTTPublishData(&mqttClient, NULL, SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "Linux");
return CAYENNE_SUCCESS;
}
// Main loop where MQTT code is run.
void loop(void)
{
while (1) {
// Yield to allow MQTT message processing.
CayenneMQTTYield(&mqttClient, 1000);
// Publish some example data every second. This should be changed to send your actual data to Cayenne.
CayenneMQTTPublishDataFloat(&mqttClient, NULL, DATA_TOPIC, 0, TYPE_TEMPERATURE, UNIT_CELSIUS, 30.5);
CayenneMQTTPublishDataInt(&mqttClient, NULL, DATA_TOPIC, 1, TYPE_LUMINOSITY, UNIT_LUX, 1000);
}
}
// Main function.
int main(int argc, char** argv)
{
// Initialize the network.
NetworkInit(&network);
// Initialize the Cayenne client.
CayenneMQTTClientInit(&mqttClient, &network, username, password, clientID, NULL);
// Connect to Cayenne.
if (connectClient() == CAYENNE_SUCCESS) {
// Run main loop.
loop();
}
else {
printf("Connection failed, exiting\n");
}
return 0;
}
I didnāt get any error message on Arduino IDE consol. The sketch is 100% uploded. And device ESP12E development board with CP2102 (usb to serial) is connected properly to cayenne. When I add Button it is added to Cayenne dashboard But on clicked it is not changing the state of button, It shows continuous searching action just like not reachable action.
Iām getting confused, maybe a language translation issue? Lets start with the basics, which sketch are you currently using? I see you initially posted a sketch but in your last post you included a different sketch. Also I see that the MQTT username/password/clientID is still set at the default values. Was that intentional for posting to the forum? It is a good idea to delete this info before posting, just wanted to make sure you were changing in the sketch you are uploading.
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT serial
char ssid[] = "iBall-Baton";
char password[] = "***************";
char username[] = "*********************************************";
char mqtt_password[] = "*********************************************";
char client_id[] = "****************************************";
int ledPin = 2;
void setup()
{
// put your setup code here, to run once.
Serial.begin(9600);
Cayenne.begin(username, mqtt_password, client_id, ssid, password);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void loop()
{
// put your main code here, to run repeatedly:
Cayenne.loop();
}
CAYENNE_IN(0)
{
digitalWrite(ledPin, !getValue.asInt());
}
With this code uploading ESP12E is added to Cayenne.
I want to make led on pin no2 to ON/OFF
So I added Custom Widget āButtonā
Name-LED1
Device - ESP8266-MQTT
Sensor - Digital Actuator
Unit-Digital (0/1)
Channel 0
Icon - lamp
Then I clicked āAdd widgetā
Note: The option āStep1: Codeā I cannot use. (This only I missing , I think)
The āButtonā appears on cayenne dashboard.
But the action of LED ON/OFF expected, is not working.
There should be no need to use that āStep 1: Codeā button or anything to enter there. That button just provides example C code that you could use for connecting a similar MQTT device ā you can ignore it since you are using Arduino Sketch code anyway.
I tried your code and it worked OK for me (again, on an Arduino, but I even re-wired the LED to Pin 2 and changed my button widget to channel 0.) I did notice you inverted the logic by setting the pin to HIGH in setup() and inverting the getValue.asInt() result, but that worked OK on my end too.
Unless this is something ESP specific, could it potentially be a wiring issue? Have you tried with the LED on any other pin? Iām curious if it even lights up the sketch is first uploaded and hits the initial digitalWrite(ledPin, HIGH); statment, even if the button is not working as expected.
Yes! I got it .
I traced physically the inbuilt led pin connection on my AMICA board, it is on GPIO16
But this was not the cause.
I removed my ESP-board from Cayenne. And added new credentials username,password, client id.
It immediately worked. Last four days I was using the same earlier credentials.
Iām trying the above sketch on a esp32 in hopes it will upload and connect. I get avr/pgmspace.h no such file. Can you direct me to where on github I can get this file? Just trying to connect first.
thanks
william
ESP32 is not supported yet. I do have one at home but Iām not sure when Iāll get time to look at it to see if I can get it connected. I have about 10 projects going on at once nowā¦ if you want to try yourself my plan would be to use the pubsubclient MQTT library (standard MQTT library, not Cayenne) to see if that works.