element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
  • About Us
  • 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
Safe and Sound
  • Challenges & Projects
  • Design Challenges
  • Safe and Sound
  • More
  • Cancel
Safe and Sound
Blog Safe & Sound -Flood early-warning Alarm Pack #9: pubNub on Website for Flood Alarm
  • 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: fyaocn
  • Date Created: 28 Jun 2017 6:10 AM Date Created
  • Views 476 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Safe & Sound -Flood early-warning Alarm Pack #9: pubNub on Website for Flood Alarm

fyaocn
fyaocn
28 Jun 2017

1. PubNub.com has provided great tools for publish channel over PubNub service over internet, the website can response to the request by subscribe the channel, only subscribe key is needed for this service. Of course, this can be done by AWS IoT service, but PubNub is the easiest and secure.

2. I have registered one simple website for this project as flood_alarm,

image

Then power the development board with CC3100 boostpack plugged, waiting for publish over pubNub,

image

The web subscribe the channel and response with flooding now alert.

image

3. Now the design loop closes. The alarm pack get water level by capacitive sensing, publish the topic (or Channel) via pubNub service to web portal that subscribe the topic (or Channel).

More service like SMS can be added later. Now I can  polish the code and adjust the parameter.

4. Reference code for pubnub Web,

<script>
  // Application object.
  var app = {}
var pubnub = new PubNub({
    subscribeKey: 'sub-c-xxxxxxxxxxxxxxxxxxxxxxxx', // always required
    publishKey: 'pub-c-xxxxxxxxxxx' // only required if publishing
});
pubnub.addListener({
    status: function(statusEvent) {
        if (statusEvent.category === "PNConnectedCategory") {
            var payload = {
                my: 'payload'
            };
            pubnub.publish(
                { 
                    message: payload
                }, 
                function (status) {
                    // handle publish response
                }
            );
        }
    },
    message: function(message) {
        // handle message
app.showMessage("---Flooding Now----");
    },
    presence: function(presenceEvent) {
        // handle presence
    }
})

pubnub.subscribe({
    channels: ['flood_alarm_signal']
});


  // Connected device.
  app.device = null;
  app.showMessage = function(info)
  {
  document.getElementById('info').innerHTML = info
  };
  </script> 

for html design,

<!DOCTYPE html>
<html>
<!--
This is an demo app for Flood Alarm Alert
-->
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, user-scalable=no
  initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
  <title>Flood Alarm Pack Website</title>
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.12.0.js"></script>
</head>
<body ontouchstart="" ><!-- ontouchstart="" enables low-delay CSS transitions. -->
  <header align="center">
  <button class="back" onclick="history.back()">
  <img src="back.jpg" />
  </button>
  <img class="logotype" src="flood_alarm.jpg" alt="Evothings" />
  </header>
  <h1 align="center"> Flood Alarm Pack  </h1>
  <p id="info" align="center" >Initializing...</p>
</body>
</html>

  • Sign in to reply
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