Hello,
Could somebdy review my code? I just conect my arduino to MQTT but temporary widgets not appear and if I add by custom widgets data is empty.
What I am doing wrong?
I can see comunicatin by serial.
Here my code
#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include “DHT.h”
// WiFi network info.
char ssid = “xequebo”;
char wifiPassword = “++++”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “8****++1”;
char password = “******+”;
char clientID = “98090b10-14d1-11e8-aa1d-++++++”;
// 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
ESP8266 wifi(&EspSerial);
#define DHTPIN 7
#define DHTTYPE DHT11 // DHT 11
#define SENSOR_PIN 1 // fotoresistor
#define Azul 9 //PWM LED
#define Rojo 10 //PWM LED
#define Verde 11 //PWM LED
#define Amarillo 12
#define Blanco 13
DHT dht(DHTPIN, DHTTYPE);
#define VIRTUAL_CHANNEL 1 // Temperatura
#define VIRTUAL_CHANNEL2 2// Humedad
#define VIRTUAL_CHANNEL3 3// Luminosidad
#define VIRTUAL_CHANNEL4 4// Led
#define VIRTUAL_CHANNEL5 5// Led
#define VIRTUAL_CHANNEL6 6// Led
#define VIRTUAL_CHANNEL7 7// Led
#define VIRTUAL_CHANNEL8 8// Led
void setup()
{
dht.begin();
Serial.begin(9600);
delay(10);
// 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()
{
// 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_OUT(VIRTUAL_CHANNEL)
{
float t = dht.readTemperature();
Cayenne.virtualWrite(VIRTUAL_CHANNEL,t,TYPE_TEMPERATURE,UNIT_CELSIUS);
}
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
float h = dht.readHumidity();
Cayenne.virtualWrite(VIRTUAL_CHANNEL2,h,TYPE_RELATIVE_HUMIDITY,UNIT_PERCENT);
}
CAYENNE_OUT(VIRTUAL_CHANNEL3)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL3, analogRead(SENSOR_PIN),TYPE_LUMINOSITY,UNIT_LUX);
}
CAYENNE_IN(VIRTUAL_CHANNEL4)
{
int value = getValue.asInt(); // 0 to 255
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL4, Azul, value);
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
analogWrite(Azul, value);
}
CAYENNE_IN(VIRTUAL_CHANNEL5)
{
int value = getValue.asInt(); // 0 to 255
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL5, Rojo, value);
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
analogWrite(Rojo, value);
}
CAYENNE_IN(VIRTUAL_CHANNEL6)
{
int value = getValue.asInt(); // 0 to 255
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL6, Verde, value);
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
analogWrite(Verde, value);
}
CAYENNE_IN(VIRTUAL_CHANNEL7)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL7, Amarillo, value);
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
digitalWrite(Amarillo, value);
}
CAYENNE_IN(VIRTUAL_CHANNEL8)
{
int value = getValue.asInt(); // 0 to 255
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL8, Blanco, value);
// Write the value received to the PWM pin. analogWrite accepts a value from 0 to 255.
digitalWrite(Blanco, value);
}
If I monitor the serial port I can see comunication:
T+CIPSEND=1,40
[9903872] Publish: topic 1, channel 3, value 411, subkey lux, key lum
AT+CIPSEND=1,40
[9908895] Publish: topic 1, channel 0, value 9908895, subkey , key
AT+CIPSEND=1,40
[9913917] Connection ok
[9914233] Publish: topic 1, channel 1, value 26.000, subkey c, key temp
AT+CIPSEND=1,40
[9919531] Publish: topic 1, channel 2, value 53.000, subkey p, key rel_hum
AT+CIPSEND=1,40
[9924560] Publish: topic 1, channel 3, value 421, subkey lux, key lum
AT+CIPSEND=1,40
[9929584] Publish: topic 1, channel 0, value 9929584, subkey , key
AT+CIPSEND=1,40
But dashboard not works:
Advanced thanks fr yur support¡¡¡