@ognqn.chikov, he’s referring to this – if you think you have something that should go there, let us know!
@bestes, I could make a post with what you tagged me for, but I’m not sure there is that much to say. Let me share here first and we can discuss?
virtualWrite(), (and most of the other functions used in the Cayenne Arduino Library) we have documentation here.
Cayenne.run() is an infrastructure function that needs to be called at an interval to keep your device connected to Cayenne. It doesn’t take any optional parameters. For the most part, just include this once at the start of your sketch’s
void loop() function and you’ll be good to go. And don’t go crazy with
delay() functions in the rest of the sketch or it could cause connectivity issues. If you need to replace
delay() in your code, you can use the SimpleTimer library. Here’s an example I made some time ago of of replacing
delay() with SimpleTimer in a Cayenne sketch.
Cayenne.loop() isn’t present in the sketches used when connecting a device to Cayenne with the Arduino Library. Instead think of it like a replacement for
Cayenne.run() when connecting an Arduino/ESP8266 device through the Cayenne MQTT/“Bring Your Own Thing” API via the Cayenne MQTT Arduino Library. Just like the
run() function above, include it once in your
loop() function and it will maintain connectivity to Cayenne.
This function has a single, optional parameter for advanced users. It can take a single integer value for yield time which specifies the time in milliseconds that code will wait to process incoming messages, for users with time sensitive code who want to ensure our connectivity function doesn’t block their other items in the main loop from running. If not specified, this defaults to 1000ms (so 1 second).
The code for it also includes this note:
* Main Cayenne loop
* @param yieldTime Time in milliseconds to yield to allow processing of incoming MQTT messages and keep alive packets.
* NOTE: Decreasing the yieldTime while calling write functions (e.g. virtualWrite) in your main loop could cause a
* large number of messages to be sent to the Cayenne server. Use caution when adjusting this because sending too many
* messages could cause your IP to be rate limited or even blocked. If you would like to reduce the yieldTime to cause your
* main loop to run faster, make sure you use a timer for your write functions to prevent them from running too often.