Will it Rain IFTTT

Hi total noob question and apologies if its obvious but the docs aren’t making sense to me. I want to trigger a function on my Photon from the Will It Rain recipe. I’m getting confused of where to put Particle.function syntax from within my code. Any help greatly appreciated.

Please post your code so it will be easier to help you :slight_smile:


// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
#include "application.h"

SYSTEM_MODE(AUTOMATIC);

#define PIXEL_PIN D2
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);



void setup()
{
    Particle.function("set_color");
    strip.begin();
    strip.setBrightness(30);
    strip.show();
}

void loop() {
 colorAll(strip.Color(255, 0, 0), 50);

    } 

Particle.function();

{

    {
        colorAll(strip.Color(0, 255, 0), 50);
    }
}


void colorAll(uint32_t c, uint8_t wait) {
  uint16_t i;

  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
  delay(wait);
}

What i’m trying to do is have a set of neopixels change colour for a length of time should it be rain tomorrow. Just confused of where to put the different Particle.function parts

I can tell you that your Particle.function is incomplete. See docs here: https://docs.particle.io/reference/firmware/photon/#particle-function-

Notice the second argument in the example calls function in firmware called brewCoffe();

You need to write a function that will set the neopixels to the desired color and then wait for the amount of time you want. If it is a long time and you don’t want your Photon stuck in a delay you will need to track the time differently than using delay and rework the colorAll function to not delay and eliminate the references to wait. A simple if condition in loop can track how long the neopixels have been on since you turned them on and turn them back off when a certain time has been reached.

if (millis() > rainAlertEnd){ turn off neopixels}

> // This #include statement was automatically added by the Particle IDE.
> #include "neopixel/neopixel.h"
> #include "application.h"

> SYSTEM_MODE(AUTOMATIC);

> #define PIXEL_PIN D2
> #define PIXEL_COUNT 12
> #define PIXEL_TYPE WS2812B

> Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

> int newColor(String command);

> void setup()
> {
>     Particle.function("set_color", newColor);
>     strip.begin();
>     strip.setBrightness(30);
>     strip.show();
> }

> void loop() {
>  colorAll(strip.Color(255, 0, 255), 50);

>     } 

> int newColor(String command)

>  {
>     if(command == "rain_tom")
>     {
>         colorAll(strip.Color(0, 255, 0), 50);
           delay(3000);
>         return 1;
>     }
>     else return -1;
> }




> void colorAll(uint32_t c, uint8_t wait) {
>   uint16_t i;

>   for(i=0; i<strip.numPixels(); i++) {
>     strip.setPixelColor(i, c);
>   }
>   strip.show();
>   delay(wait);

}

Hi sorry for the delay, I’ve updated my code as you can see above but when i hit the check now button in the IFTTT recipe nothing happens. I’ve read about 15 mins delay with IFTTT, does this apply to the check now button or is there something wrong with the code again Thanks.

IFTTT log shows it being triggered but nothing happens my end.

I tried calling the function via the Particle CLi and it returned a -1, must be something code wise.

This is a screenshot of what i’ve done in IFTTT, is this correct…?

maybe change

if(command == “rain_tom”)

into

if(command.equals(“rain_tom”))

See: https://docs.particle.io/reference/firmware/photon/#equals-

Does that help?
Rolf