Subversion Repositories HomeAutomation

Rev

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

Rev 2237 Rev 2240
Line 244... Line 244...
244
        "module_name" : module_name,
244
        "module_name" : module_name,
245
        "module_id"   : module_id,
245
        "module_id"   : module_id,
246
        "group"       : false   });
246
        "group"       : false   });
247
       
247
       
248
        /* Must check sensor here in case no alias is stored the adress needs to be printed */
248
        /* Must check sensor here in case no alias is stored the adress needs to be printed */
-
 
249
        var RubicsonSuccess = "NoRubicsonSensor";
249
        var VikingSuccess = "NoVikingSensor";
250
        var VikingSuccess = "NoVikingSensor";
250
        var VikingSteakSuccess = "NoVikingSteakSensor";
251
        var VikingSteakSuccess = "NoVikingSteakSensor";
-
 
252
        if (variables["Protocol"] == "Rubicson")
-
 
253
        {
-
 
254
            /*
-
 
255
                      ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
-
 
256
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
-
 
257
            a = address, s = sign, t = temperature, h = humidity, c = crc
-
 
258
            */
-
 
259
            var data = variables["IRdata"];
-
 
260
            var unknown = rshift(data,26)&0x3FF;
-
 
261
            //var crc = data&0xFF;
-
 
262
            //var humidity = (data>>>8)&0xFF;
-
 
263
            var temp = (data>>>12)&0xFFF;
-
 
264
            var addr = rshift(data,24)&0x3;
-
 
265
            //var calccrc=crc8(rshift(data,8), 32);
-
 
266
                   
-
 
267
            var sign = (temp>>>11)&1;
-
 
268
            if (sign > 0)
-
 
269
            {
-
 
270
                temp = temp^0xFFF;
-
 
271
                temp += 1;
-
 
272
                temp = -temp;
-
 
273
            }
-
 
274
            temp = temp/10;
-
 
275
 
-
 
276
            RubicsonSuccess = "RubicsonNotFound";
-
 
277
           
251
        if (variables["Protocol"] == "Viking")
278
        } else if (variables["Protocol"] == "Viking")
