Webhook publishes too frequently [Solved]

I’ve got my core up and running. Finally got my webhook figured out, but it is publishing too frequently.

As a trial, I’m reading the temperature in my office and sending it out to Netsuite (a cloud CRM/ERP). I originally had the publish set to 60 seconds, but now I want it every 15 minutes. Here’s my code:

void loop()
{
  int reading = 0;
  double voltage = 0.0;
  reading = analogRead(A7);
  voltage = (reading * 3.3) / 4095;
  temperature = (voltage - 0.5) * 100;

  Spark.publish("netsuite", String(temperature), 900000, PRIVATE);

  delay(900000);
}

I initially had my Spark.publish set to 60 and the delay at 900,000, but that didn’t work.

I’ve tried changing all 900000 values to 60 or other values, but I always seem to get published every 60 seconds.

I’m counting on you Spark community! :smile:

Just a side note. The TTL parameter is set in seconds, so 900000 is rather long, and actually you’d not really need to change this for your intention :wink:

One other thing, can you be sure your Core actually took the new flash with 900000ms delay?

Next, the suggested way to do longish delays would be via the use of millis() - e.g. like this

const unsigned long softDelay = 900000;
unsigned long softDelayCount;
 
void setup()
{
  ...
  softDelayCount = millis();
}

void loop()
{
  if (millis() - softDelayCount >= softDelay)
  {
    softDelayCount = millis();
    // do your timed jobs here
  }
  // other jobs here
}

As for your published event, try PUBLIC to start with and check the frequency via the public fire hose e.g. in Chrome like this
view-source:https://api.spark.io/v1/events/?access_token=YOUR_ACCESS_TOKEN
or your own Cores
view-source:https://api.spark.io/v1/devices/YOUR_CORE_ID/events/?access_token=YOUR_ACCESS_TOKEN

2 Likes

SUCCESS! Thanks @ScruffR for teaching me something new today.

I have to say, I am brand new to Spark, but the community here is great.

3 Likes

Great :+1: you’re very welcome!

Congrats to be part of this community now - it is the best I ever contributed too!
Loads of great and helpful people - cheers to all of you :smile:

I hope you don’t mind when I mark this solved then?

1 Like