Trouble with Particle.publish(); & Particle.subscribe(); -- "no matching function" error

I’m a noob. Love the Particle devices. Experimenting with the Cloud functions: Particle.publish(); & Particle.subscribe() on the Photon.

Just trying to create simple communication twixt 2 Photons where a button pressed on one changes the LED light behavior on another. Writing the code for the “button” photon now. Code with the Particle.publish() expression won’t compile. Here is the error message.

error: no matching function for call to 'CloudClass::publish(const char [13], bool, Spark_Event_TypeDef)'
void loop() {


Here is my code:

#include "Particle.h"

int pushB = D6; // var for button definition
int led = D7; // 

void setup() {
  pinMode(pushB, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
  if (digitalRead(pushB)){
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  Serial.println(digitalRead(pushB));  // print values to the serial monitor 
  Particle.publish("change-light", TRUE, PRIVATE);
  
  } else {
      digitalWrite(led, LOW);  // Turn OFF the LED pins
      Serial.println(digitalRead(pushB));  // print values to the serial monitor 
      Particle.publish("change-light", FALSE, PRIVATE);
  }
}

Help. What am I doing wrong?

I don’t think you can use ‘TRUE’ and ‘FALSE’ like that. Take a look at the example:

// EXAMPLE USAGE
Particle.publish("lake-depth/1", "28m", 21600);

Additionally, mind this:

NOTE: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.

Without rate limiting in your loop, you’ll blow over that instantly. You’re also going to need some debouncing.

thanks. i’ll check all of that out.

OK, working. Thanks for the pointer. I did this (below). It sends the other photon a message every 1 second with the button state, which is used to change LED behavior via the subscribe event handler:


#include "Particle.h"

int pushB = D6; // var for button definition
int led = D7; // 
int bState = 0;
//
int sec_interval = 2;
int prev_second = 0;

void setup() {
  pinMode(pushB, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
  button();
  secondTimer();
}

void button() {
  if (digitalRead(pushB)){
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  bState = 1;
  } else {
      digitalWrite(led, LOW);  // Turn OFF the LED pins
      bState = 0;
  }
}

void secondTimer(){
  int curr_second = (millis() / 1000);
  if ((curr_second % sec_interval == 0) && (curr_second != prev_second)) {
    if (bState == 0){
      Particle.publish("change-light", "0");
      Serial.println(bState);  // print values to the serial monitor
    }else{
      Particle.publish("change-light", "1");
      Serial.println(bState);  // print values to the serial monitor
    }
  prev_second = curr_second;
  }
}