Things used in this project

Code

Encode JSON & Publish to PubNubArduino
This is the main task in Energia. It will encode the latest sensor readings into a JSON payload & publish it up to PubNub. Be sure to modify this code example with your WiFi credentials & appropriate PubNub pub/sub keys & channel.
/*
  PubNub sample client

  This sample client will publish raw (JSON pre-encoded) PubNub messages.

  This code is in the public domain.
  */

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

WiFiClient *client;
PubSubClient *subClient;
  
char pubkey[] = "ADD_YOUR_PUBKEY_HERE";
char subkey[] = "ADD_YOUR_SUBKEY_HERE";
char* channel = "ADD_YOUR_CHANNEL_HERE";
//char subChannel[] = "hello_world_sub";

// your network name also called SSID
char ssid[] = "ADD_YOUR_WIFI_SSID_HERE";
// your network password
char password[] = "ADD_YOUR_WIFI_PASSWORD_HERE";

//GLOBAL VARIABLES
int MOISTURE = 0;
int LIGHT = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Serial set up");

  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  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");

  // Print the WiFi status.
  printWifiStatus();

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

void loop()
{
  
    // CREATE JSON ENCODED PAYLOAD TO PUBLISH
    aJsonObject *msg = createMessage();
    char* myPayload = (char*)aJson.print(msg);
  
    client = PubNub.publish(channel, myPayload);  // https://jsfiddle.net/qc3bzzjx/embedded/result/
    Serial.print("published message: ");
    Serial.println(myPayload);
    aJson.deleteItem(msg);
    free(myPayload);
    
    delay(250);

}


aJsonObject *createMessage()
{
  aJsonObject *msg = aJson.createObject();
  aJsonObject *eon = aJson.createObject();
  aJson.addStringToObject(eon, "myName", "TI_LaunchPad");
  aJson.addNumberToObject(eon, "LIGHT", (int)LIGHT);
  aJson.addNumberToObject(eon, "MOISTURE", (int)MOISTURE);
  aJson.addItemToObject(msg, "eon", eon);
  return msg;
}

void printWifiStatus() {
	// print the SSID of the network you're attached to:
	Serial.print("SSID: ");
	Serial.println(WiFi.SSID());

	// print your WiFi IP address:
	IPAddress ip = WiFi.localIP();
	Serial.print("IP Address: ");
	Serial.println(ip);

	// print the received signal strength:
	long rssi = WiFi.RSSI();
	Serial.print("signal strength (RSSI):");
	Serial.print(rssi);
	Serial.println(" dBm");
}
Read light sensor dataArduino
void setupLight(){

}

void loopLight(){
  LIGHT = analogRead(23);
  delay(250);
}
Read Moisture sensorArduino
void setupMoisture(){

}

void loopMoisture(){
  MOISTURE = analogRead(24);
  delay(250);
}

Credits

10384512 10105541378165610 2876926985073736385 n
Adrian Fernandez

peek a boo my name is adrian

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Wi-Fi IoT Workshop for TI LaunchPad+Educational BoosterPack
Easy
  • 1,348
  • 121

Full instructions

Get started with some IoT projects. Learn how to use Wi-Fi wireless communication with the TI LaunchPad.

ASEE 2017: TI LaunchPad 4 Student Owned Freshman Experience
Easy
  • 127
  • 1

Protip

Learn how to use low cost student owned hardware for hands on intro courses.

Control Your Bot From Anywhere
Easy
  • 18
  • 0

Full instructions

IoT with your robot at one place and your phone another, both connected via internet.

MSP432 Fun with IoT Workshop 2016
Easy
  • 3,288
  • 68

Full instructions

Explore the Educational BoosterPack paired with the MSP432 LaunchPad and then take that to the cloud with the CC3100 Wi-Fi BoosterPack!

MIT IAP 2016 Lab
Easy
  • 1,962
  • 46

A collection of the 6 labs for the MIT IAP Texas Instruments LaunchPad Workshop

Texas Instruments MSP-EXP432 - MultiTasking
Easy
  • 582
  • 18

Protip

MultiTasking ultrasonic and color sensor with Texas Instruments MSP-EXP432 and Energia.

Add projectSign up / Login