Help Combining Sketch File with DS18B20

Excellent.

The Arduinos are not multi-threaded microprocessors. They are single microcontrollers, thus if Cayenne.run() is not called often, it cannot respond to commands.

Rule of thumb for everyone should be to minimize wait states in the main loop or function calls that take a lot of time. Also, be careful of functions that may get hung up or have retries in them.

This is a good way to do something periodically without using delay(). This could also be in a function call, and you could cycle through and print temps one at a time if needed.

unsigned long lastMillis = 0;

void loop() 
{
     //Needs to run every second or so to keep from missing things
    Cayenne.run();

    //Publish data every 10 seconds (10000 milliseconds). 
    if (millis() - lastMillis > 10000) 
    {
	lastMillis = millis();
	
        //do something
    }
}

Cheers,

Craig

2 Likes