Rev 1648 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1648 | Rev 1649 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | Sensor_ModuleNames = [ "DS18x20", "FOST02", "BusVoltage" ]; |
2 | Sensor_ModuleNames = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF" ]; |
| 3 | Sensor_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
3 | Sensor_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 4 | Sensor_Aliases = function() { return Module_GetAliasNames(Sensor_ModuleNames); }; |
4 | Sensor_Aliases = function() { return Module_GetAliasNames(Sensor_ModuleNames); }; |
| 5 | Sensor_AvailableIds = function() { return Module_GetAvailableIds(Sensor_ModuleNames); }; |
5 | Sensor_AvailableIds = function() { return Module_GetAvailableIds(Sensor_ModuleNames); }; |
| 6 | 6 | ||
| 7 | function Sensor_SetReportInterval(alias_name, interval) |
7 | function Sensor_SetReportInterval(alias_name, interval) |
| 8 | { |
8 | { |
| 9 | if (arguments.length < 2) |
9 | if (arguments.length < 2) |
| 10 | { |
10 | { |
| 11 | Log("\033[ |
11 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 12 | return false; |
12 | return false; |
| 13 | } |
13 | } |
| 14 | 14 | ||
| 15 | var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames); |
15 | var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames); |
| 16 | var found = false; |
16 | var found = false; |
| Line 21... | Line 21... | ||
| 21 | "SensorId" : aliases_data[name]["specific"]["SensorId"], |
21 | "SensorId" : aliases_data[name]["specific"]["SensorId"], |
| 22 | "time" : interval }; |
22 | "time" : interval }; |
| 23 | 23 | ||
| 24 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
24 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
| 25 | { |
25 | { |
| 26 |
|
26 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 27 | } |
27 | } |
| 28 | else |
28 | else |
| 29 | { |
29 | { |
| 30 |
|
30 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 31 | } |
31 | } |
| 32 | 32 | ||
| 33 | found = true; |
33 | found = true; |
| 34 | } |
34 | } |
| 35 | 35 | ||
| 36 | if (!found) |
36 | if (!found) |
| 37 | { |
37 | { |
| 38 | Log("\033[ |
38 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 39 | return false; |
39 | return false; |
| 40 | } |
40 | } |
| 41 | 41 | ||
| 42 | return true; |
42 | return true; |
| 43 | } |
43 | } |
| 44 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
44 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
| - | 45 | ||
| - | 46 | function Sensor_GetLastValue(alias_name) |
|
| - | 47 | { |
|
| - | 48 | if (arguments.length < 1) |
|
| - | 49 | { |
|
| - | 50 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
|
| - | 51 | return false; |
|
| - | 52 | } |
|
| - | 53 | ||
| - | 54 | var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames); |
|
| - | 55 | var found = false; |
|
| - | 56 | ||
| - | 57 | for (var name in aliases_data) |
|
| - | 58 | { |
|
| - | 59 | var last_value_string = Storage_GetParameter("SensorValueList", alias_name); |
|
| - | 60 | ||
| - | 61 | if (last_value_string) |
|
| - | 62 | { |
|
| - | 63 | var last_value = eval("(" + last_value_string + ")"); |
|
| - | 64 | ||
| - | 65 | for (var type_name in last_value) |
|
| - | 66 | { |
|
| - | 67 | var date = new Date(last_value[type_name]["timestamp"] * 1000); |
|
| - | 68 | ||
| - | 69 | Log("\033[96m" + type_name + ": \033[0;1m" + last_value[type_name]["value"] + "\033[0m at " + date.toString() + "\n"); |
|
| - | 70 | } |
|
| - | 71 | } |
|
| - | 72 | else |
|
| - | 73 | { |
|
| - | 74 | Log("\033[32mNo value is stored for " + name + ".\033[0m\n"); |
|
| - | 75 | } |
|
| - | 76 | ||
| - | 77 | found = true; |
|
| - | 78 | } |
|
| - | 79 | ||
| - | 80 | if (!found) |
|
| - | 81 | { |
|
| - | 82 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
|
| - | 83 | return false; |
|
| - | 84 | } |
|
| - | 85 | ||
| - | 86 | return true; |
|
| - | 87 | } |
|
| - | 88 | Console_RegisterCommand(Sensor_GetLastValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases()); }); |
|
| - | 89 | ||
| - | 90 | function Sensor_OnMessage(module_name, module_id, command, variables) |
|
| - | 91 | { |
|
| - | 92 | if (in_array(Sensor_ModuleNames, module_name)) |
|
| - | 93 | { |
|
| - | 94 | var aliases_data = Module_LookupAliases({ |
|
| - | 95 | "module_name" : module_name, |
|
| - | 96 | "module_id" : module_id, |
|
| - | 97 | "group" : false |
|
| - | 98 | }); |
|
| - | 99 | ||
| - | 100 | switch (command) |
|
| - | 101 | { |
|
| - | 102 | case "Phonenumber": |
|
| - | 103 | { |
|
| - | 104 | for (var alias_name in aliases_data) |
|
| - | 105 | { |
|
| - | 106 | var last_value = {}; |
|
| - | 107 | var last_value_string = Storage_GetParameter("SensorValueList", alias_name); |
|
| - | 108 | ||
| - | 109 | if (last_value_string) |
|
| - | 110 | { |
|
| - | 111 | last_value = eval("(" + last_value_string + ")"); |
|
| - | 112 | } |
|
| - | 113 | ||
| - | 114 | last_value[command] = { "value" : variables["Number"], "timestamp" : get_time() }; |
|
| - | 115 | ||
| - | 116 | Storage_GetParameter("SensorValueList", alias_name, JSON.stringify(last_value)); |
|
| - | 117 | } |
|
| - | 118 | ||
| - | 119 | break; |
|
| - | 120 | } |
|
| - | 121 | case "Voltage": |
|
| - | 122 | case "Temperature_Celsius": |
|
| - | 123 | case "Humidity_Percent": |
|
| - | 124 | { |
|
| - | 125 | for (var alias_name in aliases_data) |
|
| - | 126 | { |
|
| - | 127 | if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"]) |
|
| - | 128 | { |
|
| - | 129 | continue; |
|
| - | 130 | } |
|
| - | 131 | ||
| - | 132 | var last_value = {}; |
|
| - | 133 | var last_value_string = Storage_GetParameter("SensorValueList", alias_name); |
|
| - | 134 | ||
| - | 135 | if (last_value_string) |
|
| - | 136 | { |
|
| - | 137 | last_value = eval("(" + last_value_string + ")"); |
|
| - | 138 | } |
|
| - | 139 | ||
| - | 140 | last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() }; |
|
| - | 141 | ||
| - | 142 | Storage_SetParameter("SensorValueList", alias_name, JSON.stringify(last_value)); |
|
| - | 143 | } |
|
| - | 144 | ||
| - | 145 | break; |
|
| - | 146 | } |
|
| - | 147 | } |
|
| - | 148 | } |
|
| - | 149 | } |
|
| - | 150 | Module_RegisterToOnMessage("all", Sensor_OnMessage); |
|