Subversion Repositories HomeAutomation

Rev

Rev 2046 | Rev 2048 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2046 Rev 2047
Line 1... Line 1...
1
/* RRD_Tool() must be called from autostart.js to start timers */
1
function RRD_Tool() {Log("\033[31mCall to RRD_Tool() can be removed from autostart.js!\033[0m\n");}
-
 
2
 
-
 
3
RRD_Tool_Init();
2
function RRD_Tool()
4
function RRD_Tool_Init()
3
{
5
{
4
    /* We must always call the parent constructor, initialization
6
    /* We must always call the parent constructor, initialization
5
       of variables could be done here, but initialize is a better place */
7
       of variables could be done here, but initialize is a better place */
6
    var self = this;
8
    var self = this;
7
   
9
   
8
    /* Constant config name */
10
    /* Constant config name */
9
    RRD_Tool_Config = "RRD_Tool_config";
11
    RRD_Tool_Config = "RRD_Tool_config";
10
   
12
   
11
    Log("\033[33mRRD Tool updater starting...\033[0m");
13
    //Log("\033[33mRRD Tool updater starting...\033[0m");
12
   
14
   
13
    var last_value_string = Storage_GetParameters(RRD_Tool_Config);
15
    var last_value_string = Storage_GetParameters(RRD_Tool_Config);
14
    RRD_Tool_StoredData = new Array();
16
    RRD_Tool_StoredData = new Array();
15
    RRD_Tool_Timers = new Array();
17
    RRD_Tool_Timers = new Array();
16
    for (var name in last_value_string)
18
    for (var name in last_value_string)
17
    {
19
    {
18
        RRD_Tool_StoredData[name] = eval("(" + last_value_string[name] + ")");
20
        RRD_Tool_StoredData[name] = eval("(" + last_value_string[name] + ")");
19
        Log("\033[33mFound: "+name+" with update rate of "+RRD_Tool_StoredData[name]["rrd"]["Period_s"]+"s.\033[0m");
21
        Log("\033[33mFound: "+name+" with update rate of "+RRD_Tool_StoredData[name]["rrd"]["Period_s"]+"s.\033[0m");
20
        RRD_Tool_Timers[name] = Timer_SetTimer(function(timer) {RRD_Tool_timerUpdate(timer)}, RRD_Tool_StoredData[name]["rrd"]["Period_s"]*1000, true);
22
        RRD_Tool_Timers[name] = Timer_SetTimer(function(timer) {RRD_Tool_timerUpdate(timer)}, RRD_Tool_StoredData[name]["rrd"]["Period_s"]*1000, true);
21
    }
23
    }
22
    Log("\033[33mRRD Tool updater created.\033[0m");
24
    //Log("\033[33mRRD Tool updater created.\033[0m");
23
}
25
}
24
 
26
 
25
/* Declaration of static variables */
27
/* Declaration of static variables */
26
RRD_Tool_myInterval = null;
28
RRD_Tool_myInterval = null;
27
RRD_Tool_StoredData = null;
29
RRD_Tool_StoredData = null;
28
RRD_Tool_Timers = null;
30
RRD_Tool_Timers = null;
29
RRD_Tool_Config = null;
31
RRD_Tool_Config = null;
30
 
32
 
31
RRD_Tool_timerUpdate = function(timer)
33
RRD_Tool_timerUpdate = function(timer)
32
{
34
{
33
    var alias_string = Storage_GetParameters("LastValues");
35
    var alias_string = Storage_GetParameters("LastValues");
34
    for (var name in RRD_Tool_Timers)
36
    for (var name in RRD_Tool_Timers)
35
    {  
37
    {  
36
        if (RRD_Tool_Timers[name] == timer) {
38
        if (RRD_Tool_Timers[name] == timer) {
37
            //Log("Timer: "+timer+", named: "+name+" with data: "+RRD_Tool_StoredData[name]["rrd"]["file"]+"\n");
39
            //Log("Timer: "+timer+", named: "+name+" with data: "+RRD_Tool_StoredData[name]["rrd"]["file"]+"\n");
Line 56... Line 58...
56
            //Log("Command: "+cmd);
58
            //Log("Command: "+cmd);
57
            Execute(cmd);
59
            Execute(cmd);
58
            break;
60
            break;
59
        }
61
        }
60
    }
62
    }
61
}
63
}
62
 
