IoT with CC3200 using UDP packets on LAN

CC3200First of all we need to setup the CC3200 LAUNCHXL. For that visit all the following links and do whatever is written there.

OR just watch this video for the most basic setup.

NOTE: If you already have installed Code Composer Studio and if you checked the box for CC3200 based devices then there is no need to install the device drivers as they have already been installed otherwise you must install the drivers cause without that your device wont be recognized and you wont be able to upload codes.

  • For installing drivers visit this page .
  • If you are a windows 8/8.1 user you will need to disable device signature. Learn how to do that from here .
  • Unfortunately there is a hardware related inconvenience, to work around that you need to use a jumper wire to connect two pins. More info on this page .
  • On the same page as above there is a section on how to upgrade the firmware. I strongly suggest you do that.

Here is a pinout of the CC3200 Launchxl. Note the white line connecting two pins, that is where you need to place the jumper.
LaunchPads-CC3200-—-Pins-Maps-12-28Now, i am behind a corporate proxy which renders almost every example useless. But i am trying to get some of them to work atleast on the LAN.

For this post we will be using the “WifiUdpSendReceiveString” example. For that we will need a piece of software that can send/receive UDP and(or) TCP packets. So i downloaded “Packet Sender” (UDP and TCP network test utility) from here . I downloaded the Portable version, but either the installer or the portable version should work just fine.

I edited the code such a way that whenever i sent a particular string the RED led would glow and YELLOW led would stop glowing and whenever it received something else the vice-versa would happen. Here is the edited code –


#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>

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

unsigned int localPort = 2390;      // local port to listen on

char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged"; // a string to send back

char check[255] = "shantam"; // this is the string i send back. i store it here so that i can check it against the received packet.

WiFiUDP Udp;

void setup() {
pinMode(RED_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
//Initialize serial and wait for port to open:
Serial.begin(115200);

// 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");
printWifiStatus();

Serial.println("\nWaiting for a connection from a client...");
Udp.begin(localPort);
}

void loop() {
int count = 0;

// 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);

// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();

for(int i= 0; i < packetSize; i++)
{
if(packetBuffer[i] == check[i])
{
count++;
}
else

{
count = 60;
}
}
if(count == 7)
{
//Serial.println("GOT IT");
digitalWrite(RED_LED,HIGH);
digitalWrite(YELLOW_LED,LOW);
}

else
{
//Serial.println("INCORRECT PACKET");
digitalWrite(YELLOW_LED,HIGH);
digitalWrite(RED_LED,LOW);
}
}
}

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");
}

Packet Sender configuration

This is what it looks like when u run it on windows..

Screenshot (83)The GUI is pretty straightforward to use. Just write the name of the packet in the first box. The contents of the packet itself in the following box in ASCII. The software itself generates the hex codes in the following box. After that you need to write the IP address assigned to the Launchpad in the box just below, for me it was 192.168.89.102. You can check yours by the GUI of the router you are using or by just uploading the code and opening the serial monitor. The Launchpad will print its IP address itself. Adjacent to that you need to write the port over which the communication is happening which as mentioned in the example code is 2390.

pcket sender)As of now i do not own a router and am using “Connectify”. It used to give me a lot of trouble but after upgrading to “PRO” and to the latest version there are no connection drops !!. Well frankly speaking i got that for free as last year they were providing it free to university students !!.

The demonstration video for this should be up by this week. Till then – keep hacking and happy making !!.

Advertisements

About Shantam Raj

Currently I am a final year B.Tech undergraduate majoring in “Electronics and Communication Engineering” from IIT Guwahati. I am passionate about electronics and robotics. Apart from that I love writing, visit https://medium.com/@shantam_raj for some of my works. I am a die hard soccer fan. I also love to play badminton. I am a hardware hacking enthusiast and a tinkerer !!.
This entry was posted in CC3200, Internet of Things and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s