-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.h
65 lines (55 loc) · 2.5 KB
/
actions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/******************************************************************
*
******************************************************************/
#ifndef actions_h
#define actions_h
//###################################################################
//-------------------------------------------------------------------
void actionsTask(void *params){
int tmpSize;
int maxTopicSize = 45;
int maxValueSize = 7;
char tmpTopic[maxTopicSize];
char tmpValue[maxValueSize];
while(true) {
coreUtilizationCalculation(); // calaculate time cores have been idle
websocket.printfAll("%s", systemStatusJson().c_str()); // update all connected clients.
tmpSize=snprintf (tmpTopic, maxTopicSize, "%s%s", mqttTopicRoot, "core0PercentIdle");
tmpSize=snprintf (tmpValue, maxValueSize, "%.2f", core0PercentIdle);
if (isVerbose) {Serial.print(tmpTopic); Serial.print(": "); Serial.print(tmpValue); }
mqttClient.publish(tmpTopic, mqttQosLevel, mqttRetain, tmpValue);
tmpSize=snprintf (tmpTopic, maxTopicSize, "%s%s", mqttTopicRoot, "core1PercentIdle");
tmpSize=snprintf (tmpValue, maxValueSize, "%.2f", core1PercentIdle);
if (isVerbose) {Serial.print(" "); Serial.print(tmpTopic); Serial.print(": "); Serial.println(tmpValue); }
mqttClient.publish(tmpTopic, mqttQosLevel, mqttRetain, tmpValue);
scheduleCheck();
vTaskDelay(15000 / portTICK_PERIOD_MS);
}
}
//-------------------------------------------------------------------
// do activities needed when schedule is active
void setScheduleStatus (bool newStatus){
if (isVerbose) {Serial.print("setScheduleStatus: Executing on core: "); Serial.print(xPortGetCoreID()); Serial.print("; priority: "); Serial.println(uxTaskPriorityGet(NULL));}
if (isScheduleOn != newStatus) {
isScheduleOn = newStatus;
if (isScheduleOn) {
// Turn on relay
digitalWrite(RELAY_PIN,HIGH);
digitalWrite(TX_LED,LOW); //use TX to show the schedule is working (in case there is no relay attached)
} else {
// Turn off relay
digitalWrite(RELAY_PIN,LOW);
digitalWrite(TX_LED,HIGH);
}
websocket.printfAll("%s", systemStatusJson().c_str());
websocket.printfAll("%s", scheduleJson().c_str());
}
}
//###################################################################
void actions_setup(){
xTaskCreatePinnedToCore(actionsTask, "actionsTask", 3072, NULL, 2, NULL, 0); //priority:2, core 0
}
//-------------------------------------------------------------------
void actions_loop() {
}
#endif //actions_h