I sort of have the same case. All widgets are turning on after reboot
I used customize widgets and BYOT.
This is my code:
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneTemperature.h>
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
unsigned long lastMillis = 0;
#define VIRTUAL_CHANNEL_YELLOW 2
#define ACTUATOR_PIN_YELLOW 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL_BLUE 3
#define ACTUATOR_PIN_BLUE 3
#define VIRTUAL_CHANNEL_RED 4
#define ACTUATOR_PIN_RED 4
#define VIRTUAL_CHANNEL_ALARM 5
#define ACTUATOR_PIN_ALARM 5
#define VIRTUAL_CHANNEL_MOTOR 8
#define ACTUATOR_PIN_MOTOR 8
#define VIRTUAL_CHANNEL_GREEN 9
#define ACTUATOR_PIN_GREEN 9
#define VIRTUAL_CHANNEL_MOTION 7
#define SENSOR_PIN_MOTION 7
#define VIRTUAL_CHANNEL_TEMP 1
#define SENSOR_PIN_LDR 2
#define VIRTUAL_CHANNEL_LDR 0
// Analog pin the TMP36 is connected to.
const int tmpPin = 1;
// Voltage to the TMP36. For 3v3 Arduinos use 3.3.
const float voltage = 5.0;
TMP36 tmpSensor(tmpPin, voltage);
void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN_YELLOW, OUTPUT);
pinMode(ACTUATOR_PIN_BLUE, OUTPUT);
pinMode(ACTUATOR_PIN_RED, OUTPUT);
pinMode(ACTUATOR_PIN_ALARM, OUTPUT);
pinMode(ACTUATOR_PIN_MOTOR, OUTPUT);
pinMode(ACTUATOR_PIN_GREEN, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if(millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(0, lastMillis);
}
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(2)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_YELLOW, ACTUATOR_PIN_YELLOW, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_YELLOW, value);
}
CAYENNE_IN(3)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_BLUE, ACTUATOR_PIN_BLUE, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_BLUE, value);
}
CAYENNE_IN(4)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_RED, ACTUATOR_PIN_RED, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_RED, value);
}
CAYENNE_IN(5)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_ALARM, ACTUATOR_PIN_ALARM, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_ALARM, value);
}
CAYENNE_IN(8)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_MOTOR, ACTUATOR_PIN_MOTOR, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_MOTOR, value);
}
CAYENNE_IN(9)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_GREEN, ACTUATOR_PIN_GREEN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_GREEN, value);
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(7)
{
// Read data from the sensor and send it to the virtual channel here.
// For example, to send a digital value you can use the following:
int value = digitalRead(SENSOR_PIN_MOTION);
Cayenne.virtualWrite(VIRTUAL_CHANNEL_MOTION, value, TYPE_DIGITAL_SENSOR, UNIT_DIGITAL);
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(1)
{
// This command writes the temperature in Celsius to the Virtual Channel.
Cayenne.celsiusWrite(VIRTUAL_CHANNEL_TEMP, tmpSensor.getCelsius());
// To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL_TEMP, tmpSensor.getFahrenheit());
//Cayenne.kelvinWrite(VIRTUAL_CHANNEL_TEMP, tmpSensor.getKelvin());
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL_LDR)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_LDR, analogRead(SENSOR_PIN_LDR));
}
Hope you can help Cayenne. Thanks in advance