[RESOLVED] No change "2 state" widget esp8266


#1
  • Device : ESP01 (8266) with arduino IDE

  • Dashboard : Web and Android

  • 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 :slightly_frowning_face: :


If i use a “BUTTON” widget with LED icon : the state of read gpio2 change :slight_smile: :

on android Dashboard “2 STATE” widget working well :slight_smile:


#2

And your virtualWriting the state change? Or whats your code


#3

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.


#4

I tried to Reset Dashboard :
Device Online or Offline look at this (i pressed F5 to reload + closed/open Cayenne ) :


#5

i deleted widget one by one and this is the result : state no change again ! :

Android Dashboard is ok :


#6

This is the Arduino code :

// 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

Get Commande led :1
Tx Etat Led -> 1
wait…

Get Commande led :0
Tx Etat Led -> 0
wait…


#7

If it’s usefull : the chart recording well, the different state. But widget doesn’t change :


#8

I have a feeling the issue is with the line:

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)


#9

@samarchri Looks like @rsiegel answered my question elsewhere haha NodeMCU and Digital Motion Sensor Try that out and let us know if it works.


#10

ok @adam i’ll test it. But Before , i deleted the “state” widget again , and when i push the button , the "defaut widget " appears and working good !!


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.


#11

@adam i 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 :stuck_out_tongue_winking_eye:
thanks to @adam and @rsiegel for help


#12

It must be some bug where the Android app doesn’t require the data type but the web dashboard does.


#13

Yes ! Something like this . If someone could up this bug @rsiegel :wink:


#14

Could you guys let me know a bit more about the bug you suspect? I have an Arduino MQTT device looping:

Cayenne.virtualWrite(1, 0,"digital_sensor", "d");
delay(1000);
Cayenne.virtualWrite(1, 1,"digital_sensor", "d");

And I don’t see any issue with the 2-state widget on either the web dashboard, or the Android dashboard.


#15

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:

Cayenne.virtualWrite(1, 0);
delay(1000);
Cayenne.virtualWrite(1, 1);

#16

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.


#17

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.


#18

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.


#19

i agree with you , and working well with this temporary widget. But how to change the widget for a 2-state looks like, without :

@adam is right :

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 :open_mouth:

I’m sure there is a bug here :wink:


#20

Thanks for the detail, I will try to nail down this bug on my end. First, I have a few questions:

  1. 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?

  2. 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?