Controlling RSLK Over Internet

Learn how easy it is to control TI RSLK kit over internet and control different motions of robot using Android app.

AdvancedFull instructions provided2 days1,468
Controlling RSLK Over Internet

Things used in this project

Story

Read more

Code

RSLK IoT Control

Arduino
Control RSLK kit over internet
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>

//define the pins to be connected to ultrasonic sensorw
//define the pins to be connected to ultrasonic sensor




char ssid[] = "Ashita";
char password[] = "ashita123";

const int HTTPPORT = 80;
char * USER_AGENT = "TI";
char * VERSION = "1.6";
char * server = "things.ubidots.com";
char* TOKEN = "A1E-tHJT1waqiDx5MkG2F3htau6fuYXXLL"; // Put here your TOKEN

char* DEVICE_LABEL = "autobot"; // Your Device label

/* Put here your variable's labels*/
char const * VARIABLE_LABEL = "autobot";
WiFiClient client;

void setup() {



  pinMode(40,OUTPUT);
pinMode(39,OUTPUT);
pinMode(38,OUTPUT);
pinMode(35,OUTPUT);
pinMode(34,OUTPUT);
pinMode(33,OUTPUT);

digitalWrite(38,HIGH);
digitalWrite(33,HIGH);
  //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);
  }

 
}


void loop() {
   if (client.connect(server, 80)) {
    client.print(F("GET /api/v1.6/devices/"));
    client.print(DEVICE_LABEL);
    client.print(F("/"));
    client.print(VARIABLE_LABEL);
    client.print(F("/lv"));
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Host: "));
    client.print(server);
    client.print(F("\r\n"));
    client.print(F("User-Agent: "));
    client.print(USER_AGENT);
    client.print(F("/"));
    client.print(VERSION);
    client.print(F("\r\n"));
    client.print(F("X-Auth-Token: "));
    client.print(TOKEN);
    client.print(F("\r\n"));
    client.print(F("Content-Type: application/json\r\n\r\n"));
    client.println();
    
}
  String s="";
  bool a=false;
  char movement='5';
  while (client.available()) {
    char c = client.read();
    s=s+c;
    a=true;
  }

  Serial.println(s);
   movement = get_movement(s);
   Serial.println(movement);
 
  if(a==true){
      client.stop();
      a=false;
  }
 
  if(movement=='1'){    //Forward

analogWrite(40,80);
analogWrite(39,-80);
analogWrite(35,80);    // forward2
analogWrite(34,-80);
  
  }
  if(movement=='5'){ //stop
analogWrite(40,0);
analogWrite(39,0);
analogWrite(35,0);    
analogWrite(34,0);
  
    }

 
  if(movement=='2'){    //back

analogWrite(40,-80);
analogWrite(39,80);
analogWrite(35,-80);    // back
analogWrite(34,80);
  
  }

  
  if(movement=='3'){    //

analogWrite(40,80);
analogWrite(39,-80);
analogWrite(35,80);    // left
analogWrite(34,80);
  
  }


  if(movement=='4'){    //Forward

analogWrite(40,80);
analogWrite(39,80);
analogWrite(35,80);    // right
analogWrite(34,-80);
  
  }
  

 }


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

  // print your WiFi shield's 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");
}


char get_movement(String a){
  int endi =0;
  int i;
  for(i=0;i<a.length();i++){

    if(a.charAt(i)=='\n'){
      endi++;
    }
    if(endi==10){
      break;
    }
  }
  return a.charAt(i+1);
  
}

Credits

Dr. Umesh Dutta
42 projects • 61 followers
Working as Director of Innovation Centre at Manav Rachna, India. I am into development for the last 12 years.
Contact
Texas Instruments University Program
91 projects • 120 followers
TI helps students discover what's possible to engineer their future.
Contact
Energia
34 projects • 26 followers
Founder of @energiaproject
Contact
devdutt
10 projects • 9 followers
Robotic Gold Medalist at IIT Guwahati and Embedded,Hardware Developer at Manav Rachna Innovation and Incubation Centre
Contact

Comments

Please log in or sign up to comment.