Have just viewed the youtube: Introduction to Cayenne: Advanced Online Session
Introduction to Cayenne: Advanced Online Session - YouTube which used an Arduino example file meant to be on Community, can someone please provide a link to file
Cheers
Hi @rfb000 and welcome to the Cayenne Community.
@bestes â do you still have the sketch file you used when making this video? It appears at 26:23
@rsiegel @rfb000 I just searched for that sketch fileâŚlooks like I donât have it anymore
But, this would be a good place to start, you can use this code and make some small modifications as you need.
Hope this helps,
~Benny
Thanks Benny, Iâm new to Cayenne and finding some examples difficult to find although Iâm well experienced with Arduino code. Trolling through the Community posts can be a bit of a pain but I expect that the support pages are still being developed and further documentation is still being developed.
Iâd really like to find a definitive reference to things like âCayenne.run()â âCayenne.loop()â âCayenne.virtualWrite()â etc something that confirms purpose and any arguments used in those functions.
I thought there would be a library description on GitHub or somewhere but not yet found so any links would be appreciated.
Thanks for the prompt response to my post
@rsiegel think this ^ is something we could add to âThe Libraryâ ?
~B
We can develop some kind of library with users` codes that are confirmed as working and where people can copy them without searching in themes with a lot of posts ?
@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?
For 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.
*/