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

捕获.JPG

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

捕获.JPG

 

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

捕获.JPG

the publish and subscribe keys are set automatically.

捕获.JPG

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.

捕获.JPG