I am working with ESP8266(wemos d1 mini).My example send temprature data and I can see temprature widget on my dashboard. However I can’t add any new widget or actuator my dashboard like actuator or custom widget. Here custom widget setting look like this.
Here my code:
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include "Adafruit_MCP9808.h"
#define LED LED_BUILTIN //On board LED
#define VIRTUAL_CHANNEL 1
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
// WiFi network info.
char ssid[] = "xxxxx";
char wifiPassword[] = "xxxxx";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxxxxxx";
char password[] = "xxxxxx";
char clientID[] = "xxxxxx";
unsigned long lastMillis = 0;
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Serial.println("MCP9808 TEST PROGRAM");
if (!tempsensor.begin(0x18)) {
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
while (1);
}
Serial.println("Found MCP9808!");
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
//Onboard LED port Direction output
pinMode(LED,OUTPUT);
}
void loop() {
Cayenne.loop();
if(millis()-lastMillis > 5000) {
lastMillis = millis();
tempsensor.wake(); // wake up, ready to read!
float c = tempsensor.readTempC();
Serial.print("Temp: ");
Serial.print(c, 4); Serial.print("*C\t \n");
Cayenne.celsiusWrite(2,c);
}
}
// 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);
}
CAYENNE_IN(1)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}
}
// 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");
}