Virtual write issue


#1

Hi all

Working on a KMP ProDiNo (Leonardo)

I’m calling this function at startup (after connection established) to send an initial “uptime” value of ZERO

Cayenne.virtualWrite(V5,0);

And it just wont display zero in the dashboard!
It stays the last displayed value until this is run after a minute (and each minute thereafter):

Cayenne.virtualWrite(V5, millis/60000);

which displays the correct uptime (yes i know it will rollover and be incorrect in 49ish days)

any ideas??


#2

That is interesting. Can you post the sketch so we can get a better idea of what is happening?


#3

relevant process - firstConnect is TRUE before this runs

CAYENNE_CONNECTED(){
CAYENNE_LOG(“Connection established”);
digitalWrite(13,HIGH);
if (firstConnect == true){
Cayenne.virtualWrite(V5,0);
firstConnect = false;
}
}


#4

Can you post the entirety of the code? That will help us figure out what is wrong. Also, how do you know firstConnect is true when CAYENNE_CONNECTED() is running?


#5

Code as follows the virtualWrite within the CAYENNE_CONNECTED function just wont work.
firstConnect is def true going in and false coming out as can be seen on debug output

//Cayenne test bed
//KMP ProDiNo


#define CAYENNE_PRINT Serial    // Comment this out to disable prints and save space
#include <CayenneEthernet.h>    // Change this to use a different communication device. See Communications examples.
#include <SimpleTimer.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>



// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxxxxxxxxx";

boolean firstConnect = true;

SimpleTimer timer;

void setup(){
  Serial.begin(9600);                                               // Debug Serial Output
  pinMode(10,OUTPUT);
  pinMode(13,OUTPUT);
  delay(5000);
      
  digitalWrite(10,LOW);
  delay(500);
  digitalWrite(10,HIGH);
  delay(1000);
    Cayenne.begin(token);
  
  
    // Setup a function to be called every second
    timer.setInterval(60000, sendUptime);                        // send uptime every minute

  wdt_enable(WDTO_8S);
}

void loop(){
  wdt_reset();
    Cayenne.run();                                                // Runs main loop
    timer.run();                                                  // Initiates SimpleTimer
}  

CAYENNE_CONNECTED(){
  CAYENNE_LOG("Connection established");
  digitalWrite(13,HIGH);
  Serial.println(firstConnect);
  if (firstConnect == true){
    Cayenne.virtualWrite(V5,0);
    firstConnect = false;
    Serial.println(firstConnect);
  }
}

CAYENNE_DISCONNECTED(){
  CAYENNE_LOG("Connection Lost");
  digitalWrite(13,LOW);
}

void sendUptime(){
  Serial.println(F("=> Send Uptime"));
  Cayenne.virtualWrite(V5, millis() / 60000);
}

#6

Sorry - worked it out - just do it manually!


#7

I meant post the code manually - the VirtualWrite issue still remains


#8

Still cant make and virtual.Write commands work within the CAYENNE.CONNECTED routine?
Any ideas guys?


#9

You can use a millis loop…


#10

Sorry but I am lost on the relevance of that to my issue?
Other functions (digitalWrite, serialPrint etc) all work within the CAYENNE_CONNECTED function as expected but not the Cayenne Virtual.write functions.

Every part of this routine runs as expected EXCEPT Caynne.virtualWrite.

CAYENNE_CONNECTED(){
  CAYENNE_LOG("Connection established");
  digitalWrite(13,HIGH);
  Serial.println(firstConnect);
  if (firstConnect == true){
    Cayenne.virtualWrite(V5,0);
    firstConnect = false;
    Serial.println(firstConnect);
  }
}

#11

Sorry for the delay…lost this topic. Give the code below a try, works for me.

CAYENNE_CONNECTED(){
  CAYENNE_LOG("Connection established");
  digitalWrite(13,HIGH);
  Serial.println(firstConnect);
  if (firstConnect == true){
    delay(3000);
    Cayenne.virtualWrite(V5,0);
    firstConnect = false;
    Serial.println(firstConnect);
  }
}

#12

Actually it seems like this is a bug where dashboard values are not updated if the device is shown as offline when the updated value is sent. Even with the 3 second delay you might still notice a time or two that it doesn’t update to 0 but if you refresh your page 2 or 3 times it should show up. If you increase the delay to 10 seconds that should pretty much guarantee the device is showing as online when it sends the value. I’ll change your post to the bugs category.


#13

I’ll give it a try