<< Previous |
Connectivity alternatives
My initial idea was to connect Edison directly to the smoke detector. But I've read a post by Peter Scargill mentioned early by mcb1
In this post Peter was talking about Alarm Smoke Notifier, which is using audio signal instead of embedded connection. I've analyzed pros and cons of both options.
Criteria | Audio Link | Embedding |
---|---|---|
Coding complexity | Medium (separating noise from detector sound) | High (power mode complexity) |
Energy budget | Separate power source | Negative impact on battery life for a detector not connected to power external source |
Detector impact | No impact | Need to solder cables. May loose warranty on detector. May be prohibited by law in some jurisdictions. |
Cabling | No new cabling | Cabling is required to connect Edison board to detector |
Esthetic | No change (Edison board can be placed anywhere in the same room with detector) | Additional cables and board may have a negative impact |
Cost | Additional low cost audio sensor. One device may able to connect several smoke detectors in the same room. | Cabling and fixture. Need to connect to each smoke detector. |
After this analysis I've decided to start with the Audio Link option.
Edison meets Grove Starter Kit for Arduino
Grove Starter Kit for Arduino includes audio sensor. It took just a couple of minutes to connect parts. Then I've tested it with Spectrum Analyzer. I've followed the instruction and it worked very well right away. I as well added a LED as indicator and a switch button. I'm planning to use it latter for automatic calibration to reduce number of false positives as different smoke detectors may have different audio signature. The distance between smoke detector and microphone plays role as well.
Detector Interface Coding
I've used Libmraa to interface node.js program with the analog audio sensor. The same library has been used in the Spectrum Analyzer. This C/C++ library has as well bindings to Java and Python. The initial programming of the detector interface module was pretty straightforward as I used a tutorial from Seeed. But it took some time to manually adjust thresholds and other parameters. So I hoping to automate this process.
try { console.log(require.resolve("mraa")); // libmraa - Low Level Skeleton Library for Communication var mraa = require('mraa'); // Analog audio sensor attached to pin 0 var audio = new mraa.Aio(0); // Set the audio threshold var threshold = 470; // Wait before trigger alarm to reduce false positives var audioCounter = 0; var state = false; // Run the function to start out processAudio(); client.publish(kitchen_alarm_topic, 'true', {qos: 2, retain: true}, function() { console.log("Kitchen alarms detector connected"); client.publish(kitchen_alarm_state_topic, 'false', {qos: 2, retain: true}); }); } catch(e) { console.error("mraa is not found"); client.publish(kitchen_alarm_topic, 'false', {qos: 2, retain: true}, function() { console.log("Kitchen alarms detector not connected"); }); //process.exit(e.code); } // Declare the sound check function function processAudio(){ // read the value to start off var level = audio.read(); // If the sound is higher than the threshold, make the request if(level >= threshold){ audioCounter=audioCounter+10; console.log('Above treashold ' + level + ' counter ' + audioCounter); setTimeout(processAudio, 100); if(audioCounter>50){ state = true; setTimeout(processAudio, 60*1000); //wait 60 seconds before activating it again client.publish(kitchen_alarm_state_topic, 'true', {qos: 2, retain: true}, function() { console.log('Audio alarm detected ' + level + ' counter ' + audioCounter); }); audioCounter=0; //reset counter } } else { if(audioCounter>0){ audioCounter--; }else if(state){ state = false; //switch off alarm client.publish(kitchen_alarm_state_topic, 'false', {qos: 2, retain: true}, function() { console.log('Audio alarm switched off ' + level + ' counter ' + audioCounter); }); } setTimeout(processAudio, 100); console.log(level + ' counter ' + audioCounter); } }
Summary
Now I have to programs - one central monitor, which can work with multiple detectors and detector interface. They communicate over MQTT
To Do List
- Resolve issue with switching alarm state off to fast.
- Build and test disconnect a connected appliance scenario.
- Find a box to fit the board.
- Implement auto calibration of alarm sound detection algorithm.
- Publish code to my github repo.
Top Comments