Arduino UNO actuators sliders with feedback as a Data in dashboard


#1

Hello with MQTT I reach to connect the Arduino UNO with a Photoresistor and DHT11 devices to know the status of my room.
also I add 3 LED controlled by PWM as a slider on the dashboard. sometimes the slider and the reality does not match. soI implement a data on the dashborad to know in which status is the LED.
Here the result:

It is really usefull for remote applications that it is the real purpose of the Cayenne system. but I dont know if this is the best method to carry out this validation. It would be great if someone could be share if it is OK or there are other ways to carry out because sometimes connection is unestable or is slow feedbad. I try to avoid the data overload using a additional millis delay to send datas from the DHT11 but behaviour is similar.

What do you thing guys?


#2

Also I have no found clear data about how it works CAYENNE_LOG. if I do not implement on the digital actuator it was not working well and dashboard waas really slow but I would like to know how the comand works:
CAYENNE_LOG(“Channel %d, pin %d, value %d”, 13, 13, blanco);

And here my code:

#include <CayenneMQTTESP8266Shield.h>
#include "DHT.h"
int Verde = 0;
int Rojo = 0;
int Azul = 0;
int amarillo = 0;
int blanco = 0;
unsigned long tiempoAnterior = 0;
int periodo = 10000;
// WiFi network info.
char ssid[] = "xequebo";
char wifiPassword[] = "0";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "0";
char password[] = "0";
char clientID[] = "0";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial
#define DHTPIN 7
#define DHTTYPE DHT11
ESP8266 wifi(&EspSerial);
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  delay(10);
  dht.begin();
  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  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()
{
  if (millis() > tiempoAnterior + periodo) { //si ha transcurrido el periodo programado

    float h = dht.readHumidity();
    float t = dht.readTemperature();
    Cayenne.virtualWrite(0, millis() / 1000);

    Cayenne.luxWrite(2, analogRead(1));
    Cayenne.virtualWrite(3, t, TYPE_TEMPERATURE, UNIT_CELSIUS);
    Cayenne.virtualWrite(4, h, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
    tiempoAnterior = millis(); //guarda el tiempo actual como referencia
  }
  Cayenne.virtualWrite(5, Verde);
  Cayenne.virtualWrite(6, Rojo);
  Cayenne.virtualWrite(7, Azul);
}


CAYENNE_IN(11)
{
  Verde = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 11, 11, Rojo);
  analogWrite(11, Verde);
}

CAYENNE_IN(10)
{
  Rojo = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 10, 10, Rojo);
  analogWrite(10, Rojo);
}
CAYENNE_IN(9)
{
  Azul = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 9, 9, Azul);
  analogWrite(9, Azul);
}
CAYENNE_IN(12)
{
  amarillo = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 12, 12, amarillo);
  digitalWrite(12, amarillo);
}
CAYENNE_IN(13)
{
  blanco = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", 13, 13, blanco);
  digitalWrite(13, blanco);
}

#3

I’m not exactly sure what your overall question is, but to answer your CAYENNE_LOG question, you can see how it is defined here. Basically it’s just a tool to print a message to the serial output.