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
  • 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
Design for a Cause - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Design for a Cause - Design Challenge
  • More
  • Cancel
Design for a Cause - Design Challenge
Blog Blowing-Whistle as Controller(BWaC) -----Build Android APP  for Pubnub service #7
  • 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: 3 Sep 2018 3:39 AM Date Created
  • Views 737 views
  • Likes 3 likes
  • Comments 0 comments
  • blowing-whistle as controller
Related
Recommended

Blowing-Whistle as Controller(BWaC) -----Build Android APP  for Pubnub service #7

fyaocn
fyaocn
3 Sep 2018

1. The pubnub service features full SDK support with over 70 platform and programming language. That gives more choice for developers for creative. In fact, the free network service always means more payment sacrificing better performance or leakage of personal data.

I have used one IoT platform service, until I notice my data is sending back to  one famous Search Engine Analysis Server.  At least, this delay my access to the IoT service.

The pubnub runs well on arduino. And good in mobile too.

I would like to make the BWaC traceable, using pubnub service in android application.

2. There have been two choice for android development, eclipse SDK or android studio. It would be easy for android studio for quick development and deployment.

2.1 The updated version is Android Studio 3.1.4. Start one new project,

image

 

2.2 Then, using Gradle (Including Android Studio), include the following line in build.gradle,

compile group: 'com.pubnub', name: 'pubnub-gson', version: '4.19.0'

While the following  would be better,

implementation group: 'com.pubnub', name: 'pubnub-gson', version: '4.19.0'

 

Put these permission outside the <application> tag, preferable before the tag in the AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bwac">


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permi

ssion.ACCESS_NETWORK_STATE"/>


    <application

 

2.3 Program in the MainActivity.java as follows,

Creating PNconnection,

        PNConfiguration pnConfiguration = new PNConfiguration();
        pnConfiguration.setSubscribeKey("demo");
        pnConfiguration.setPublishKey("demo");
        PubNub pubnub = new PubNub(pnConfiguration);

add listeners

  pubnub.addListener(new SubscribeCallback()

subscribe to channel "bwac",

pubnub.subscribe().channels(Arrays.asList("bwac")).execute();

 

2.4 Print out message received from pubnub channel in

            @Override
            public void message(PubNub pubnub, PNMessageResult message) {
                // Handle new message stored in message.message
                if (message.getChannel() != null) {
                }
                else {
                }
                System.out.println(message.getMessage() );
                received(  );
            }

,

3. The run the arduino sketch in last blog,

image

Received by android application.

image

This test is passed.

  • 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