virtualWrite connection loss after wifi reset

Hello everybody,

I noticed during tests that after resetting WiFI data aren’t written at channels in the dashboard. I’m using virtualWrite functions for writing data into dashboard? Are there any solutions for that problem?

Thank you in advance for replies

which device are you using? can you add #define CAYENNE_DEBUG in your code? share the Serial monitor output when the disconnect occurs and when it is connected again.

I’m using ESP32 DevkitC, code used for testing purposes looks like this:

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>
#include <CayenneArduinoMQTTClient.h>

unsigned int LoopCounter = 1;
unsigned long int time_begin = 0;
unsigned long int time_of_operation = 0;
unsigned long int time_of_previous_operation = 0;

// WiFi network info.
char ssid = “”;
char wifiPassword = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “”;
char password = “”;
char clientID = “”;

void setup() {
// put your setup code here, to run once:

Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Cayenne.virtualWrite(0, 1);


void loop()
{ // put your main code here, to run repeatedly:

time_begin = micros();
if(LoopCounter == 300)
Cayenne.virtualWrite(0, time_of_previous_operation);

time_of_operation = micros() - time_begin;

if(LoopCounter == 300)
time_of_previous_operation = time_of_operation;
LoopCounter =0;



Under normal conditions serial output from virtualWrite looks like this:

23:36:39.121 → [24846] Publish: topic 1, channel 0, value 1878, subkey , key
23:36:39.121 → 1871

That means, the time of execution of virtualWrite function was around 2 ms. Tests were performed to determine, how fast this function can be executed. Howewer, after disabling wifi output looks similar to this:

23:46:20.179 → [605921] Publish: topic 1, channel 0, value 149, subkey , key
23:46:20.179 → 151

The only difference in the serial port output is much lower value, which shows how fast function was executed. After resetting WIFI output looks like this:

23:51:12.976 → [898710] Publish: topic 1, channel 0, value 146, subkey , key
23:51:12.976 → 148

and it’s similar to the situation with disabled WIFI. Also, all the time after disabling WIFI dashboard shows tested device as offline.

first of all, never use the delay in the void loop. second, why are using two if loop in place of one? third, where is Cayenne.loop();