64
 
63
/* Tab complete stuff */
65
/* Tab complete stuff */
64
RRD_Tool_Aliases        = function() { return Module_GetAliasNames(); };
66
RRD_Tool_Aliases        = function() { return Module_GetAliasNames(); };
65
RRD_Tool_Intervals      = function() { return [ 5, 10, 30, 60, 120, 150, 300 ]; };
67
RRD_Tool_Intervals      = function() { return [ 5, 10, 30, 60, 120, 150, 300 ]; };
66
/* Function returns an array with all CAN variables existing in LastValues storage */
68
/* Function returns an array with all CAN variables existing in LastValues storage */
Line 68... Line 70...
68
{
70
{
69
    var last_value_string = Storage_GetParameters("LastValues");
71
    var last_value_string = Storage_GetParameters("LastValues");
70
    var last_values = new Array();
72
    var last_values = new Array();
71
    var last_values_variables = [];
73
    var last_values_variables = [];
72
    for (var name in last_value_string)
74
    for (var name in last_value_string)
73
    {
75
    {
74
        last_values[name] = eval("(" + last_value_string[name] + ")");
76
        last_values[name] = eval("(" + last_value_string[name] + ")");
75
        for (var name2 in last_values[name])
77
        for (var name2 in last_values[name])
76
        {
78
        {
77
            /* Only get unique variables */
79
            /* Only get unique variables */
78
            if (last_values_variables.indexOf(name2) == -1)
80
            if (last_values_variables.indexOf(name2) == -1)
Line 81... Line 83...
81
            }
83
            }
82
        }
84
        }
83
    }
85
    }
84
    return last_values_variables;
86
    return last_values_variables;
85
};
87
};
86
 
88
 
87
/*
89
/*
88
electricPower={"rrd":{"file":"/var/www/appdata/rrd-data-new/electricPower.rrd","Period_s":"60"}, "rrdNames":{"power":{"Module":"powerMeter","data":"Power32","value":"value"}}}
90
electricPower={"rrd":{"file":"/var/www/appdata/rrd-data-new/electricPower.rrd","Period_s":"60"}, "rrdNames":{"power":{"Module":"powerMeter","data":"Power32","value":"value"}}}
89
 
91
 
90
<store_name>={"rrd":{"file":"<rrd_filename>","Period_s":"<push_interval>"}, "rrdNames":{"<rrd_data_source_name>":{"Module":"<alias_name>","data":"<variable_name>","value":"value"}}}
92
<store_name>={"rrd":{"file":"<rrd_filename>","Period_s":"<push_interval>"}, "rrdNames":{"<rrd_data_source_name>":{"Module":"<alias_name>","data":"<variable_name>","value":"value"}}}
91
*/
93
*/
Line 103... Line 105...
103
    {
105
    {
104
        Log("\033[31mNot enough parameters given.\033[0m\n");
106
        Log("\033[31mNot enough parameters given.\033[0m\n");
105
        return false;
107
        return false;
106
    }
108
    }
107
 
109
 
108
    /* In case RRD_Tool() is not called from autostart.js yet */
-
 
109
    if (RRD_Tool_Config == null || RRD_Tool_StoredData == null || RRD_Tool_Timers == null)
110
    if (RRD_Tool_Config == null || RRD_Tool_StoredData == null || RRD_Tool_Timers == null)
110
    {
111
    {
111
        RRD_Tool_Config = "RRD_Tool_config";
112
        RRD_Tool_Config = "RRD_Tool_config";
112
        RRD_Tool_StoredData = new Array();
113
        RRD_Tool_StoredData = new Array();
113
        RRD_Tool_Timers = new Array();
114
        RRD_Tool_Timers = new Array();
114
       
-
 
115
        Log("\033[31mRRD_Tool() must be called from autostart.js!.\033[0m\n");
-
 
116
    }
115
    }
117
   
116
   
118
    //Log("rrd data source array length: "+rrd_data_source_name_array.length);
117
    //Log("rrd data source array length: "+rrd_data_source_name_array.length);
119
    //if (rrd_data_source_name_array.length > 0)
118
    //if (rrd_data_source_name_array.length > 0)
120
    //{
119
    //{