Sleepypi - help with dusk2dawn code

Hello I have a custom Arduino board - a sleepypi2 (Sleepy-pi-2/) which I am planning to use to turn a raspberry pi on and off at sunset and sunrise. I am using the board so I can turn the pi on at night to record some bats with infra-red, the camera will be up a tree and in a wood and I need the schedule to save battery.

My amazing friend has adapted an existing code for the board which turns the pi on and off at set times. The original code is here - Wakeduringday.ino
This wakeduringday code works (and prints debugging information) when I upload it to the sleepypi2 board.

My friend has adapted the code to attempt to turn the pi on and off between sunset and sunrise but when I upload it to the board no debugging information is printed and the sleepypi2 doesn’t turn the pi on and off. If anyone can see any reasons why the code isn’t working, please let me know,

I really appreciate any help!

// 
// Simple example showing how to set the RTC alarm pin to wake up the Arduino.
// Like an alarm clock the alarm is triggered at a particular time and 
// then the Arduino wakes up.
//
// In this example two times are set: 
//      Wakeup time = Time to awake
//      Bedtime     = Time to go back to Sleep
// 
// To test on the RPi without power cycling and using the Arduino IDE
// to view the debug messages, fit the Power Jumper or enable
// self-power
// 
// 

// **** INCLUDES *****
#include "SleepyPi2.h"
#include <Dusk2Dawn.h>
#include <TimeLib.h>
#include <LowPower.h>
#include <PCF8523.h>
#include <Wire.h>

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

// Globals
Dusk2Dawn location(34.0522, -118.2437, -8);
uint8_t WakeUp_StartHour;
uint8_t WakeUp_StartMinute;
uint8_t Bedtime_SleepHour;
uint8_t Bedtime_SleepMinute;
tmElements_t tm;
bool pi_awake = false;

void min2bytes(uint8_t hour, uint8_t minute, int minutes) {
    float floatHour   = minutes / 60.0;
    float floatMinute = 60.0 * (floatHour - floor(floatHour));
    hour              = (uint8_t) floatHour;
    minute            = (uint8_t) floatMinute;
}

void setup()
{
    // initialize serial communication: In Arduino IDE use "Serial Monitor"
    Serial.begin(9600);
    Serial.println("Starting...");
    delay(50);

    SleepyPi.rtcInit(true);

    // Default the clock to the time this was compiled.
    // Comment out if the clock is set by other means
    // ...get the date and time the compiler was run
    if (getDate(__DATE__) && getTime(__TIME__)) {
        // and configure the RTC with this info
        SleepyPi.setTime(DateTime(F(__DATE__), F(__TIME__)));
    }

    printTimeNow();
}

void loop() 
{
    // get current time
    DateTime now = SleepyPi.readTime();

    // set date and DST state for location
    int locationSunrise  = location.sunrise(now.year(), now.month(), now.day(), false);
    int locationSunset   = location.sunset(now.year(), now.month(), now.day(), false);

    /*  Time is returned in minutes elapsed since midnight. If no sunrises or
    *  sunsets are expected, a "-1" is returned.
    */
    Serial.println(locationSunrise);  // 418
    Serial.println(locationSunset);   // 1004

    // convert sunrise and sunset times to bytes
    min2bytes(WakeUp_StartHour, WakeUp_StartMinute, locationSunset);
    min2bytes(Bedtime_SleepHour, Bedtime_SleepMinute, locationSunrise);

    // this is the initial state on boot
    if(pi_awake == false)
    {
        SleepyPi.rtcClearInterrupts();

        // debugging bits
        Serial.print("Alarm Set for: ");
        Serial.print(WakeUp_StartHour);
        Serial.print(":");
        Serial.println(WakeUp_StartMinute);

        // enable alarm
        SleepyPi.enableWakeupAlarm(true);

        // Setup the Alarm Time
        SleepyPi.setAlarm(WakeUp_StartHour, WakeUp_StartMinute);

        delay(500);   // Delay purely for serial print

        // Enter power down state with ADC and BOD module disabled.
        // Wake up when wake up pin is low (which occurs when our alarm clock goes off)
        SleepyPi.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 

		// the Arduino is now awake again

        SleepyPi.ackAlarm();

        Serial.println("I've Just woken up on the Alarm!");

        // Print the time
        printTimeNow();   
        delay(50);

        // power the Rpi ++++++
        SleepyPi.enablePiPower(true); 
        pi_awake = true;
    }
    else
    { // pi awake
        SleepyPi.rtcClearInterrupts();

        // debugging bits
        Serial.print("Bedtime Set for: ");
        Serial.print(Bedtime_SleepHour);
        Serial.print(":");
        Serial.println(Bedtime_SleepMinute);

        // enable alarm
        SleepyPi.enableWakeupAlarm(true);

        // Setup the Alarm Time
        SleepyPi.setAlarm(Bedtime_SleepHour, Bedtime_SleepMinute);   // Hours & Minutes i.e. 22:07 on the 24 hour clock    

        delay(500); // Delay purely for serial print

        // Enter power down state with ADC and BOD module disabled.
        // Wake up when wake up pin is low (which occurs when our alarm clock goes off)
        SleepyPi.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 

        SleepyPi.ackAlarm();

		// the Arduino is now awake again

        Serial.println("I've Just gone to bed...zzzzzzzz");

        // Print the time
        printTimeNow();
        delay(50);

        // ++++++ Power-down the Rpi ++++++++
        SleepyPi.piShutdown();
        pi_awake = false;            
    }
}

void printTimeNow()
{
	// Read the time
	DateTime now = SleepyPi.readTime();

	// Print out the time
	Serial.print("Ok, Time = ");
	print2digits(now.hour());
	Serial.write(':');
	print2digits(now.minute());
	Serial.write(':');
	print2digits(now.second());
	Serial.print(", Date (D/M/Y) = ");
	Serial.print(now.day());
	Serial.write('/');
	Serial.print(now.month()); 
	Serial.write('/');
	Serial.print(now.year(), DEC);
	Serial.println();

	return;
}

bool getTime(const char *str)
{
	int Hour, Min, Sec;

	if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
	tm.Hour = Hour;
	tm.Minute = Min;
	tm.Second = Sec;
	return true;
}

bool getDate(const char *str)
{
	char Month[12];
	int Day, Year;
	uint8_t monthIndex;

	if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
	for (monthIndex = 0; monthIndex < 12; monthIndex++) {
		if (strcmp(Month, monthName[monthIndex]) == 0) break;
	}
	if (monthIndex >= 12) return false;
	tm.Day = Day;
	tm.Month = monthIndex + 1;
	tm.Year = CalendarYrToTm(Year);
	return true;
}

void print2digits(int number) {
	if (number >= 0 && number < 10) {
		Serial.write('0');
	}
	Serial.print(number);
}

It seems the most logical approach is to ask your amazing friend to fix what's wrong with it. If for some reason, you cannot do that, then you need to provide more information about your problem.

The problem is you never set your Bedtime or WakeUp variables since the min2bytes() function does absolutely nothing. You pass it in some variables, it does some calculations and then returns nothing.

I'd get a new amazing friend if he wrote that code.

Thanks blh64, sounds like that might be it, we'll try that

p.s. after much thought I have decided it was wrong to use the word amazing (all friends are amazing it shouldn't need defining)