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?
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);
}
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.
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.