Rev 2182 | Rev 2207 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2182 | Rev 2205 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | Sensor_ModuleNames = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF", "DHT11" ]; |
2 | Sensor_ModuleNames = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF", "DHT11" ]; |
| - | 3 | SensorRf_ModuleNames = [ "rfTransceive" ]; |
|
| 3 | Sensor_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
4 | Sensor_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 4 | Sensor_Aliases = function() { return Module_GetAliasNames(Sensor_ModuleNames); }; |
5 | Sensor_Aliases = function() { return Module_GetAliasNames(Sensor_ModuleNames); }; |
| 5 | Sensor_AvailableIds = function() { return Module_GetAvailableIds(Sensor_ModuleNames); }; |
6 | Sensor_AvailableIds = function() { return Module_GetAvailableIds(Sensor_ModuleNames); }; |
| 6 | 7 | ||
| 7 | function Sensor_SetReportInterval(alias_name, interval) |
8 | function Sensor_SetReportInterval(alias_name, interval) |
| Line 217... | Line 218... | ||
| 217 | } |
218 | } |
| 218 | } |
219 | } |
| 219 | } |
220 | } |
| 220 | } |
221 | } |
| 221 | Module_RegisterToOnMessage("all", Sensor_OnMessage); |
222 | Module_RegisterToOnMessage("all", Sensor_OnMessage); |
| - | 223 | ||
| - | 224 | function SensorRf_OnMessage(module_name, module_id, command, variables) |
|
| - | 225 | { |
|
| - | 226 | if (in_array(SensorRf_ModuleNames, module_name)) |
|
| - | 227 | { |
|
| - | 228 | var aliases_data = Module_LookupAliases({ |
|
| - | 229 | "module_name" : module_name, |
|
| - | 230 | "module_id" : module_id, |
|
| - | 231 | "group" : false }); |
|
| - | 232 | ||
| - | 233 | var VikingSuccess = "NoVikingSensor"; |
|
| - | 234 | loopAliases: /* Label to break nested */ |
|
| - | 235 | for (var alias_name in aliases_data) |
|
| - | 236 | { |
|
| - | 237 | if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] && |
|
| - | 238 | variables["Status"] == "Burst" && |
|
| - | 239 | aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"]) |
|
| - | 240 | { |
|
| - | 241 | switch (variables["Protocol"]) |
|
| - | 242 | { |
|
| - | 243 | case "Viking": |
|
| - | 244 | { |
|
| - | 245 | VikingSuccess = "VikingNotFound"; |
|
| - | 246 | /* |
|
| - | 247 | ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc |
|
| - | 248 | 341731651126 0b100 11111001 000011001011 00101110 00110110 20.3 46% |
|
| - | 249 | a = address, s = sign, t = temperature, h = humidity, c = crc |
|
| - | 250 | */ |
|
| - | 251 | var data = variables["IRdata"]; |
|
| - | 252 | var crc = data&0xFF; |
|
| - | 253 | var humidity = (data>>>8)&0xFF; |
|
| - | 254 | var temp = (data>>>16)&0xFFF; |
|
| - | 255 | var addr = rshift(data,28)&0xFF; |
|
| - | 256 | var unknown = rshift(data,36)&0xF; |
|
| - | 257 | var calccrc=crc8(rshift(data,8), 32); |
|
| - | 258 | ||
| - | 259 | if (crc != calccrc) |
|
| - | 260 | { |
|
| - | 261 | Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m"); |
|
| - | 262 | break loopAliases; |
|
| - | 263 | } |
|
| - | 264 | if (addr == aliases_data[alias_name]["specific"]["Address"]) |
|
| - | 265 | { |
|
| - | 266 | VikingSuccess = "VikingFound"; |
|
| - | 267 | ||
| - | 268 | var sign = (temp>>>11)&1; |
|
| - | 269 | temp = temp&0x7FF; |
|
| - | 270 | if (sign > 0) |
|
| - | 271 | { |
|
| - | 272 | temp = -temp; |
|
| - | 273 | } |
|
| - | 274 | temp = temp/10; |
|
| - | 275 | ||
| - | 276 | if (unknown != 4) |
|
| - | 277 | { |
|
| - | 278 | Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m"); |
|
| - | 279 | } |
|
| - | 280 | ||
| - | 281 | var last_value = {}; |
|
| - | 282 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
|
| - | 283 | ||
| - | 284 | if (last_value_string) |
|
| - | 285 | { |
|
| - | 286 | last_value = eval("(" + last_value_string + ")"); |
|
| - | 287 | } |
|
| - | 288 | ||
| - | 289 | var timestamp = get_time(); |
|
| - | 290 | last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp }; |
|
| - | 291 | last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp }; |
|
| - | 292 | ||
| - | 293 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
|
| - | 294 | ||
| - | 295 | break loopAliases; |
|
| - | 296 | } |
|
| - | 297 | break; |
|
| - | 298 | } |
|
| - | 299 | } |
|
| - | 300 | } |
|
| - | 301 | } |
|
| - | 302 | if (VikingSuccess == "VikingNotFound") |
|
| - | 303 | { |
|
| - | 304 | Log("Found unknown vikingsensor address="+addr+" temperature="+temp+" humidity="+humidity+" unknown="+unknown); |
|
| - | 305 | } |
|
| - | 306 | } |
|
| - | 307 | } |
|
| - | 308 | Module_RegisterToOnMessage("all", SensorRf_OnMessage); |
|
| 222 | 309 | ||
| 223 | function Sensor_StoreNumberInPhonebook(number, timestamp) |
310 | function Sensor_StoreNumberInPhonebook(number, timestamp) |
| 224 | { |
311 | { |
| 225 | var phonebookNumbers = Storage_GetJsonParamter("PhoneBook", number); |
312 | var phonebookNumbers = Storage_GetJsonParamter("PhoneBook", number); |
| 226 | 313 | ||