I’m using ESP32 DevkitC, code used for testing purposes looks like this:
#define CAYENNE_DEBUG
#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:
Serial.begin(115200);
randomSeed(300);
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;
}
LoopCounter++;
Serial.println(time_of_operation);
if(time_of_operation<15000)
{
delayMicroseconds(15000-time_of_operation);
}
}
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.