From 200868b6fb26ee62916e4a68156394c8618eed8b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 22 Jun 2024 10:08:30 -0400 Subject: [PATCH] Update adafruitio_00_publish_modified.cpp use millis instead of delay --- .../adafruitio_00_publish_modified.cpp | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp index bb592ec2..0b919596 100644 --- a/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp +++ b/stempayload/Payload_BME280_MPU6050_AIO/adafruitio_00_publish_modified.cpp @@ -28,6 +28,7 @@ // this int will hold the current count for our sketch int count = 0; bool aio_connected = false; +unsigned long delay; // set up the 'counter' feed //AdafruitIO_Feed *counter = io.feed("counter"); @@ -59,6 +60,7 @@ void aio_setup() { Serial.println(); Serial.println(io.statusText()); */ + delay = millis(); } void aio_loop(float tlm[]) { @@ -78,31 +80,34 @@ void aio_loop(float tlm[]) { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - - // save count to the 'counter' feed on Adafruit IO - Serial.print("\nSending to Adafruit IO -> "); - // Serial.println(count); - // counter->save(count); - Serial.print(tlm[0]); - temperature->save(tlm[0]); - Serial.print(" "); - Serial.print(tlm[1]); - pressure->save(tlm[1]); - Serial.print(" "); - Serial.print(tlm[2]); - altitude->save(tlm[2]); - Serial.print(" "); - Serial.print(tlm[3]); - humidity->save(tlm[3]); - Serial.println(" "); - - // increment the count by 1 - count++; + if ((millis() - delay) > 8000) { // Only send if 8 seconds have passed + delay = millis(); + // save count to the 'counter' feed on Adafruit IO + Serial.print("\nSending to Adafruit IO -> "); + // Serial.println(count); + // counter->save(count); + Serial.print(tlm[0]); + temperature->save(tlm[0]); + Serial.print(" "); + Serial.print(tlm[1]); + pressure->save(tlm[1]); + Serial.print(" "); + Serial.print(tlm[2]); + altitude->save(tlm[2]); + Serial.print(" "); + Serial.print(tlm[3]); + humidity->save(tlm[3]); - // Adafruit IO is rate limited for publishing, so a delay is required in - // between feed->save events. In this example, we will wait three seconds - // (1000 milliseconds == 1 second) during each loop. - delay(10000); // 1000 + Serial.println(" "); + + // increment the count by 1 + count++; + + // Adafruit IO is rate limited for publishing, so a delay is required in + // between feed->save events. In this example, we will wait three seconds + // (1000 milliseconds == 1 second) during each loop. + // delay(10000); // 1000 + } } }