# Works "continuous" but struggling getting "periodic" to work

**URL:** <https://discuss.blues.com/t/works-continuous-but-struggling-getting-periodic-to-work/1979>\
**Category:** Uncategorized\
**Created:** [February 23, 2024, 5:56pm UTC](https://discuss.blues.com/t/works-continuous-but-struggling-getting-periodic-to-work/1979 "2024-02-23T17:56:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rayjorgnsen](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rayjorgnsen](https://discuss.blues.com/u/rayjorgnsen)\
**Post date:** [February 23, 2024, 5:56pm UTC](https://discuss.blues.com/t/works-continuous-but-struggling-getting-periodic-to-work/1979/1 "2024-02-23T17:56:57Z")

</div>

I can’t find what I’m doing wrong to get periodic outbound to work. The code is a modified example six. If someone could look it over and give me a hint I’d appreciate it!!

Swan - notecarrier A - Cellular card

I also don’t know how to add code the right way!!!

```auto
#include <Notecard.h>
#include <NotecardPseudoSensor.h>
#include <Notecarrier.h>

#define usbSerial Serial

// This is the unique Product Identifier for your device
#define PRODUCT_UID "com.gmail.jorgensenray53:quickstart" // "com.my-company.my-name:my-project"

#define myProductID PRODUCT_UID

#define VoltagePin A0
int readVoltage = 0;
float voltage = 0;

using namespace blues;

Notecard notecard;
NotecardPseudoSensor sensor(notecard);

// One-time Arduino initialization
void setup()
{
  // Set up for debug output (if available).
#ifdef usbSerial
  // If you open Arduino's serial terminal window, you'll be able to watch
  // JSON objects being transferred to and from the Notecard for each request.
  usbSerial.begin(115200);
  const size_t usb_timeout_ms = 3000;
  for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
    ;
  notecard.setDebugOutputStream(usbSerial);
#endif

  // Initialize the physical I/O channel to the Notecard
#ifdef txRxPinsSerial
  notecard.begin(txRxPinsSerial, 9600);
#else
  notecard.begin();
#endif

  J *req = notecard.newRequest("hub.set");
  if (myProductID[0])
  {
    JAddStringToObject(req, "product", myProductID);
  }
  //JAddStringToObject(req, "mode", "continuous");
  JAddStringToObject(req, "mode", "periodic");
  JAddNumberToObject(req, "outbound", 2); // 2 minutes send interval
  JAddNumberToObject(req, "inbound", 60); //Check for incoming data every 48 hrs
  notecard.sendRequestWithRetry(req, 5); // 5 seconds
}

// In the Arduino main loop which is called repeatedly, add outbound data every
// 15 seconds
void loop()
{
  float temperature = sensor.temp();
  float humidity = sensor.humidity();
  float pressure = 100;
  float wind = 25.3;

  J *req = notecard.newRequest("note.add");
  if (req != NULL)
  {
    //JAddStringToObject(req, "file", "sensors.qo");
    //JAddBoolToObject(req, "sync", true);
    J *body = JAddObjectToObject(req, "body");
    if (body != NULL)
    {
      JAddNumberToObject(body, "temp", temperature);
      JAddNumberToObject(body, "humidity", humidity);
      JAddNumberToObject(body, "pressure", pressure);
      JAddNumberToObject(body, "wind", wind);
      JAddNumberToObject(body, "voltage", voltage);

      notecard.sendRequest(req);
    }
    //delay(30000); //15000 9000000
  }
}

```

---

<div class="post-metadata">

**Author:** ![RobLauer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/roblauer/32/1567_2.png) [@RobLauer](https://discuss.blues.com/u/RobLauer)\
**Post date:** [February 23, 2024, 6:12pm UTC](https://discuss.blues.com/t/works-continuous-but-struggling-getting-periodic-to-work/1979/2 "2024-02-23T18:12:30Z")

</div>

Hi @rayjorgnsen,

(FYI I formatted your post for you, the simplest way to add code is to use three back ticks “```” before and after your code sample).

At first glance everything looks syntactically correct, with a couple notes:

1. Your outbound argument is set to 2, which means the Notecard will re-connect every 2 minutes if there is data to be synced. That’s awfully low for periodic (it’s basically still continuous effectively), so in a more real world scenario you’d want that to be higher.
2. You’ll want to uncomment your delay, otherwise you are going to be adding new Notes at a rate so fast you’ll fill up all the available flash on the Notecard.

Are you seeing a specific error or is data just not appearing in Notehub?

Rob

---

<div class="post-metadata">

**Author:** ![rayjorgnsen](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rayjorgnsen](https://discuss.blues.com/u/rayjorgnsen)\
**Post date:** [February 23, 2024, 6:44pm UTC](https://discuss.blues.com/t/works-continuous-but-struggling-getting-periodic-to-work/1979/3 "2024-02-23T18:44:25Z")

</div>

the 2 min outbound is just to see something on notehub without waiting forever. I commented out the delay cause I thought the outbound time (2 min) took the place of the delay. All should be fine.

I was getting messages on notehub faster than I could unplug the power!!

Thanks