252
        {
279
        {
253
            /*
280
            /*
254
                              ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
281
                              ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
255
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
282
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
256
            a = address, s = sign, t = temperature, h = humidity, c = crc
283
            a = address, s = sign, t = temperature, h = humidity, c = crc
Line 264... Line 291...
264
            var calccrc=crc8(rshift(data,8), 32);
291
            var calccrc=crc8(rshift(data,8), 32);
265
 
292
 
266
            var sign = (temp>>>11)&1;
293
            var sign = (temp>>>11)&1;
267
            temp = temp&0x7FF;
294
            temp = temp&0x7FF;
268
            if (sign > 0)
295
            if (sign > 0)
269
            {
296
            {
270
                temp = -temp;
297
                temp = -temp;
271
            }
298
            }
272
            temp = temp/10;
299
            temp = temp/10;
273
 
300
 
274
            VikingSuccess = "VikingNotFound";
301
            VikingSuccess = "VikingNotFound";
275
           
302
           
276
            if (unknown != 4)
303
            if (unknown != 4)
277
            {
304
            {
278
                Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m");
305
                Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m");
279
            }
306
            }
280
        } else if (variables["Protocol"] == "VikingSteak")
307
        } else if (variables["Protocol"] == "VikingSteak")
281
        {
308
        {
282
            var data = variables["IRdata"];
309
            var data = variables["IRdata"];
283
            var addr = (data>>>4)&0xFF;
310
            var addr = (data>>>4)&0xFF;
284
            var byte0 = rshift(data,32)&0xF;
311
            var byte0 = rshift(data,32)&0xF;
285
            var byte1 = rshift(data,28)&0xF;
312
            var byte1 = rshift(data,28)&0xF;
286
            var byte2 = rshift(data,24)&0xF;
313
            var byte2 = rshift(data,24)&0xF;
287
            var temp = Math.round((((((byte1^byte2)<<8)+((byte0^byte1)<<4)+byte0^10)-122)*5)/9);
314
            var temp = Math.round((((((byte1^byte2)<<8)+((byte0^byte1)<<4)+byte0^10)-122)*5)/9);
288
            VikingSteakSuccess = "VikingNotFound";
315
            VikingSteakSuccess = "VikingNotFound";
289
        }
316
        }
290
               
317
               
291
        loopAliases:    /* Label to break nested */
318
        loopAliases:    /* Label to break nested */
292
        for (var alias_name in aliases_data)
319
        for (var alias_name in aliases_data)
293
        {
320
        {
294
            if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] &&
321
            if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] &&
295
                aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"])
322
                aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"])
296
            {
323
            {
297
                switch (variables["Protocol"])
324
                switch (variables["Protocol"])
298
                {
325
                {
299
                    case "Viking":
326
                    case "Viking":
300
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
327
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
301
                        if (crc != calccrc)
328
                        if (crc != calccrc)
-
 
329
                        {
-
 
330
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
-
 
331
                            break loopAliases;
-
 
332
                        }
-
 
333
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
-
 
334
                        {
-
 
335
                            VikingSuccess = "VikingFound";
-
 
336
 
-
 
337
                            var last_value = {};
-
 
338
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
339
 
-
 
340
                            if (last_value_string)
-
 
341
                            {
-
 
342
                                last_value = eval("(" + last_value_string + ")");
-
 
343
                            }
-
 
344
 
-
 
345
                            var timestamp = get_time();
-
 
346
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
347
                            if (humidity<101)
-
 
348
                            {
-
 
349
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
-
 
350
                            }
-
 
351
 
-
 
352
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
353
                           
-
 
354
                            break loopAliases;
-
 
355
                        }
-
 
356
                        break;
-
 
357
                    }
-
 
358
                    case "Viking":
-
 
359
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
-
 
360
                        /*if (crc != calccrc)
302
                        {
361
                        {
303
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
362
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
304
                            break loopAliases;
363
                            break loopAliases;
305
                        }
364
                        }*/
306
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
365
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
307
                        {
366
                        {
308
                            VikingSuccess = "VikingFound";
367
                            RubicsonSuccess = "RubicsonFound";
309
 
368
 
310
                            var last_value = {};
369
                            var last_value = {};
311
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
370
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
312
 
371
 
313
                            if (last_value_string)
372
                            if (last_value_string)
314
                            {
373
                            {
315
                                last_value = eval("(" + last_value_string + ")");
374
                                last_value = eval("(" + last_value_string + ")");
316
                            }
-
 
317
 
-
 
318
                            var timestamp = get_time();
-
 
319
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
320
                            if (humidity<101)
-
 
321
                            {
-
 
322
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
-
 
323
                            }
375
                            }
324
 
376
 
-
 
377
                            var timestamp = get_time();
-
 
378
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
379
                            /*if (humidity<101)
-
 
380
                            {
-
 
381
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
-
 
382
                            }
-
 
383
                            */
325
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
384
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
326
                           
385
                           
327
                            break loopAliases;
386
                            break loopAliases;
328
                        }
387
                        }
329
                        break;
388
                        break;
330
                    }
389
                    }
331
                    case "VikingSteak":
390
                    case "VikingSteak":
332
                    {   /* Add alias with these specifics: Channel=0,Proto=VikingSteak,Address=<address of sensor> */
391
                    {   /* Add alias with these specifics: Channel=0,Proto=VikingSteak,Address=<address of sensor> */
333
                        /* if no Address is added to the alias, all vikingSteaksensors will match*/
392
                        /* if no Address is added to the alias, all vikingSteaksensors will match*/
334
                        if (aliases_data[alias_name]["specific"]["Address"] == undefined)
393
                        if (aliases_data[alias_name]["specific"]["Address"] == undefined)
335
                        {
394
                        {
336
                            VikingSteakSuccess = "VikingFound";
395
                            VikingSteakSuccess = "VikingFound";
337
                            var last_value = {};
396
                            var last_value = {};
338
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
397
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
339
 
398
 
-
 
399
                            if (last_value_string)
-
 
400
                            {
-
 
401
                                last_value = eval("(" + last_value_string + ")");
-
 
402
                            }
-
 
403
 
-
 
404
                            var timestamp = get_time();
-
 
405
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
406
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
-
 
407
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
408
                            break loopAliases;
-
 
409
                        }
-
 
410
                        else if (addr == aliases_data[alias_name]["specific"]["Address"])
-
 
411
                        {
-
 
412
                            VikingSteakSuccess = "VikingFound";
-
 
413
                            var last_value = {};
-
 
414
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
415
 
340
                            if (last_value_string)
416
                            if (last_value_string)
341
                            {
417
                            {
342
                                last_value = eval("(" + last_value_string + ")");
418
                                last_value = eval("(" + last_value_string + ")");
343
                            }
419
                            }
344
 
420
 
345
                            var timestamp = get_time();
421
                            var timestamp = get_time();
346
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
422
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
347
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
423
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
348
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
424
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
425
                           
-
 
426
                            break loopAliases;
-
 
427
                        }
-
 
428
                        break;
-
 
429
                    }
-
 
430
                    case "Rubicson":
-
 
431
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
-
 
432
                        if (crc != calccrc)
-
 
433
                        {
-
 
434
                            Log("\033[31mError: Rubicson, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
349
                            break loopAliases;
435
                            break loopAliases;
350
                        }
436
                        }
351
                        else if (addr == aliases_data[alias_name]["specific"]["Address"])
437
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
352
                        {
438
                        {
353
                            VikingSteakSuccess = "VikingFound";
439
                            VikingSuccess = "VikingFound";
-
 
440
 
354
                            var last_value = {};
441
                            var last_value = {};
355
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
442
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
356
 
443
 
357
                            if (last_value_string)
444
                            if (last_value_string)
358
                            {
445
                            {
359
                                last_value = eval("(" + last_value_string + ")");
446
                                last_value = eval("(" + last_value_string + ")");
360
                            }
447
                            }
361
 
448
 
362
                            var timestamp = get_time();
449
                            var timestamp = get_time();
363
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
450
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
451
                            if (humidity<101)
-
 
452
                            {
364
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
453
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
-
 
454
                            }
-
 
455
 
365
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
456
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
366
                           
457
                           
367
                            break loopAliases;
458
                            break loopAliases;
368
                        }
459
                        }
369
                        break;
460
                        break;
370
                    }
461
                    }
371
                    case "Nexa2":
462
                    case "Nexa2":
372
                    {   /* Add alias with these specifics: Channel=0,Proto=Nexa2,OnData=<data for on>,OffData=<data for off> */
463
                    {   /* Add alias with these specifics: Channel=0,Proto=Nexa2,OnData=<data for on>,OffData=<data for off> */
373
                        var deviceStateCommand = "";
464
                        var deviceStateCommand = "";
Line 378... Line 469...
378
                        else if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OffData"] && variables["Status"] == "Pressed")
469
                        else if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OffData"] && variables["Status"] == "Pressed")
379
                        {
470
                        {
380
                            deviceStateCommand = "Off";
471
                            deviceStateCommand = "Off";
381
                        }
472
                        }
382
                        else
473
                        else
383
                        {
474
                        {
384
                            break;
475
                            break;
385
                        }
476
                        }
386
                       
477
                       
387
                        var last_value = {};
478
                        var last_value = {};
388
                        var last_value_string = Storage_GetParameter("LastValues", alias_name);
479
                        var last_value_string = Storage_GetParameter("LastValues", alias_name);
Line 420... Line 511...
420
            Log("Found unknown vikingsensor address="+addr+" temperature="+temp+" humidity="+humidity+" unknown="+unknown);
511
            Log("Found unknown vikingsensor address="+addr+" temperature="+temp+" humidity="+humidity+" unknown="+unknown);
421
        }
512
        }
422
        if (VikingSteakSuccess == "VikingNotFound")
513
        if (VikingSteakSuccess == "VikingNotFound")
423
        {
514
        {
424
            Log("Found unknown vikingSteaksensor address="+addr+" temperature="+temp);
515
            Log("Found unknown vikingSteaksensor address="+addr+" temperature="+temp);
-
 
516
        }
-
 
517
        if (RubicsonSuccess == "RubicsonNotFound")
-
 
518
        {
-
 
519
            Log("Found unknown Rubicson sensor address="+addr+" temperature="+temp);
425
        }
520
        }
426
    }
521
    }
427
}
522
}
428
Module_RegisterToOnMessage("all", SensorRf_OnMessage);
523
Module_RegisterToOnMessage("all", SensorRf_OnMessage);
429
 
524