Skip to content

Commit

Permalink
update app + new IOctrl + debug weekly alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
NitrofMtl committed Sep 30, 2018
1 parent 49dd2bf commit 82f5116
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
Binary file not shown.
8 changes: 4 additions & 4 deletions multi_room_thermostat/Controler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ inline void microChrono(char* chronoId, void (*timedCallback)() ) {
Serial << "Function " << chronoId << chrono << "uSec" << endl;
}

void regulator_inputs() { //output regulation loop per channel
void regulator() { //output regulation loop per channel
//microChrono("inputRead ", inputRead();
inputRead();
regulator_outputs();
}

void regulator_outputs() { //outputs controler at 10Hz
for (byte i = 0; i < 10; i++) {
outChannelID[i].ssrOut(&inChannelID[i]);//ssr controler
outChannelID[i].ssrOut(inChannelID[i]);//ssr controler
}
}

Expand All @@ -27,8 +28,7 @@ void inputRead() {
//-----------------------------------------------------------

void checkWeeklyAlarm() {
//digitalClockDisplay();
//SPAlarm.handler();
digitalClockDisplay(now(), Serial);
weeklyAlarm.handler();
}

Expand Down
28 changes: 23 additions & 5 deletions multi_room_thermostat/Setup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool setClock() {
time_t getTime = getNtpTime(ntpAddr);
if (getTime) {
setTime(getTime);
syncWithMinute();
return true;
}
}
Expand Down Expand Up @@ -92,7 +93,25 @@ void setupTime() {
lastNtpSync = now();
digitalClockDisplay(now(), Serial);
clkSync.interval(syncInterval, syncTime);
//setSyncInterval(86400000);//sync clock once a day
//setSyncInterval(86400000);//sync clock once a day
}

void syncWithMinute() {
static int sec = -1;
if ( -1 == sec ) sec = second(); //set sec in the first pass
if ( second() == sec ) { //loop back function if second did not change
TimeOut(1, syncWithMinute);
return;
}
int timeBeforeNewMinute = (60 - second()) * 1000; //millisecond before new minute
TimeOut(timeBeforeNewMinute, starWeeklyAlarmHandler);
sec = -1; //reset checker for the next sync
}

void starWeeklyAlarmHandler() {
timerWeeklyAlarm.cancel();
checkWeeklyAlarm();
timerWeeklyAlarm.interval(mn(1), checkWeeklyAlarm); //check weekly alarm each minute
}


Expand Down Expand Up @@ -150,11 +169,10 @@ void setupOutput() {

void setupWeeklyAlarm() {
init_alarmMemory();
//set alarm callback with int (callback, int)
//set alarm: (type, almSwitch, Hour, Min)
//AlarmType::SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURSDAY, WEEK, WEEK_END, ALL_DAYS
//set alarm callback with int (callback, int)
//set alarm: (type, almSwitch, Hour, Min)
//AlarmType::SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURSDAY, WEEK, WEEK_END, ALL_DAYS
for (int i = 0; i < numAlarm; i++) {
//SPAlarm.set(i, ALL_DAYS, OFF, 0, 0, setSp);
SPAlarm[i].setCallback(setSp, i);
SPAlarm[i].set(AlarmType::ALL_DAYS, OFF, 0, 0);
weeklyAlarm.add(SPAlarm[i]);
Expand Down
2 changes: 1 addition & 1 deletion multi_room_thermostat/WebSocket.ino
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void wsParseHomePutSetpoint(JsonObject& data) {


void wsSendDataConfigs() {
regulator_inputs();//refresh analog readings
inputRead();//refresh analog readings
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["id"] = "configs";
Expand Down
12 changes: 6 additions & 6 deletions multi_room_thermostat/multi_room_thermostat.ino
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ void setupSdCard();
void setupEthernet();
void setupTime();
void setupWebSocket();
void regulator_inputs();
void regulator_outputs();
void regulator();
void checkWeeklyAlarm();
void RTDSetup();
void setupOutput();
Expand All @@ -135,17 +134,17 @@ void setup() {
//WDT_Restart (WDT);
setupTime();
//WDT_Restart (WDT);
timerMainRegulator.interval(sc(10), regulator_inputs); // read inputs every 10 sec
timerWeeklyAlarm.interval(mn(1), checkWeeklyAlarm); //check weekly alarm each minute
timerMainRegulator.interval(sc(10), regulator); // read inputs every 10 sec
//timerWeeklyAlarm.interval(mn(1), checkWeeklyAlarm); //move to syncClock
RTDSetup();
setupOutput();
setupWeeklyAlarm();
restore(); //restoring user data from sd card
//WDT_Restart (WDT); //reset the watchdog timer
regulator_inputs(); //read inputs a first time before loop start
inputRead(); //read inputs a first time before loop start
delay(200);//for stability
//WDT_Restart (WDT); //reset the watchdog timer
timerSSROutput.interval(100, regulator_outputs); //outputs regulator controler at 10 Hz
//timerSSROutput.interval(100, regulator_outputs); //now runnig into timeout method

Serial.print("Free memory is: ");
Serial.println(freeMemory());
Expand All @@ -160,6 +159,7 @@ void loop() {
webServ();
webSocket.loop();
Interval::handler();
TimeOut::handler();
//WDT_Restart (WDT); //reset the watchdog timer
}

Expand Down

0 comments on commit 82f5116

Please sign in to comment.