Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling time from Manager for behavior customization uses UTC, should use Local #196

Open
udellc opened this issue May 19, 2022 · 0 comments

Comments

@udellc
Copy link
Member

udellc commented May 19, 2022

Describe the bug
Loom 2.5 but may still be bug in Loom3 - please test and fix if needed - or close with reply if not a bug in Loom3.
Using this function to pull time from Manager returns time in UTC:
myHour = Loom.DS3231().now().hour();
But intended use to to modify behavior of the device within the context of local time. This function ought to return local time.

Hardware in Use
Feather M0, Stemma soil sensor, Relay to turn sensor power on and off

To Reproduce
Steps to reproduce the behavior:
Compile and open Serial Monitor
You may comment out soil sensor and relay things.

Expected behavior
Should return Local time, but returns UTC
Code
///////////////////////////////////////////////////////////////////////////////

// This example uses an RTC DS3231 Alarm to wake up and sample i2c sensors
// at a user defined interval (see config.h).
// It also uses pins A4 and A5 to control a latched relay to turn the
// power to the i2c sensor on and off (if hooked up as prescribed in the
// associated Pin-out diagram

///////////////////////////////////////////////////////////////////////////////

#include <Loom.h>

// Include configuration
const char* json_config =
#include "config.h"
;

// Set enabled modules
LoomFactory<
Enable::Internet::Disabled,
Enable::Sensors::Enabled,
Enable::Radios::Disabled,
Enable::Actuators::Disabled,
Enable::Max::Disabled

ModuleFactory{};

LoomManager Loom{ &ModuleFactory };

const int theSetPin = A4;
const int theUnsetPin = A5;
const int AlarmPin = 10; // Pin DS3231 INT pin is physically connected to

int moistureVal = 404; // initialize to a bogus but known value so we know if data is being refreshed

const int buzzPin = A0;

const int moistureThresh = 800; // Moisture threshold

int myHour = 0; // place to save hour value from DS3231 for challenge assignment

void setup()
{

pinMode(theSetPin, OUTPUT); // Set pin, output
pinMode(theUnsetPin, OUTPUT); // Unset pin, output

// Set Buzzer pin A0 to function as an output
pinMode(buzzPin, OUTPUT);

relayOn(); // Power on attached sensor for setup!

Loom.begin_LED();
digitalWrite(LED_BUILTIN, HIGH);

// while(!Serial) {}

Loom.begin_serial(false);
Loom.parse_config(json_config);
Loom.print_config();

Loom.InterruptManager().register_ISR(AlarmPin, wakeISR, LOW, ISR_Type::IMMEDIATE);

digitalWrite(LED_BUILTIN, LOW);

LPrintln("\n ** Setup Complete ** ");

}

void loop()
{
LPrintln("Powering up sensor");
relayOn(); // Power up sensor via Relay

// Flash pattern to visually indicate processor has turned on
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
delay(250);

Loom.measure(); // Sample attached sensors
Loom.package(); // Format data for display and SD
Loom.display_data(); // display printed JSON formatted data on serial monitor

// Pull Soil Moisture data
moistureVal = Loom.get_data_as("STEMMA", "capactive");
LPrintln("Moisture Value: ", moistureVal);

// Example of condition to test if time is between 9AM and 9PM:
myHour = Loom.DS3231().now().hour();
Serial.print("My Hour: "); Serial.println(myHour);
if(9 <= myHour <= 21)
{
// if moistureVal is under 800, too dry, chirp buzzer!
if(moistureVal < moistureThresh)
{
digitalWrite(LED_BUILTIN, HIGH); // optional set LED high
tone(buzzPin, 1000); // 500ms chirp
delay(500);
noTone(buzzPin);
digitalWrite(LED_BUILTIN, LOW);
}
} // end challenge if statement

// Log using default filename as provided in configuration
// in this case, 'datafile.csv'
Loom.SDCARD().log();

// Or log to a specific file (does not change what default file is set to)
//Loom.SDCARD().log("BEETest1.csv");

Loom.InterruptManager().RTC_alarm_duration(0,0,0,30); // Wakes up the sensors every 5 seconds
Loom.InterruptManager().reconnect_interrupt(AlarmPin); // Important, make interrupt pin sensitive to alarm signal again

LPrintln("Powering down sensor");
relayOff(); // Power down sensor via Relay

LPrintln("Going to sleep");
Loom.pause();
//Loom.SleepManager().sleep(); // rest in low power sleep mode

LPrintln("Awake");
}

// subroutine to set A4 and A5 pins to turn relay on
void relayOn()
{
// Set relay signal pins to known state, both low
digitalWrite(theUnsetPin, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(theSetPin, LOW); // turn the LED on (LOW is the voltage level)

// To turn relay on, set theSetPin High for 20ms, then set low again
digitalWrite(theSetPin, HIGH);
delay(20);

}

// subroutine to set A4 and A5 pins to turn relay off
void relayOff()
{
// Set relay signal pins to known state, both low
digitalWrite(theUnsetPin, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(theSetPin, LOW); // turn the LED on (LOW is the voltage level)

// To turn relay on, set theSetPin High for 20ms, then set low again
digitalWrite(theUnsetPin, HIGH);
delay(20);
digitalWrite(theUnsetPin, LOW); // Turn off the UnsetPin LED to save battery
}

// Subroutine that is executed when the RTC timer signal triggers the
// wake up interrupt service routine
void wakeISR() {

detachInterrupt(AlarmPin);
LPrintln("Alarm went off");

}
Config
"{
'general':
{
'name':'Device',
'instance':1,
'interval':30000
},
'components':[
{
'name':'SD',
'params':[true,1000,4,'SmtPtdata',true]
},
{
'name':'Sleep_Manager',
'params':[true,false,1]
},
{
'name':'Interrupt_Manager',
'params':[0]
},
{
'name':'DS3231',
'params':[10, true,false]
},
{
'name':'STEMMA',
'params':'default'
}
]
}"
Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant