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

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!!!

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

#define usbSerial Serial

// This is the unique Product Identifier for your device
#define PRODUCT_UID "" // ""

#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.
  const size_t usb_timeout_ms = 3000;
  for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)

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

  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);

    //delay(30000);  //15000  9000000

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?


1 Like

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!!


1 Like