The Dashboard bug :
i push a button on Cayenne Dashboard (channel 0)
i on/off a led on gpio2 in the arduino code with Cayenne Received code
i read LED state on gpio2 ESP01 and send to Cayenne.(ch 1)
If i use a “2 STATE” widget : the state doesn’t change when gpio2 change :
My guess is that the 2nd screenshot, showing that you’re having trouble even deleting the 2-state widget, means something about it is/was buggy on our end. I’d try settings gear > Reset Dashboard > Confirm to see if that eliminates the 2 State widget, and then try creating a fresh one to see if it behaves better. Please note that if you do Reset Dashboard it will be necessary to re-set the icons and potentially widget types on your other existing widgets.
// carte ESP8266 GENERIC sur cayenne
// esp01 : Led gpio2 ON OFF par cayenne
// 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>
char ssid[] = "xxxxxxxxxxx";
char wifiPassword[] = "xxxxxxxxxxx";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxxxxxxxxxx";
char password[] = "xxxxxxxxxxx";
char clientID[] = "xxxxxxxxxxxxx";
unsigned long lastMillis = 0;
// Led state
#define LED_PIN 2 //LED sur GPIO2
int current ;//connaitre l'etat de la LED et Tx a cayenne
int last;
//===================================
//= SETUP =
//===================================
void setup() {
Serial.begin(9600);
Serial.println("\n++ Demarrage de Cayenne ++");
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
} // FIN de setup
//===================================
//= LOOP =
//===================================
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(2, lastMillis / 60000);// send in minutes
//Some examples of other functions you can use to send data.
Cayenne.celsiusWrite(3, 22.0);
Cayenne.luxWrite(4, 700);
Cayenne.virtualWrite(5, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
// grab the current state of the LED.
if (digitalRead(LED_PIN) == LOW)
current = 0;
else
current = 1;
// return if the value hasn't changed
if (current == last) // si led pas changée on remonte
return;
//SINON : modifi l'etat courant de la led
Serial.print("Tx Etat Led -> ");
Cayenne.virtualWrite(1, current); //Tx a cayenne etat led
Serial.println(current);
Serial.println("wait...");
// store last LED state
last = current;
} //FIN de loop
//=================================================================================
//====================== AUTRES FONCTIONS ==================================
//==========================================================================
CAYENNE_IN(0) // reception de la part de cayenne sur canal 0
{
digitalWrite(2, getValue.asInt()); // Allume ou Eteint la Led GPIO2
Serial.print("\nGet Commande led :"); Serial.println(getValue.asInt());
}
And the result on COM port :
++ Demarrage de Cayenne ++
[247] Connecting to Nxxxxxxxx
[1247] Connected to WiFi
[1247] IP: 1xxxxxxxxxxxxx
[1248] Connecting to mqtt.mydevices.com:1883
[1560] Connected
Cayenne.virtualWrite(1, current); //Tx a cayenne etat led
@rsiegel I know with manual MQTT publishing (not using the Arduino library) you have to specify the data type for it to display correctly in a two state widget (discovered this here “digital,d=”) Is there a special function you have to call to send a 2 state value? I looked through the docs for the Arduino MQTT library and it was kind of lacking on the functions to send data back (virtualWrite, celsiusWrite, etc)
But if a remove this “defaut widget” and ad manually “2 state widget” it doesn’t work on WEB Dashboard . On Android Dashboard “2 state widget”, working very good !!
Why ONLY in Web Dashboard it doesn’t working ? I don’t sure the arduino Sketch is defect.
@adami change :
Cayenne.virtualWrite(1, current); //Tx a cayenne etat led By :
Cayenne.virtualWrite(1, current,“digital_sensor”, “d”); //Tx a cayenne etat led
And working very well !! But I still believe there is a bug in WEB Dashboard
thanks to @adam and @rsiegel for help
The bug is that the Android client doesn’t require the data type to be specified to work, but the web dashboard does. I have not tested it, just taking his word for it. Use this:
On my end, that results in a Value widget bouncing between 1.00 and 0.00 on both web and Android.
To me, that doesn’t seem like a bug, we’re telling the server “Publish the value 1 to MQTT channel 1” with no context of data type or unit, so it’s being safe and picking a numeric value widget as a default. I think that is a better default than assuming it is boolean digital data since this way
Cayenne.virtualWrite(1, 0); Cayenne.virtualWrite(1, 1);
and Cayenne.virtualWrite(1, 153); are all treated the same way – as decimal number data – unless we’re told something otherwise.
Try manually adding a 2 state widget and sending those values to it, I think that’s where he’s having the bug, It’s not much of a bug other than they should both behave the same.
I think my opinion is that the bug/oversight is that we allow you to create the 2-state widget on the device dashboard of MQTT device before publishing any data to it, allowing for this confusion to happen.
The intent of our design is that you would publish the values first from code, which then auto-creates temporary ‘green’ widgets which can be approved and then added to the dashboard.
Why Android Dasboard working very well with this Arduino code : Cayenne.virtualWrite(1, current);
While WEB dashbord requiered code : Cayenne.virtualWrite(1, current,“digital_sensor”, “d”); Furthermore, the chart into the 2-state widget recording well all states … but widget doesn’t change visually.
NEW : i just see that if i create a 2-state widget when the button AND the gpio are already ON : i push the button: the 2-state widget change from 1 to 0 but if i push again the button, it doesn’t go to 1
Thanks for the detail, I will try to nail down this bug on my end. First, I have a few questions:
Are you creating this 2-state widget with a publish command? Or are you creating it first in the Cayenne UI and then publishing data to it with Cayenne.virtualWrite(1, current,“digital_sensor”, “d”); ? If in the Cayenne UI, is this on Web or Android?
The behavior you saw where the 2-state widget changed from 1 to 0, but not back to 1 – was this on Web, Android, or both?