In my previous post I have discussed myproject proposal....
I have selected WiFi with UDP protocol for communication, and selected CC3200 for main processing and commnication Part at sensor node...
So meanwhile parts for this challenge arrive... I have started to work with what I have now (CC3200 Launchpad)..
In this Post I am sharing my work for communicate CC3200 with PC/ Android cell phone using UDP.
I am using Energia IDE for CC3200 application development.
and I am using Processing for developing PC / Andoid app for remot monitoring station...
I have used these opensource platform by keeping in mind that all the codes are in opensource for future use.
Here is code for CC3200 for UDP sensor node... I am using BMA222 Accelerometer library for this demo. Which is available here https://github.com/energia/Energia/tree/master/hardware/cc3200/libraries/BMA222 ..
/*============================================================================
Sudden Impact Wearable Design Challenge
Real Time Player monitoring System
Energia Sketch (Running on CC3200 Launchpad)
Test Code for WiFi UDP connection between
Sensor node(CC3200 LaunchPad)and monitoring Station(Android cell phone / PC)
UDP Sender/Receiver Application used for Android cell phone
Processing application for use with PC (Linux/MacOS/Windows)
BMA222 Library used for CC3200 Launchpad on board Accelerometer interface
created 13 December 2014
by Ravi Butani
e-mail: ravi_butani@yahoo.com
Attribute : Noah Luskey for his UDP library
Code Released under CC-SA 2014 license
===========================================================================*/
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>
#include <Wire.h>
#include <BMA222.h>
BMA222 mySensor;
// your network name also called SSID
char ssid[] = "ravi1";
// your network password
char password[] = "11223344";
unsigned int localPort = 2390;      // local port to listen on
char packetBuffer[255]; //buffer to hold incoming packet
char ReplyBuffer[5];    // a string to send back
String str;
WiFiUDP Udp;
void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  // attempt to connect to Wifi network:
  Serial.println("====Sudden Impact Wearable Design Challenge====");
  Serial.println("=======Real Time Player Monitoring System======");
  Serial.println("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");
  printWifiStatus();
  mySensor.begin();
  uint8_t chipID = mySensor.chipID();
  Serial.print("chipID: ");
  Serial.println(chipID);
  Serial.println("\nWaiting for a connection from a remote monitoring Station...");
  Udp.begin(localPort);
}
void loop() {
  int8_t datax,datay,dataz;
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(", port ");
    Serial.println(Udp.remotePort());
    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len] = 0;
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    // once connected with remote monitoring station send accelerometer data continuously
    while(1)
    {
      datax = mySensor.readXData();
      datay = mySensor.readYData();
      dataz = mySensor.readZData();
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      str=String(datax); //converting integer into a string
      str.toCharArray(ReplyBuffer,5);
      Udp.write("X=");
      Udp.write(ReplyBuffer);
      str=String(datay); //converting integer into a string
      str.toCharArray(ReplyBuffer,5);
      Udp.write("\tY=");
      Udp.write(ReplyBuffer);
      str=String(dataz); //converting integer into a string
      str.toCharArray(ReplyBuffer,5);
      Udp.write("\tZ=");
      Udp.write(ReplyBuffer);
      Udp.endPacket();
      delay(200); // just to visulize readings on serial port
    }
  }
}
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");
}
Once above energia sketch loaded on CC3200... I have Used my cell phone as hot spot to connect CC3200 sensor node and PC/Android cell phone(Remote monitoring Station)..
For testing received Data on Android phone I have used UDP Sender/Receiver android application available on google play store https://play.google.com/store/apps/details?id=com.jca.udpsendreceive&hl=en
Here is snapshot of received UDP packets on my android cell phone...
This is processing sketch for test UDP packets on PC running on (Linux/MAC/Windows)
/*============================================================================
Sudden Impact Wearable Design Challenge
Real Time Player monitoring System
Processing Sketch (running on PC)
Test Code for Wifi UDP connection between
Sensor node(CC3200 LaunchPad)and monitoring Station(Android cell phone / PC)
UDP Sender/Receiver Application used for Android cell phone
Processing application for use with PC (Linux/MacOS/Windows)
BMA222 Library used for CC3200 Launchpad on board Accelerometer interface
created 13 December 2014
by Ravi Butani
 e-mail: ravi_butani@yahoo.com
Attribute : Cousot stephane for The Atelier Hypermedia
            http://hypermedia.loeil.org/processing/
Code released under CC-SA  2014 license
===========================================================================*/
// import UDP library
import hypermedia.ne.*;
UDP udp;  // define the UDP object
/**
* init
*/
void setup() {
  // create a new datagram connection on port 6000
  // and wait for incomming message
  udp = new UDP( this, 2390 );
  udp.listen( true );
}
//process events
void draw() {
    String message  = "hii";  // the message to send
    String ip      = "192.168.43.134";  // the remote IP address
    int port        = 2390;    // the destination port
    // formats the message for Pd
    message = message+";\n";
    // send the message
    udp.send( message, ip, port );
    while(true)
    {;}
}
/**
* To perform any action on datagram reception, you need to implement this
* handler in your code. This method will be automatically called by the UDP
* object each time he receive a nonnull message.
* By default, this method have just one argument (the received message as
* byte[] array), but in addition, two arguments (representing in order the
* sender IP address and his port) can be set like below.
*/
// void receive( byte[] data ) { // <-- default handler
void receive( byte[] data, String ip, int port ) { // <-- extended handler
  // get the "real" message =
  // forget the ";\n" at the end <-- !!! only for a communication with Pd !!!
  data = subset(data, 0, data.length);
  String message = new String( data );
  // print the result
println( "UDP Rx: "+message+"\t from "+ip+"\t on port "+port );
}
and here is the result of received UDP Packets on my PC...
Next : Interfacing ADXL345 and ADXL377 (Free Samples from ADI) Accelerometer with CC3200 and Designing some GUI application for remote monitoring station both for PC and Android phone...
Thanks
Ravi
			    
