element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog [Upcycle It] WiFi Connected Smoke Detector #3: Connecting dots - MQTT + Node.js + Slack
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 8 Apr 2017 8:53 PM Date Created
  • Views 1457 views
  • Likes 6 likes
  • Comments 8 comments
  • mqtt
  • node
  • slack
Related
Recommended

[Upcycle It] WiFi Connected Smoke Detector #3: Connecting dots - MQTT + Node.js + Slack

vlasov01
vlasov01
8 Apr 2017
<< Previous

Project Index

Next >>

Integration Design

 

Once sensor detects smoke, it will publish a message to MQTT topic. Then this message will be passed to a mobile application and at the same time will be converted to a command to switch of all connected electric appliances in the room where smoke has been detected. It is important to define the topic model before coding.

image

 

MQTT Topics structure

 

I've used a topics structure from a best practices article as a starting point. I've defined a topic structure for home monitor/sensor/appliances:

 

An alarm sensor topic structure for this

<location>/<alarm>/<sensor type>/<connected>|<state>

Examples:

kitchen/alarm/smoke/connected

kitchen/alarm/smoke/state

 

A monitor topic structure

<location>/<alarm>/<monitor type>/<connected>

Example:

home/alarm/monitor/connected

 

An appliance topic structure

<location>/<appliance>/<appliance type>/<connected>|<command>

Example:

kitchen/appliance/oven/power

 

MQTT messages to topics

 

To simplify things I've decided that a message to these topics can be published as true or false.

Examples:

 

1. A smoke alarm is connected in a kitchen:

kitchen/alarm/smoke/connected/true

 

2. A smoke alarm in a kitchen detected smoke:

kitchen/alarm/smoke/state/true

 

3. A command to turn power off for an oven in a kitchen:

kitchen/appliance/oven/power/off

 

4. A command to turn off socket 1 of PDU (see PDU Upcycle project) in a workshop:

workshop/appliance/pdu-socket1/power/off

 

5. A command to turn off outlet 1 of ESP8266-01 and MQTT for AC Outlet Control  project by codemonkey0 in a workshop:

workshop/appliance/outlet1/power/off

 

I need to validate this topics model approach with jasonwier92

 

Home Alert Monitor

 

Node.js is a nice platform to create a small server. In my project it will be listening to MQTT topics, sending commands and communication with mobile/web channel.

 

MQTT Node.js client Installation

 

Node.js is already installed on Edison. I've added Node MQTT client:

npm install mqtt -g
mqtt@2.5.1 /usr/lib/node_modules/mqtt
├── inherits@2.0.3
├── reinterval@1.1.0
├── xtend@4.0.1
├── minimist@1.2.0
├── concat-stream@1.6.0 (typedarray@0.0.6)
├── commist@1.0.0 (leven@1.0.2)
├── split2@2.1.1 (through2@2.0.3)
├── end-of-stream@1.4.0 (once@1.4.0)
├── pump@1.0.2 (once@1.4.0)
├── mqtt-packet@5.2.2 (process-nextick-args@1.0.7, bl@1.2.0)
├── readable-stream@2.2.6 (buffer-shims@1.0.0, string_decoder@0.10.31, util-deprecate@1.0.2, process-nextick-args@1.0.7, core-util-is@1.0.2, isarray@1.0.0)
├── websocket-stream@3.3.3 (through2@2.0.3, ws@1.1.4, duplexify@3.5.0)
└── help-me@1.0.1 (through2@2.0.3, callback-stream@1.1.0, glob-stream@5.3.5)

 

For test I've opened two SSH terminals to Edison board.

One to subscribe to a test topic

mqtt sub -t 'test' -h 'localhost' -v

 

and one to send a test message

mqtt pub -t 'test' -h 'localhost' -m 'from MQTT.js'

 

and got the message in the first window:

test from MQTT.js

 

Slack client Installation

I'm planning to use Slack mobile application to display a state of the alarm system on the go. Slack allows to create a free channels which can be used by teams/families.

 

npm install @slack/client -g
@slack/client@3.9.0 /usr/lib/node_modules/@slack/client
├── inherits@2.0.3
├── eventemitter3@1.2.0
├── url-join@0.0.1
├── async@1.5.2
├── retry@0.9.0
├── pkginfo@0.4.0
├── ws@1.1.4 (options@0.0.6, ultron@1.0.2)
├── bluebird@3.5.0
├── https-proxy-agent@1.0.0 (extend@3.0.0, debug@2.6.3, agent-base@2.0.1)
├── winston@2.3.1 (cycle@1.0.3, stack-trace@0.0.9, eyes@0.1.8, isstream@0.1.2, async@1.0.0, colors@1.0.3)
├── request@2.81.0 (aws-sign2@0.6.0, oauth-sign@0.8.2, tunnel-agent@0.6.0, forever-agent@0.6.1, caseless@0.12.0, is-typedarray@1.0.0, stringstream@0.0.5, safe-buffer@5.0.1, aws4@1.6.0, isstream@0.1.2, extend@3.0.0, json-stringify-safe@5.0.1, performance-now@0.2.0, uuid@3.0.1, qs@6.4.0, combined-stream@1.0.5, mime-types@2.1.15, tough-cookie@2.3.2, form-data@2.1.2, hawk@3.1.3, http-signature@1.1.1, har-validator@4.2.1)
└── lodash@4.17.4

 

The next step is to create a channel and obtain a token for integration with Slack API.

  • Sign in to reply

Top Comments

  • jasonwier92
    jasonwier92 over 8 years ago +2
    Very good write up and thought into your topic. I really like the idea, and I have never done this, is put in if a device type, assuming it is only doing one function. But in reality, the MQTT topic for…
  • vlasov01
    vlasov01 over 8 years ago in reply to mcb1 +1
    Thank you for the feedback! I've added a diagram to clarify events processing sequence. Sergey
  • vlasov01
    vlasov01 over 8 years ago in reply to jasonwier92 +1
    Hi Jason, Thank you a lot for the feedback. I've started coding. I'll publish my Node.js code this week. Here is the part responsible for subscription to smoke detector alarms state/connection state from…
Parents
  • mcb1
    mcb1 over 8 years ago

    Good post setting out all the options.

     

    On our systems we have the four states, connected, stale (not there), alarms, okay.

    These states can be expanded to include :- local (tech working on it), bypass, on battery and quite a few others.

     

    You may wish to ensure that the detection end will respond correctly without having to individually check each state.

    ie when a smoke detector goes off (*/alarm/smoke/state/true), you want to shut down power on every connected device, or just the workshop.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 8 years ago in reply to mcb1

    Thank you for the feedback!

    I've added a diagram to clarify events processing sequence.

     

    Sergey

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • vlasov01
    vlasov01 over 8 years ago in reply to mcb1

    Thank you for the feedback!

    I've added a diagram to clarify events processing sequence.

     

    Sergey

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube