Rev 2014 | Rev 2091 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2014 | Rev 2050 | ||
|---|---|---|---|
| Line 38... | Line 38... | ||
| 38 | 38 | ||
| 39 | return true; |
39 | return true; |
| 40 | } |
40 | } |
| 41 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
41 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
| 42 | 42 | ||
| - | 43 | Sensor_OnNewPhonenumberFunctions = null; |
|
| - | 44 | ||
| 43 | function |
45 | function Sensor_RegisterToNewPhonenumber(alias_name, callback) |
| - | 46 | { |
|
| - | 47 | if (Sensor_OnNewPhonenumberFunctions == null) |
|
| - | 48 | { |
|
| - | 49 | Sensor_OnNewPhonenumberFunctions = new Array(); |
|
| - | 50 | } |
|
| - | 51 | ||
| - | 52 | if (!Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| 44 | { |
53 | { |
| - | 54 | Sensor_OnNewPhonenumberFunctions[alias_name] = new Array(); |
|
| - | 55 | } |
|
| - | 56 | ||
| - | 57 | Sensor_OnNewPhonenumberFunctions[alias_name].push(callback); |
|
| - | 58 | } |
|
| - | 59 | ||
| - | 60 | function Sensor_OnMessage(module_name, module_id, command, variables) |
|
| - | 61 | { |
|
| 45 | if (in_array(Sensor_ModuleNames, module_name)) |
62 | if (in_array(Sensor_ModuleNames, module_name)) |
| 46 | { |
63 | { |
| 47 | var aliases_data = Module_LookupAliases({ |
64 | var aliases_data = Module_LookupAliases({ |
| 48 | "module_name" : module_name, |
65 | "module_name" : module_name, |
| 49 | "module_id" : module_id, |
66 | "module_id" : module_id, |
| 50 | "group" : false |
67 | "group" : false |
| 51 | }); |
68 | }); |
| 52 | 69 | ||
| 53 | switch (command) |
70 | switch (command) |
| 54 | { |
71 | { |
| 55 | case "Phonenumber": |
72 | case "Phonenumber": |
| 56 | { |
73 | { |
| 57 | for (var alias_name in aliases_data) |
74 | for (var alias_name in aliases_data) |
| 58 | { |
75 | { |
| 59 | if (variables["Number"].length > 6) |
76 | if (variables["Number"].length > 6) |
| - | 77 | { |
|
| 60 | var direction; |
78 | var direction; |
| 61 | var start = 0; |
79 | var start = 0; |
| 62 | if (variables["Number"].charAt(0) == 'A') { |
80 | if (variables["Number"].charAt(0) == 'A') { |
| 63 | direction = "in"; |
81 | direction = "in"; |
| 64 | start = 1; |
82 | start = 1; |
| Line 68... | Line 86... | ||
| 68 | var endIndex = variables["Number"].indexOf('C'); |
86 | var endIndex = variables["Number"].indexOf('C'); |
| 69 | if (endIndex == -1) { |
87 | if (endIndex == -1) { |
| 70 | endIndex = variables["Number"].length; |
88 | endIndex = variables["Number"].length; |
| 71 | } |
89 | } |
| 72 | variables["Number"] = variables["Number"].substring(start,endIndex); |
90 | variables["Number"] = variables["Number"].substring(start,endIndex); |
| 73 | var last_value = {}; |
91 | var last_value = {}; |
| 74 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
92 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 75 | 93 | ||
| 76 | if (last_value_string) |
94 | if (last_value_string) |
| 77 | { |
95 | { |
| 78 | last_value = eval("(" + last_value_string + ")"); |
96 | last_value = eval("(" + last_value_string + ")"); |
| 79 | } |
97 | } |
| 80 | 98 | ||
| 81 | last_value[command] = { "value" : variables["Number"], "timestamp" : get_time(), "direction" : direction }; |
99 | last_value[command] = { "value" : variables["Number"], "timestamp" : get_time(), "direction" : direction }; |
| 82 | 100 | ||
| 83 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
101 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 84 | 102 | ||
| 85 | var all_numbers = Storage_GetParameters("PhoneCalls"); |
103 | var all_numbers = Storage_GetParameters("PhoneCalls"); |
| 86 | var newString = "{\"number\":\"" + variables["Number"] + "\",\"module\":\"" + alias_name + "\",\"direction\":\"" + direction + "\"}"; |
104 | var newString = "{\"number\":\"" + variables["Number"] + "\",\"module\":\"" + alias_name + "\",\"direction\":\"" + direction + "\"}"; |
| 87 | Storage_SetParameter("PhoneCalls", get_time(), newString); |
105 | Storage_SetParameter("PhoneCalls", get_time(), newString); |
| 88 | Log("New number: "+newString +"\n"); |
106 | Log("New number: "+newString +"\n"); |
| 89 | Sensor_StoreNumberInPhonebook(variables["Number"]); |
107 | Sensor_StoreNumberInPhonebook(variables["Number"]); |
| - | 108 | if (Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 109 | { |
|
| - | 110 | for (var n in Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 111 | { |
|
| - | 112 | /* Call callback with arguments number, direction */ |
|
| - | 113 | Sensor_OnNewPhonenumberFunctions[alias_name][n](alias_name, variables["Number"], direction); |
|
| - | 114 | } |
|
| - | 115 | } |
|
| - | 116 | } |
|
| - | 117 | else if (variables["Number"].length > 1) |
|
| - | 118 | { |
|
| - | 119 | if (variables["Number"] == "B00C") |
|
| - | 120 | { |
|
| - | 121 | /* Unknown number */ |
|
| - | 122 | var newString = "{\"number\":\"" + variables["Number"] + "\",\"module\":\"" + alias_name + "\",\"direction\":\"" + "in" + "\"}"; |
|
| - | 123 | Storage_SetParameter("PhoneCalls", get_time(), newString); |
|
| - | 124 | if (Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 125 | { |
|
| - | 126 | for (var n in Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 127 | { |
|
| - | 128 | /* Call callback with arguments number, direction */ |
|
| - | 129 | Sensor_OnNewPhonenumberFunctions[alias_name][n](alias_name, variables["Number"], "in"); |
|
| - | 130 | } |
|
| - | 131 | } |
|
| - | 132 | } |
|
| - | 133 | else if (variables["Number"] == "B10C") |
|
| - | 134 | { |
|
| - | 135 | /* Secret/protected number */ |
|
| - | 136 | var newString = "{\"number\":\"" + variables["Number"] + "\",\"module\":\"" + alias_name + "\",\"direction\":\"" + "in" + "\"}"; |
|
| - | 137 | Storage_SetParameter("PhoneCalls", get_time(), newString); |
|
| - | 138 | if (Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 139 | { |
|
| - | 140 | for (var n in Sensor_OnNewPhonenumberFunctions[alias_name]) |
|
| - | 141 | { |
|
| - | 142 | /* Call callback with arguments number, direction */ |
|
| - | 143 | Sensor_OnNewPhonenumberFunctions[alias_name][n](alias_name, variables["Number"], "in"); |
|
| - | 144 | } |
|
| - | 145 | } |
|
| - | 146 | } |
|
| - | 147 | else |
|
| - | 148 | { |
|
| - | 149 | Log("Incoming phonecall, short number: "+variables["Number"]+" length: "+variables["Number"].length); |
|
| - | 150 | } |
|
| 90 | } |
151 | } |
| 91 | } |
152 | } |
| 92 | break; |
153 | break; |
| 93 | } |
154 | } |
| 94 | case "Voltage": |
155 | case "Voltage": |
| 95 | case "Temperature_Celsius": |
156 | case "Temperature_Celsius": |
| 96 | { |
157 | { |
| 97 | if ((module_name == "DS18x20") && (variables["Value"] == 85)) |
158 | if ((module_name == "DS18x20") && (variables["Value"] == 85)) |
| 98 | { |
159 | { |
| 99 | Log("\033[31mDS18x20: Temperature conversion error: " + module_name + ":" + module_id + ", SensorId=" + variables["SensorId"] + "\033[0m"); |
160 | Log("\033[31mDS18x20: Temperature conversion error: " + module_name + ":" + module_id + ", SensorId=" + variables["SensorId"] + "\033[0m"); |
| 100 | break; |
161 | break; |
| 101 | } |
162 | } |
| 102 | } |
163 | } |
| 103 | case "Humidity_Percent": |
164 | case "Humidity_Percent": |
| 104 | { |
165 | { |
| 105 | for (var alias_name in aliases_data) |
166 | for (var alias_name in aliases_data) |
| 106 | { |
167 | { |
| 107 | if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"]) |
168 | if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"]) |
| 108 | { |
169 | { |
| 109 | continue; |
170 | continue; |
| 110 | } |
171 | } |
| 111 | 172 | ||
| 112 | var last_value = {}; |
173 | var last_value = {}; |
| 113 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
174 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 114 | 175 | ||
| 115 | if (last_value_string) |
176 | if (last_value_string) |
| 116 | { |
177 | { |
| 117 | last_value = eval("(" + last_value_string + ")"); |
178 | last_value = eval("(" + last_value_string + ")"); |
| 118 | } |
179 | } |
| 119 | 180 | ||
| 120 | last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() }; |
181 | last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() }; |
| 121 | 182 | ||
| 122 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
183 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 123 | } |
184 | } |
| 124 | 185 | ||
| 125 | break; |
186 | break; |
| 126 | } |
187 | } |
| 127 | } |
188 | } |
| 128 | } |
189 | } |
| 129 | } |
190 | } |
| 130 | Module_RegisterToOnMessage("all", Sensor_OnMessage); |
191 | Module_RegisterToOnMessage("all", Sensor_OnMessage); |
| 131 | 192 | ||
| 132 | function Sensor_StoreNumberInPhonebook(number) |
193 | function Sensor_StoreNumberInPhonebook(number) |
| 133 | { |
194 | { |
| 134 | var phonebook = Storage_GetJsonParamter("PhoneBook",number) |
195 | var phonebook = Storage_GetJsonParamter("PhoneBook",number) |
| 135 | if (!phonebook) |
196 | if (!phonebook) |
| 136 | 197 | { |
|
| 137 | if (number.charAt(0) != '0') |
198 | if (number.charAt(0) != '0') |
| - | 199 | { |
|
| 138 | if (typeof sensorDefaultPhoneAreaCode === 'undefined') |
200 | if (typeof sensorDefaultPhoneAreaCode === 'undefined') |
| - | 201 | { |
|
| 139 | Log("\033[31mOnlinePhonebook: please add sensorDefaultPhoneAreaCode = yourAreaCode to autostart.js, defaulting to 031\033[0m\n"); |
202 | Log("\033[31mOnlinePhonebook: please add sensorDefaultPhoneAreaCode = yourAreaCode to autostart.js, defaulting to 031\033[0m\n"); |
| 140 | number = "031"+number; |
203 | number = "031"+number; |
| 141 | } else { |
- | |
| 142 | number = sensorDefaultPhoneAreaCode+number; |
- | |
| 143 | } |
204 | } |
| - | 205 | else |
|
| - | 206 | { |
|
| - | 207 | number = sensorDefaultPhoneAreaCode+number; |
|
| 144 | } |
208 | } |
| - | 209 | } |
|
| - | 210 | ||
| 145 | var persons = new Array(); |
211 | var persons = new Array(); |
| 146 | url = "wap.eniro.se/query?search_word=" + number + "&what=mobwp"; |
212 | url = "wap.eniro.se/query?search_word=" + number + "&what=mobwp"; |
| 147 |
|
213 | Log("\033[31mURL: http://"+url+"\033[0m\n"); |
| 148 | Http_Request(url, |
214 | Http_Request(url, |
| 149 | function(socket_id, result, header, content_data) { |
215 | function(socket_id, result, header, content_data) { |
| 150 | if (result.indexOf("200 OK") != -1) |
216 | if (result.indexOf("200 OK") != -1) |
| 151 | { |
217 | { |
| 152 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
218 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
| Line 156... | Line 222... | ||
| 156 | var nameStartString = "<td class=\"hTd2\">"; |
222 | var nameStartString = "<td class=\"hTd2\">"; |
| 157 | var nameEndString = "</table>"; |
223 | var nameEndString = "</table>"; |
| 158 | for (var n = 1; n < lines.length; n++) |
224 | for (var n = 1; n < lines.length; n++) |
| 159 | { |
225 | { |
| 160 | var line = lines[n].trim("\n"); |
226 | var line = lines[n].trim("\n"); |
| 161 | 227 | ||
| 162 | if (line.indexOf(endString) != -1) |
228 | if (line.indexOf(endString) != -1) |
| 163 | { |
229 | { |
| 164 | break; |
230 | break; |
| 165 | } |
231 | } |
| 166 | if (line.indexOf(nameStartString) != -1) |
232 | if (line.indexOf(nameStartString) != -1) |
| 167 | { |
233 | { |
| 168 | line = lines[n+1].trim("\n"); |
234 | line = lines[n+1].trim("\n"); |
| 169 | splitted = line.split("b>"); |
235 | splitted = line.split("b>"); |
| 170 | persons[persons.length] = splitted[1].substr(0, splitted[1].length -2); |
236 | persons[persons.length] = splitted[1].substr(0, splitted[1].length -2); |
| 171 | break; |
237 | break; |
| 172 | } |
238 | } |
| 173 | 239 | ||
| 174 | } |
240 | } |
| 175 | 241 | ||
| 176 | //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n"); |
242 | //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n"); |
| 177 | //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n"); |
243 | //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n"); |
| 178 | //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n"); |
244 | //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n"); |
| 179 | if (persons.length > 0) |
245 | if (persons.length > 0) |
| - | 246 | { |
|
| 180 | Storage_SetJsonParameter("PhoneBook", number, persons); |
247 | Storage_SetJsonParameter("PhoneBook", number, persons); |
| 181 | 248 | ||
| 182 | //CAll all listeners! |
249 | //CAll all listeners! |
| 183 | //.... |
250 | //.... |
| 184 | 251 | ||
| 185 | Log("\033[31mOnlinePhonebook: Found: " + JSON.stringify(persons) + "\033[0m\n"); |
252 | Log("\033[31mOnlinePhonebook: Found: " + JSON.stringify(persons) + "\033[0m\n"); |
| 186 | } |
253 | } |
| 187 | } |
254 | } |
| 188 | else |
255 | else |
| 189 | { |
256 | { |
| 190 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
257 | Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n"); |
| 191 | } |
258 | } |
| 192 | } |
259 | } |
| 193 | ); |
260 | ); |
| 194 | if (persons.length == 0) { |
261 | if (persons.length == 0) { |
| 195 | if (typeof |
262 | if (typeof sensorRKSEEK_API === 'undefined') |
| - | 263 | { |
|
| 196 | ; |
264 | ; |
| - | 265 | } |
|
| 197 |
|
266 | else |
| - | 267 | { |
|
| 198 | url = "rkseek.oblivioncreations.se/?client="+sensorRKSEEK_API+"&n=" + number + "&out=text"; |
268 | url = "rkseek.oblivioncreations.se/?client="+sensorRKSEEK_API+"&n=" + number + "&out=text"; |
| 199 |
|
269 | Log("\033[31mURL: http://"+url+"\033[0m\n"); |
| 200 | Http_Request(url, |
270 | Http_Request(url, |
| 201 | function(socket_id, result, header, content_data) |
271 | function(socket_id, result, header, content_data) |
| - | 272 | { |
|
| 202 | var persons = new Array(); |
273 | var persons = new Array(); |
| 203 | if (result.indexOf("200 OK") != -1) |
274 | if (result.indexOf("200 OK") != -1) |
| 204 | { |
275 | { |
| 205 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
276 | //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n"); |
| 206 | var lines = content_data.split("\n"); |
277 | var lines = content_data.split("\n"); |