Simple Channel Input Question

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.

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.

1 Like

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.

1 Like

@jburhenn or @shramik_salgaonkar 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()
/* Publish data every (period_ms) ms */
if (millis() > chrono) {
chrono = millis() + period_ms;

all the function are handled by the arduino MQTT library. Cayenne-MQTT-Arduino/CayenneArduinoMQTTClient.h at eb15ebd95980d31d30f33c5b258f0f364760e9b2 · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub and Cayenne-MQTT-Arduino/src at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub

1 Like

Can i alter cayenne_in to run every 15secs? Because i have a “mode switch” that if pressed will change the behaviour of my system

If the switch is on the arduino will check a different set of sensors while off they will be ignored

CAYENNE_IN does not run every 15 secs, it runs whenever there is a change in the actuator subscribe state.