Subversion Repositories HomeAutomation

Rev

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

Rev 2240 Rev 2257
Line 1... Line 1...
1
 
1
 
2
Sensor_ModuleNames    = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF", "DHT11", "VoltageCurrent", "ultrasonic" ];
2
Sensor_ModuleNames    = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF", "DHT11", "VoltageCurrent", "ultrasonic", "flower" ];
3
SensorRf_ModuleNames    = [ "rfTransceive" ];
3
SensorRf_ModuleNames    = [ "rfTransceive" ];
4
Sensor_Intervals      = function() { return [ 1, 5, 10, 15, 20 ]; };
4
Sensor_Intervals      = function() { return [ 1, 5, 10, 15, 20 ]; };
5
Sensor_Aliases        = function() { return Module_GetAliasNames(Sensor_ModuleNames); };
5
Sensor_Aliases        = function() { return Module_GetAliasNames(Sensor_ModuleNames); };
6
Sensor_AvailableIds   = function() { return Module_GetAvailableIds(Sensor_ModuleNames); };
6
Sensor_AvailableIds   = function() { return Module_GetAvailableIds(Sensor_ModuleNames); };
7
 
7
 
Line 221... Line 221...
221
 
221
 
222
          if (last_value_string)
222
          if (last_value_string)
223
          {
223
          {
224
            last_value = eval("(" + last_value_string + ")");
224
            last_value = eval("(" + last_value_string + ")");
225
          }
225
          }
226
 
-
 
227
          last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() };
226
      last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() };
228
 
-
 
229
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
227
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
230
        }
228
        }
231
 
229
 
232
        break;
230
        break;
233
      }
231
      }
234
    }
232
    }
235
  }
233
  }
236
}
234
}
237
Module_RegisterToOnMessage("all", Sensor_OnMessage);
235
Module_RegisterToOnMessage("all", Sensor_OnMessage);
238
 
236
 
