Tuesday, 28 August 2018

SQL Queries

Scalar Function:- Oracle Scalar Functions allow you to perform different calculations on data values. There are different types of Scalar Functions.

1. String Function - functions that perform operations on character values.
2. Numeric Function - functions that perform operations on numeric values.
3. Date Function - functions that perform operations on date values.
4. Conversion Function - functions that convert column data types.
5. NULL-related Function - functions for handling null values.

Oracle String Functions:-
1. CONCAT - Returns text strings concatenated
     select concat('Hello','World') from dual;

2. INSTR - Returns the location of a substring in a string.
     select instr('parag','r') from dual;

3. LENGTH - Returns the number of characters of the specified string expression.
     select length('parag') from dual;

4. RTRIM - Returns a character string after truncating all trailing blanks.
     select rtrim('  parag      ') from dual;

5. LTRIM - Returns a character expression after it removes leading blanks.
    select ltrim('    parag    ') from dual;

6. REPLACE - Replaces all occurrences of a specified string value with another string value.
    select replace('hello','e','$') from dual;

7. REVERSE - Returns the reverse order of a string value.
    select reverse('parag') from dual;

8. SUBSTR - Returns part of a text.
     select substr('hello',2,3) from dual;

9. LOWER - Returns a character expression after converting uppercase character data to lowercase.
     select lower('PARAG') from dual;

10. UPPER - Returns a character expression with lowercase character data converted to uppercase.
     select upper('parag') from dual;

Oracle Numeric Functions:-
1. TRUNC - Returns an integer that is less than or equal to the specified numeric expression.
    select trunc(69.9) from dual;

2. CEIL - Returns an integer that is greater than, or equal to, the specified numeric expression.
    select ceil(69.1) from dual;

3.ROUND - Returns a numeric value, rounded to the specified length or precision.
    select round(69.9) from dual;

How to insert date and time in oracle?
Using to_date() function we can insert date and time in oracle. To insert date and time we need to use date as a data type.
CREATE TABLE WorkOn ( StaffNo NCHAR(4), MechanicName VARCHAR(50), DateTime DATE, Hours VARCHAR(2) ) ;
insert into WorkOn values('101','Parag',to_date('22/06/2018 8:30:00AM','DD/MM/YYYY HH24:MI:SS'),3);

Friday, 9 February 2018

Blink LED using Arduino

The Internet of things (IoT) is the network of physical devices, vehicles, home appliances and other items embedded with electronics, software, sensors, actuators, and connectivity which enables these objects to connect and exchange data. In this project I am using Arduino Uno board and LED to enable or disable the LED from anywhere in the world. The great thing about using a web interface is that it is cross-platform and it enables you to control your Arduino connected devices with web browsing capabilities, such as smartphones and tablets.

What you need?
1.An Arduino board with an internal LED (usually on pin 13) or a separate LED
2. A webhosting service with PHP support
3. The Arduino IDE
4. The Processing IDE
5. A text editor (e.g. Notepad++)

First, we’ll start with the web interface. It’s function is to give the user the choice to either switch the LED on or off. When either one of them is clicked, the command is written to a "test.txt" file as a 1 (ON) or 0 (OFF) value.
The interface consists of three files; a HTML front-end, a PHP document, and a text file for storing values. So, firstly create these files using a text editor: 
1. index.html
2. led.php
3. LEDstate.txt 


1. Code for index.html

<html>
<head>
<title>LED ON/OFF</title>
</head>
<body>
<font size="10">
  
<b><a href="led.php?state=1">ON LED</a></b> /
<b><a href="led.php?state=0">OFF LED</a></b></font>
</p>
  
</body>
</html>


2. Code for led.php 

<?php
$onoroff = $_GET["state"]; 
$textfile = "LEDstate.txt"
$fileLocation = "$textfile";
$fh = fopen($fileLocation, 'w   ') or die("Something went wrong!");
$stringToWrite = "$onoroff"
fwrite($fh, $stringToWrite); 
fclose($fh);
header("Location: index.html");
?>


3. Arduino Sketch

const int ledPin = 13; // the pin that the LED is attached to - change this if you have a separate LED connected to another pin
int incomingByte;      // a variable to read incoming serial data into
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}
void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}
4. Processing Sketch
import processing.serial.*;
 Serial port;
 void setup()  {
   /* This part must be altered to fit your local settings. The number in brackets after "Serial.list()" is where you declare what COM port your Arduino is connected to.
      If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3...) . */
    port = new Serial(this, Serial.list()[1], 9600);  // Open the port that the Arduino board is connected to, at 9600 baud
}
 void draw() {
  String onoroff[] = loadStrings("http://calibretechnology.com/iot/LEDstate.txt");
  print(onoroff[0]);  // Prints whatever is in the file ("1" or "0")
  if (onoroff[0].equals("1") == true) {
    println(" - TELLING ARDUINO TO TURN LED ON");
    port.write('H'); // Send "H" over serial to set LED to HIGH
  } else {
    println(" - TELLING ARDUINO TO TURN LED OFF");
    port.write('L');  // Send "L" over serial to set LED to LOW
 }
  delay(7000); // Set your desired interval here, in milliseconds
 }
Run your code & Enjoy