IoT-Based Socket Board

A portable socket board is designed that can be controlled through internet. It provides portable automation solution of devices with ease.

IntermediateFull instructions provided2 days841
IoT-Based Socket Board

Things used in this project

Story

Read more

Code

code for controlling socket

Arduino
Energia code for achieving socket control via internet. If '1' is received then all sockets will be turned on and if '0' is received then all sockets will be turned off
#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

// your network name also called SSID
char ssid[] = "note 5pro";
// your network password
char password[] = "neha9625";

const int HTTPPORT = 80;
char USER_AGENT[] = "TI";
char  VERSION[] = "1.0";
char  server[] = "industrial.api.ubidots.com";
char TOKEN[] = "BBFF-qJwJyLiI8Pi4M7BBwif3shnl4Uz6Ip"; // Put here your TOKEN

char DEVICE_LABEL[] = "socket"; // Your Device label

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

void setup() {
  //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);
    pinMode(25,  OUTPUT);

  pinMode(26,  OUTPUT);

  pinMode(26, OUTPUT);

  pinMode(27, OUTPUT);

  
  }
  
  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'){
    digitalWrite(25,1);
    digitalWrite(26,1);
    digitalWrite(27,1);
  }

   if(movement=='0'){
    digitalWrite(25,0);
    digitalWrite(26,0);
    digitalWrite(27,0);
  }
 
 
 }


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

Dr. Umesh Dutta

41 projects • 56 followers
Working as Director of Innovation Centre at Manav Rachna, India. I am into development for the last 12 years.
Neha lakhotia

Neha lakhotia

1 project • 1 follower
Texas Instruments University Program

Texas Instruments University Program

91 projects • 120 followers
TI helps students discover what's possible to engineer their future.
Energia

Energia

34 projects • 26 followers
Founder of @energiaproject

Comments