239
function SensorRf_OnMessage(module_name, module_id, command, variables)
237
function SensorRf_OnMessage(module_name, module_id, command, variables)
240
{
238
{
-
 
239
 
241
    if (in_array(SensorRf_ModuleNames, module_name))
240
    if (in_array(SensorRf_ModuleNames, module_name))
242
    {
241
    {
243
        var aliases_data = Module_LookupAliases({
242
        var aliases_data = Module_LookupAliases({
244
        "module_name" : module_name,
243
        "module_name" : module_name,
245
        "module_id"   : module_id,
244
        "module_id"   : module_id,
246
        "group"       : false   });
245
        "group"       : false   });
247
       
246
       
248
        /* Must check sensor here in case no alias is stored the adress needs to be printed */
247
        /* Must check sensor here in case no alias is stored the adress needs to be printed */
249
        var RubicsonSuccess = "NoRubicsonSensor";
248
        var RubicsonSuccess = "NoRubicsonSensor";
-
 
249
        var OregonRainSuccess = "NoSensor";
-
 
250
        var OregonTempHumSuccess = "NoSensor";
-
 
251
        var OregonWindSuccess = "NoSensor";
250
        var VikingSuccess = "NoVikingSensor";
252
        var VikingSuccess = "NoVikingSensor";
251
        var VikingSteakSuccess = "NoVikingSteakSensor";
253
        var VikingSteakSuccess = "NoVikingSteakSensor";
-
 
254
        //Log("found sensor: "+variables["Protocol"]);
-
 
255
        if (variables["Protocol"] == "OregonRain")
-
 
256
        {
-
 
257
            /* ----------- Data order proto-data ------
-
 
258
            * cc bb bb bb aa aa
-
 
259
            * a   = Rain in 0.01 inches per hour
-
 
260
            * b   = Total Rain in 0.001 inches
-
 
261
            * cc   = 0xddefffff
-
 
262
            *   dd = Channel
-
 
263
            *   e  = Battery low flag
-
 
264
            *   fffff = Lower part of rolling code
-
 
265
            * -----------------------------*/
-
 
266
            var data = variables["IRdata"];
-
 
267
            var inchPerHour = (data)&0xFFFF;
-
 
268
            inchPerHour = inchPerHour/100;
-
 
269
            var totInch = (data>>>16)&0xFFFFFF;
-
 
270
            totInch = totInch/1000;
-
 
271
            var totMM = totInch * 25.4;
-
 
272
            var mmPerHour = inchPerHour * 25.4;
-
 
273
           
-
 
274
            var addr = rshift(data,46)&0x3;
-
 
275
            var bat = rshift(data,45)&0x1;
-
 
276
            var unknown = rshift(data,40)&0x1F;
-
 
277
 
-
 
278
            OregonRainSuccess = "NotFound";
-
 
279
           
-
 
280
        } else if (variables["Protocol"] == "OregonTempHum")
-
 
281
        {
-
 
282
               /* ----------- Data order proto-data ------
-
 
283
            * cc 00 00 bb bb aa
-
 
284
            * aa   = Humidity in %
-
 
285
            * bbbb = Temperature*10 in celcius
-
 
286
            * cc   = 0xddefffff
-
 
287
            *   dd = Channel
-
 
288
            *   e  = Battery low flag
-
 
289
            *   fffff = Lower part of rolling code
-
 
290
            * -----------------------------*/  
-
 
291
            var data = variables["IRdata"];
-
 
292
            var humidity = (data)&0xFF;
-
 
293
            var temp = (data>>>8)&0x7FFF;
-
 
294
            var sign = (temp>>>23)&1;
-
 
295
            if (sign > 0)
-
 
296
            {
-
 
297
                temp = temp^0x7FFF;
-
 
298
                temp += 1;
-
 
299
                temp = -temp;
-
 
300
            }
-
 
301
            temp = temp/10;
-
 
302
            var addr = rshift(data,46)&0x3;
-
 
303
            var bat = rshift(data,45)&0x1;
-
 
304
            var unknown = rshift(data,40)&0x1F;
-
 
305
 
-
 
306
            OregonTempHumSuccess = "NotFound";
-
 
307
           
-
 
308
        } else if (variables["Protocol"] == "OregonWind")
-
 
309
        {
-
 
310
            /* ----------- Data order proto-data ------
-
 
311
            * cc 00 0d bb ba aa
-
 
312
            * aaa  = wind speed average (in 0.1m/s)
-
 
313
            * bbb  = wind speed current (in 0.1m/s)
-
 
314
            * d    = Direction in 22.5 degrees
-
 
315
            * cc   = 0xddefffff
-
 
316
            *   dd = Channel
-
 
317
            *   e  = Battery low flag
-
 
318
            *   fffff = Lower part of rolling code
-
 
319
            * -----------------------------*/
-
 
320
            var data = variables["IRdata"];
-
 
321
            var average = (data)&0xFFF;
-
 
322
            average = average/10;
-
 
323
           
-
 
324
            var current = rshift(data,12)&0xFFF;
-
 
325
            current = current/10;
-
 
326
           
-
 
327
            var direction = rshift(data,24)&0xF;
-
 
328
            direction = direction*22.5;
-
 
329
           
-
 
330
            var addr = rshift(data,46)&0x3;
-
 
331
            var bat = rshift(data,45)&0x1;
-
 
332
            var unknown = rshift(data,40)&0x1F;
-
 
333
 
-
 
334
            OregonWindSuccess = "NotFound";
-
 
335
           
252
        if (variables["Protocol"] == "Rubicson")
336
        } else if (variables["Protocol"] == "Rubicson")
253
        {
337
        {
254
            /*
338
            /*
255
                      ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
339
                      ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
256
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
340
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
257
            a = address, s = sign, t = temperature, h = humidity, c = crc
341
            a = address, s = sign, t = temperature, h = humidity, c = crc
Line 295... Line 379...
295
            if (sign > 0)
379
            if (sign > 0)
296
            {
380
            {
297
                temp = -temp;
381
                temp = -temp;
298
            }
382
            }
299
            temp = temp/10;
383
            temp = temp/10;
300
 
384
 
301
            VikingSuccess = "VikingNotFound";
385
            VikingSuccess = "VikingNotFound";
302
           
386
           
303
            if (unknown != 4)
387
            if (unknown != 4)
304
            {
388
            {
305
                Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m");
389
                Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m");
306
            }
390
            }
307
        } else if (variables["Protocol"] == "VikingSteak")
391
        } else if (variables["Protocol"] == "VikingSteak")
308
        {
392
        {
309
            var data = variables["IRdata"];
393
            var data = variables["IRdata"];
310
            var addr = (data>>>4)&0xFF;
394
            var addr = (data>>>4)&0xFF;
311
            var byte0 = rshift(data,32)&0xF;
395
            var byte0 = rshift(data,32)&0xF;
Line 323... Line 407...
323
            {
407
            {
324
                switch (variables["Protocol"])
408
                switch (variables["Protocol"])
325
                {
409
                {
326
                    case "Viking":
410
                    case "Viking":
327
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
411
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
328
                        if (crc != calccrc)
412
                        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)
-
 
361
                        {
413
                        {
362
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
414
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
363
                            break loopAliases;
415
                            break loopAliases;
364
                        }*/
416
                        }
365
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
417
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
366
                        {
418
                        {
-
 
419
                            VikingSuccess = "VikingFound";
-
 
420
 
-
 
421
                            var last_value = {};
-
 
422
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
423
 
-
 
424
                            if (last_value_string)
-
 
425
                            {
-
 
426
                                last_value = eval("(" + last_value_string + ")");
-
 
427
                            }
-
 
428
 
-
 
429
                            var timestamp = get_time();
-
 
430
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
-
 
431
                            if (humidity<101)
-
 
432
                            {
-
 
433
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
-
 
434
                            }
-
 
435
 
-
 
436
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
437
                           
-
 
438
                            break loopAliases;
-
 
439
                        }
-
 
440
                        break;
-
 
441
                    }
-
 
442
                    case "Viking":
-
 
443
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
-
 
444
                        /*if (crc != calccrc)
-
 
445
                        {
-
 
446
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
-
 
447
                            break loopAliases;
-
 
448
                        }*/
-
 
449
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
-
 
450
                        {
367
                            RubicsonSuccess = "RubicsonFound";
451
                            RubicsonSuccess = "RubicsonFound";
368
 
452
 
369
                            var last_value = {};
453
                            var last_value = {};
370
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
454
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
371
 
455
 
372
                            if (last_value_string)
456
                            if (last_value_string)
Line 430... Line 514...
430
                    case "Rubicson":
514
                    case "Rubicson":
431
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
515
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
432
                        if (crc != calccrc)
516
                        if (crc != calccrc)
433
                        {
517
                        {
434
                            Log("\033[31mError: Rubicson, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
518
                            Log("\033[31mError: Rubicson, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
435
                            break loopAliases;
519
                            break loopAliases;
436
                        }
520
                        }
437
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
521
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
438
                        {
522
                        {
439
                            VikingSuccess = "VikingFound";
523
                            VikingSuccess = "VikingFound";
440
 
524
 
441
                            var last_value = {};
525
                            var last_value = {};
442
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
526
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
443
 
527
 
444
                            if (last_value_string)
528
                            if (last_value_string)
445
                            {
529
                            {
446
                                last_value = eval("(" + last_value_string + ")");
530
                                last_value = eval("(" + last_value_string + ")");
447
                            }
531
                            }
448
 
532
 
449
                            var timestamp = get_time();
533
                            var timestamp = get_time();
450
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
534
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
451
                            if (humidity<101)
535
                            if (humidity<101)
Line 515... Line 599...
515
            Log("Found unknown vikingSteaksensor address="+addr+" temperature="+temp);
599
            Log("Found unknown vikingSteaksensor address="+addr+" temperature="+temp);
516
        }
600
        }
517
        if (RubicsonSuccess == "RubicsonNotFound")
601
        if (RubicsonSuccess == "RubicsonNotFound")
518
        {
602
        {
519
            Log("Found unknown Rubicson sensor address="+addr+" temperature="+temp);
603
            Log("Found unknown Rubicson sensor address="+addr+" temperature="+temp);
-
 
604
        }
-
 
605
        if (OregonTempHumSuccess == "NotFound")
-
 
606
        {
-
 
607
            Log("Found unknown oregon temp/humidity sensor address="+addr+" temperature="+temp +" humidity="+humidity+" unknown="+unknown + " bat="+bat);
-
 
608
        }
-
 
609
        if (OregonRainSuccess == "NotFound")
-
 
610
        {
-
 
611
            Log("Found unknown oregon rain sensor address="+addr+" tot inch="+totInch +" totMM="+totMM+" inch/h="+inchPerHour + " mm/h="+mmPerHour +" bat="+bat);
-
 
612
        }
-
 
613
        if (OregonWindSuccess == "NotFound")
-
 
614
        {
-
 
615
            Log("Found unknown oregon wind sensor address="+addr+" Average="+average +" current="+current+" direction="+direction +" bat="+bat);
520
        }
616
        }
521
    }
617
    }
522
}
618
}
523
Module_RegisterToOnMessage("all", SensorRf_OnMessage);
619
Module_RegisterToOnMessage("all", SensorRf_OnMessage);
524
 
620