Power Saving modes

I have a project that is solar and battery powered. Attached to my particle is a single channel relay. My code is simple as I just have my smartthings home automation controller sending the on and off command to the particle. I don’t need this project running 24/7 and would like to make sure I get a good runtime from the small battery and pannel. I tried reading the other posts on deep sleep mode etc and just ended up ultimately confused as I have no coding experience.

How where and what would I need to paste into my code to say make the particle deep sleep from 2am til 9am? I could use UTC if that is easier as well…

Secondly is there a mode that I could put the particle in that would sleeps everything except waiting for the on command to be recieved. If so how could I achieve that as it would be perfect for this project.

I have attached my code below for the photon. I can also provide my smartthings groovy device handler if it’s needed.

// A Spark function to parse the commands

int relay4(String command);

// We name pins 
int r4 = D3;

// This routine runs only once upon reset
void setup() 
{
  //Register Spark functions
  Spark.function("strelay4", relay4);
  
  // Initialize output pins
  
  pinMode(r4, OUTPUT);
  
  // take control of the LED
  RGB.control(true);
  
  // the following sets the RGB LED to light green:
  RGB.color(0, 0, 0);
}

// This routine loops forever 
void loop()
{
  // nothing here
}

//acts based on messages from spark cloud
int relay1(String command)
{

int relay4(String command)
{
  if (command == "1") 
    {   
    digitalWrite(r4, HIGH);   // Turn ON the relay
    return 1;
    } 
  else 
    {               
    digitalWrite(r4, LOW);    // Turn OFF the relay
    return 0;
  }
}

You got some unfinished busines with your int relay1() function in that code.
When you click the :pencil2: icon at the bottom of your post you can edit your code.

I’ve also reformatted your code block. Have a look at it how to post a code block correctly.

Also have a look here
Forum Tips and Tricks

BTW, in the other thread I already posted some suggestions of which I can’t see any sign in your current code.

2 Likes

oops yeah that relay(1) function is supposed to be erased I will fix that!

Thanks for the help @ScruffR!

1 Like