Simple Channel Input Question


#1

When does the code jump into the CAYENNE_OUT_DEFAULT() and CAYENNE_IN() functions?

Also, do they happen sequentially?

Is it possible to jump to these functions from my main loop so they can happen when I want them to? I am looking to have more control over when they are called.


#2

you will find everything about this function in this Sending MQTT messages within rate limits

this function is called automatically when you use the cayenne dashboard to send value to your device.

in case of CAYENNE_OUT_DEFAULT() you can use inbuilt millis() to send data at your own time intervals. but it should not be sent at higher rate as it could cause your device to disconnect.


#3

Currently CAYENNE_OUT_DEFAULT() is called every 15 seconds. CAYENNE_IN() is called whenever a new message is received from the server. So if by “happen sequentially” you mean are they always called in succession, no. The CAYENNE_IN() function only executes when it gets a message, not every 15 seconds.

If you want more control over calling them there are a few options. One is to make a helper function to do the work, and then have both CAYENNE_OUT_DEFAULT() and your main loop call that. Another is to just send data from the main loop as described by item #2 in the link shramiksalgaonkar posted.

A third way would be to use the poll-interval branch of the Arduino library which adds support for specifying the interval that CAYENNE_OUT functions are called via a parameter to Cayenne.loop. Though that code is untested so it could have issues. Also, you have to be careful not to send data at very short intervals since it could cause your device to be limited or blocked.


#5

@jburhenn or @shramiksalgaonkar where does the Cayenne.loop() statement call to? Is this where the CAYENNE_OUT function is called? Where can I learn more about the parameter type to the Cayenne.loop() statement?

/* Edit period_ms */
const uint32_t period_ms = 2000;
uint32_t chrono = 0;

void loop()
{
Cayenne.loop();
/* Publish data every (period_ms) ms */
if (millis() > chrono) {
chrono = millis() + period_ms;
}


#6

all the function are handled by the arduino MQTT library. https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/eb15ebd95980d31d30f33c5b258f0f364760e9b2/src/CayenneArduinoMQTTClient.h and https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/tree/master/src