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 #8: pubNub on CC3100
  • 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 2:51 AM Date Created
  • Views 376 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Safe & Sound -Flood early-warning Alarm Pack #8: pubNub on CC3100

fyaocn
fyaocn
28 Jun 2017

1. The CC3100 BoostPack can be plugged into the MSP432 lauchpad for wifi connection, with the following block diagram.

image

with Hardware Features

• 2x20 pin stackable connectors

• On-board chip antenna with option for U.FL-based conducted testing

• Power from on-board LDO using USB or 3.3 V from MCU LaunchPad

• Three push buttons

• Two LEDs

• Jumper for current measurement with provision to mount 0.1R resistor for measurement with voltmeter

• 8 Mbit serial flash (M25PX80 from Micron)

• 40 MHz crystal, 32 KHz crystal and optional 32 KHz oscillator

 

Hardware connection as

image

 

2. To use PubNub service, one app shall be created,

image

the publish and subscribe keys are set automatically.

image

3. The open energia for PubNubDemo sketch, with code,

#include <SPI.h>
#include <WiFi.h>
#include <PubNub.h>


const int subLedPin = RED_LED;
const int pubLedPin = RED_LED;


char pubkey[] = "demo";
char subkey[] = "demo";
char channel[] = "hello_world";


// your network name also called SSID
char ssid[] = "flood";
// your network password
char password[] = "xxxxxxxx";


void setup()
{
  pinMode(subLedPin, OUTPUT);
  pinMode(pubLedPin, OUTPUT);
  digitalWrite(subLedPin, LOW);
  digitalWrite(pubLedPin, LOW);


  Serial.begin(115200);
  Serial.println("Serial set up");


  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid); 
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
  // print dots while we wait to connect
  Serial.print(".");
  delay(300);
  }


  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");


  while (WiFi.localIP() == INADDR_NONE) {
  // print dots while we wait for an ip addresss
  Serial.print(".");
  delay(300);
  }


  Serial.println("\nIP Address obtained");
  // We are connected and have an IP address.
  // Print the WiFi status.
  printWifiStatus();


  PubNub.begin(pubkey, subkey);
  Serial.println("PubNub set up");
}


void flash(int ledPin)
{
  /* Flash LED three times. */
  for (int i = 0; i < 3; i++) {
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  }
}


void loop()
{
  WiFiClient *client;


  Serial.println("publishing a message");
  client = PubNub.publish(channel, "\"\\\"Hello world!\\\" she said.\"");
  if (!client) {
  Serial.println("publishing error");
  delay(1000);
  return;
  }
  while (client->connected()) {
  while (client->connected() && !client->available()) ; // wait
  char c = client->read();
  Serial.print(c);
  }
  client->stop();
  Serial.println();
  flash(pubLedPin);


  Serial.println("waiting for a message (subscribe)");
  PubSubClient *pclient = PubNub.subscribe(channel);
  if (!pclient) {
  Serial.println("subscription error");
  delay(1000);
  return;
  }
  while (pclient->wait_for_data()) {
  char c = pclient->read();
  Serial.print(c);
  }
  pclient->stop();
  Serial.println();
  flash(subLedPin);


  Serial.println("retrieving message history");
  client = PubNub.history(channel);
  if (!client) {
  Serial.println("history error");
  delay(1000);
  return;
  }
  while (client->connected()) {
  while (client->connected() && !client->available()) ; // wait
  char c = client->read();
  Serial.print(c);
  }
  client->stop();
  Serial.println();


  delay(10000);
}

 

In this sketch subscribe key and publish key shall be put to proper value above.

image

  • 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