Archive

Archive for 2014

External ADC with Raspberry Pi.

November 24th, 2014 No comments

           Really I tried a lot with MCP3208 external ADC to interface with the Raspberry pi. Searched for various codes but nothing was available in JAVA. So after some research i got some python code and modified that to JAVA.  in this i have used the Pi4J library.

/****
*Author : Bikash Narayan Panda
*Use : This is used to read ADC data foem the MCP3208 SPI based ADC.
*Date :19/Nov/2014
*Tags: Please Include the Pi4J Library.
*
*
**/
import java.io.IOException;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class SensorTest {

    public static int readadc(int adcnum, GpioPinDigitalOutput clockpin,
            GpioPinDigitalOutput mosipin, GpioPinDigitalInput misopin,
            GpioPinDigitalOutput cspin, GpioController gpio) {
        if ((adcnum > 7) || (adcnum < 0))
            return -1;

        cspin.high();
        clockpin.low();
        cspin.low();

        int commandout = adcnum;
        commandout |= 0x18;
        commandout <<= 3;
        for (int i = 0; i < 5; i++) {
            if ((commandout & 0x80) != 0) {
                mosipin.high();
            }

            else {
                mosipin.low();
            }
            commandout <<= 1;
            clockpin.high();
            clockpin.low();
        }

        int adcout = 0;
        for (int i = 0; i < 14; i++) {
            clockpin.high();
            clockpin.low();
            adcout <<= 1;
            if (misopin.getState() == PinState.HIGH) {
                adcout |= 0x1;
            }

        }

        cspin.high();

        adcout >>= 1;
        return adcout;

    }

    public static void main(String[] args) throws InterruptedException,
            IOException {

        System.out.println("<--Pi4J--> GPIO Listen Example ... started.");

        // create gpio controller
        GpioController gpio = GpioFactory.getInstance();

        GpioPinDigitalOutput SPICLK = gpio.provisionDigitalOutputPin(
                RaspiPin.GPIO_14, "SPICLK", PinState.LOW);
        GpioPinDigitalInput SPIMISO = gpio.provisionDigitalInputPin(
                RaspiPin.GPIO_13, "SPIMISO", PinPullResistance.PULL_DOWN);
        GpioPinDigitalOutput SPIMOSI = gpio.provisionDigitalOutputPin(
                RaspiPin.GPIO_12, "SPIMOSI", PinState.LOW);
        GpioPinDigitalOutput SPICS = gpio.provisionDigitalOutputPin(
                RaspiPin.GPIO_11, "SPICS", PinState.LOW);


      
        for (int i=0;i <= 20;i++) {
            float value = readadc(0, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 0value= " + value);
            value = readadc(1, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 1value= " + value);
            Thread.sleep(500);
            value = readadc(2, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 2value= " + value);
            Thread.sleep(500);
            value = readadc(3, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor3 value= " + value);
            Thread.sleep(500);
            value = readadc(4, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 4value= " + value);
            Thread.sleep(500);
            value = readadc(5, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 5value= " + value);
            Thread.sleep(500);
            value = readadc(6, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor 6value= " + value);
            Thread.sleep(500);
            value = readadc(7, SPICLK, SPIMOSI, SPIMISO, SPICS, gpio);
            System.out.println("sensor7 value= " + value);
            Thread.sleep(500);
            Thread.sleep(500);
           
            Thread.sleep(500);
        }
      
      
        gpio.shutdown();

    }
}

 

Modify your old PC SMPS to BenchTop Power Supply Unit

October 30th, 2014 No comments

Many time we do have old SMPS of no use to the computers. Those SMPS can be modified as bench-top power supply system providing -12,+12,+5,+3.3 volts. I have used one to power my all arduino based home automation modules and the Raspberry Pi. Here  i am going to post how to mod an old SMPS .

You just need following components along with some  basic tools

                                             1.Screw Terminals.
                                             2.Switch (On/Off).
                                             3.10Watt Resistive load (May be 5K or 10K i have used 4.7K working fine)

Using Raspberry Pi Serial Port

September 12th, 2014 No comments
             By default the Raspberry Pi’s serial port is configured to be used for console input/output, it means you can’t use the Serial Port in your programs and  needs to be disabled.To enable the serial port for your own use you need to disable login on the port. There are two files that need to be edited

The first and main one is     

              

 /etc/inittab

This file has the command to enable the login prompt and this needs to be disabled. Edit the file and move to the end of the file. You will see a line similar to

                      
      

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Disable it by adding a # character to the beginning. Save the file.


          When the Raspberry Pi boots up, all the bootup information is sent to the serial port. Disabling this bootup information is optional and you may want to leave this enabled as it is sometimes useful to see what is happening at bootup. If you have a device connected (i.e. Arduino) at bootup, it will receive this information over the serial port, so it is up to you to decide whether this is a problem or not.
You can disable it by editing the file

                             

/boot/cmdline.txt

The contents of the file look like this

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Remove all references to ttyAMA0 (which is the name of the serial port). The file will now look like this

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

In order you enable the changes you have made, you will need to reboot the Raspberry Pi

                         

sudo shutdown -r now

Algotithm to Convert 4 byte Hex to 32 bit float

September 10th, 2014 No comments
 I really struggled hard to find out some sorts of algorithm to convert 4 hex bytes to 32 bit float for my requirement on some analysis of MODBUS protocol. I didn’t find it and it tok me nearly 2 days to design this. Here is the algorithm..

float ModbusRead(byte id,byte msbAddress,byte lsbAddress,byte msbCrc,byte lsbCrc)
{
num=1.00;
Serial.write(id);
Serial.write(0x03);
Serial.write((byte)msbAddress);
Serial.write((byte)lsbAddress);
Serial.write((byte)0x00);
Serial.write(0x02);
Serial.write(msbCrc);
Serial.write(lsbCrc);
delay(1000);

for(i=0;i<9;i++)
{
if(!Serial.available())
{
for (int x=0;x < 9;x++)
{
reply[x]=0x00;
}
while(Serial.available()){}
break;
}
reply[i]=Serial.read();
}
while(Serial.available()){}
if((reply[3] & 0x80)!=0)
num=num*-1;
reply[3]=reply[3]<<1;
if((reply[4] & 0x80)!=0x00)
reply[3]=reply[3] | 0x01;
num=num*pow(2,reply[3]-0x7F);
i=0;
delay(1000);
return num*calculatemantisa(reply[4],reply[5],reply[6]);
}
float calculatemantisa(byte a,byte b,byte c)
{
float x=1.0000;
if((a & 0x40)!=0x00)
x=x+pow(2,-1);
if((a & 0x20)!=0x00)
x=x+pow(2,-2);
if((a & 0x10)!=0x00)
x=x+pow(2,-3);
if((a & 0x8)!=0x00)
x=x+pow(2,-4);
if((a & 0x4)!=0x00)
x=x+pow(2,-5);
if((a & 0x2)!=0x00)
x=x+pow(2,-6);
if((a & 0x1)!=0x00)
x=x+pow(2,-7);

if((b & 0x80)!=0x00)
x=x+pow(2,-8);
if((b & 0x40)!=0x00)
x=x+pow(2,-9);
if((b & 0x20)!=0x00)
x=x+pow(2,-10);
if((b & 0x10)!=0x00)
x=x+pow(2,-11);
if((b & 0x8)!=0x00)
x=x+pow(2,-12);
if((b & 0x4)!=0x00)
x=x+pow(2,-13);
if((b & 0x2)!=0x00)
x=x+pow(2,-14);
if((b & 0x1)!=0x00)
x=x+pow(2,-15);

if((c & 0x80)!=0x00)
x=x+pow(2,-16);
if((c & 0x40)!=0x00)
x=x+pow(2,-17);
if((c & 0x20)!=0x00)
x=x+pow(2,-18);
if((c & 0x10)!=0x00)
x=x+pow(2,-19);
if((c & 0x8)!=0x00)
x=x+pow(2,-20);
if((c & 0x4)!=0x00)
x=x+pow(2,-21);
if((c & 0x2)!=0x00)
x=x+pow(2,-22);
if((c & 0x1)!=0x00)
x=x+pow(2,-23);

return x;
}
Categories: 32 bit float, exponent, mantisa, MODBUS, RS-232, RS-485 Tags:

Running particular application when Rspberry Pi boots up

August 8th, 2014 No comments
              While using Raspberry Pi you might not be interested to take  a mouse and keyboard to run certain application when the Pi reboots. To avoid this many procedures are available . In this post i have used crontab to run a JAVA based application each time the Pi reboots. Actually crontab provides many more features.

First login to your pi. Change yourself to root user. Command is 

sudo -s

After that to edit the crontab type
crontab -e
At the beginning of the file append 

@reboot /usr/bin/java -classpath /home/pi/:/home/pi/Desktop/DisplayOne_lib/*.jar -jar /home/pi/Desktop/DisplayOne.jar

Here the library and .jar file paths are provided as of the location of my application file.
Have a good day…

Run GUI based application on raspberry Pi Startup

August 7th, 2014 No comments

          Belief me i went through several websites and tested many proposals to run my JAVA based GUI application on Raspberry Pi start-up. Finally the following worked out

First check inside the .config folder if it contains autostart folder or not , if not then create a folder named as autostart.

Create a myApp.desktop file inside the autostart folder.The myApp.desktop file should contain the following

[Desktop Entry]

Encoding=UTF-8

Typr=Application

Name=nds

comment=

Exec=sudo /usr/bin/java -classpath /home/pi/:/home/pi/Desktop/Display_lib/*.jar -jar /home/pi/Desktop/Display.jar

StartupNotify=false

Terminal=false

Hidden=-false



Thats all reboot your pi and your application should run now….. You can also do that by following method.. edit rc.local file and put the code just befor the exit 0.

#sudo  /usr/bin/java -classpath /home/pi/:/home/pi/Desktop/Display_lib/*.jar -jar /home/pi/Deskt/Display.jar
Another thing is to run the GUI app continuously you also need to disable the default screen blackout. To do that just edit the rc.local file and put the following codes.

setterm -blank 0 -powerdown 0 -powersave off

Or edit the ~/.xinitrc file and put the following codes..

. /etc/X11/Xsession

xset s off

xset -dpms

xset s noblank

Pi Rocks…

setterm – terminal blanking

On a per session basis, you can run:
setterm -blank 0 -powerdown 0
This will set the timeout of your monitor to 0, which will prevent it from going to sleep.
If you get yelled at about permissions, try “sudo setterm” instead.
You might not want to enter these commands every time you boot up your Pi. In this case, open up your .bashrc file (or .extras or other custom file you might use).
nano ~/.bashrc
At the end of the file add a new line with the setterm command you entered before.
setterm -blank 0 -powerdown 0
Hit ctrl+x to exit, ‘y’ to save your changes and enter to save the file.
Note: the default value for the -blank option is 0 so it may be excluded
Now when you boot up, your monitor will never sleep.

kbd configuration – terminal blanking

Open up your configuration:
sudo nano /etc/kbd/config
Find the line for BLANK_TIME and POWERDOWN_TIME and set them to 0.
BLANK_TIME=0
POWERDOWN_TIME=0
If these lines doesn’t exist go ahead and add them.

lxde configuration – Xsession blanking

The previous methods should work for the terminal. This method should prevent your screen saver from coming on in the GUI.
Open up your lxde autostart file:
sudo nano /etc/xdg/lxsession/LXDE/autostart
If your Pi is newer, the file you’ll need to change may be:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Add these lines:
@xset s noblank
@xset s off
@xset -dpms

lightdm configuration – Xsession blanking

If adding those settings to your LXDE autostart didn’t work, this might help if you’re booting straight into the GUI.
Open your lightdm configuration:
sudo nano /etc/lightdm/lightdm.conf
Anywhere below the [SeatDefaults] header, add:
xserver-command=X -s 0 -dpms
This will set your blanking timeout to 0 a

sudo apt-get install x11-xserver-utils
  • now lets make a file to run on the start of X with settings
cd /home/pi 
touch .xinitrc
nano .xinitrc
  • Now you should edit .xinitrc and add these lines (disable ss, say no monitor timeout, set no blanking)
xset s off 
xset -dpms
xset s noblank

Power Over Ethernet (For Ethernet Connected Devices)

July 28th, 2014 No comments

         Power Over Ethernet is a widely used concept to power up remote devices like Arduino, Raspberry pi or any other embedded devices working on low voltage and power.There are ready made modules available in the market but are expensive so in this tutorial i will show you to make the cable modified to work for POE.

          Ethernet cable uses 4 pairs of wires but out of them only 2 pairs are used and the remaining are unused so those can be used to carry power to the end devices.As the below image shows the unused colored wires.

Categories: Arduino, Ethernet, POE, Power, Raspberry Pi, RJ45 Tags:

Cheap Ethernet connection to Arduino using ENC28J60 module

June 21st, 2014 No comments

      While working on Ethernet projects with Arduino the basic hardware we require along with Arduino is the Ethernet Shield. But the problem is that in a constrained budget the buying one Ethernet Shield is not possible which leads to other options and a good one is ENC28J60 Ethernet chip by Microchip.This is not as smart as the Wiznet W5100 chip based Ethernet shields but are quite useful as those.This post i am going to write all about interfacing the ENC28J60 module to Arduino UNO as well as Arduino mini Pro.I have used EtherCard library for the coding to interact with the module.

     
          Below is the wiring diagram for Arduino UNO.

    
  Code:

#include <EtherCard.h>
#define PATH "temp.php"

byte mymac[] = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
uint8_t ip[] = {
192, 168, 0, 8 }; // The fallback board address.
uint8_t dns[] = {
192, 168, 0, 1 }; // The DNS server address.
uint8_t gateway[] = {
192, 168, 0, 1 }; // The gateway router address.
uint8_t subnet[] = {
255, 255, 255, 0 };

char website[] PROGMEM = "192.168.0.10";
static byte session;
byte Ethernet::buffer[800];
uint32_t timer;
Stash stash;
float temp_R=0;
int tempPinR = A0;
String cont="";
int led = 9;
int sw1 = A1;
int sw2 = A2;
int sw3 = A3;
String sReply="";

void setup () {
Serial.begin(57600);
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
Serial.println( "Failed to access Ethernet controller");//10 is the CS pin of EC28J60 connected to change if required.

ether.staticSetup(ip, gateway, dns);
ether.parseIp(ether.hisip,"192.168.0.10");//Raspberry Pi IP Change it if required
ether.printIp("SRV: ", ether.hisip);
delay(5000);
pinMode(9, OUTPUT);
pinMode(led, OUTPUT);
analogReference(INTERNAL);
}

void loop () {
word pos=ether.packetLoop(ether.packetReceive());

if (millis() > timer) {

byte sd = stash.create();
stash.print("data=hello");//change value of data to send different data

timer = millis() + 10000;

Serial.println("in");
stash.save();

Stash::prepare(PSTR("POST http://192.168.0.10/API/index.php HTTP/1.0" "rn"
"Host: 192.168.0.10 rn"
"Content-Length: $D" "rn"
"Content-Type: application/x-www-form-urlencoded rn"
"rn"
"$H"),
stash.size(), sd);//change IP path acccordingly

session= ether.tcpSend();

}
const char* reply=ether.tcpReply(session);
if(reply!=0)
{
int i;
for(i=13;i<strlen(reply);i++)
{
sReply=sReply+reply[i];
}

Serial.println(sReply);
sReply=" ";
}
}

Room temperatuer logger using arduino and JAVA

June 1st, 2014 No comments

 This post is all about a temperature logger module using two sensors(LM35) and uses serial communication to log data to MySQL server. And it does so by using Arduino at the logger end and JAVA at the server.

  The concept is so simple that the Arduino uses LM35 (providing analog output for measured temperature) ,which is connected to one of the analogIn pin of Arduino. The sketch burned to Arduino converts the read value from the pin to corresponding temperature. And it sends the data through the serial port.

  At PC side a JAVA application runs which uses TxRx library for communicating with the serial port. The application reads the data from the serial port and acknowledged to Arduino. It then saves the red data to a database.

LM35Logger.ino

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,11,12);

float temp_R=0;

float temp_Pi=0;

int tempPinR = 0;

int tempPinPi = 1;

void setup()

{

  lcd.begin(16, 2);

  pinMode(9, OUTPUT);

  Serial.begin(9600);

  analogReference(INTERNAL);

}

void loop()

{

  temp_R = analogRead(tempPinR);

  temp_Pi = analogRead(tempPinPi);

  temp_R = temp_R *0.107421875;

  temp_Pi = temp_Pi *0.107421875;

 

  Serial.print("TEMPRATURE = ");

  Serial.print(temp_R);

  Serial.print("*C");

  Serial.println();

  lcd.clear();

  String content = "";

  char character;



  while(Serial.available())

   {

      character = Serial.read();

      content.concat(character);

   }

   if(temp_Pi>36)

   {

     digitalWrite(9, HIGH);

   }

   else

   {

     digitalWrite(9, LOW);

   }

  lcd.print(content);

  lcd.setCursor(0,1);

  lcd.print("R:");

  lcd.setCursor(2,1);

  lcd.print(temp_R);

  lcd.setCursor(8,1);

  lcd.print("Pi:");

  lcd.setCursor(11,1);

  lcd.print(temp_Pi);

  delay(3000);

}

LM35Logger.java

package com.oksbwn.Arduino;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.OutputStream;



import gnu.io.CommPortIdentifier;

import gnu.io.SerialPort;

import gnu.io.SerialPortEvent;

import gnu.io.SerialPortEventListener;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Enumeration;



public class SerialTest implements SerialPortEventListener

{

int i;

SerialPort serialPort;

String trmp;

DateFormat DateF = new SimpleDateFormat("dd/MMM/yyyy");

DateFormat TimeF = new SimpleDateFormat("HH:mm");

DateFormat TimeM = new SimpleDateFormat("mm");

private static final String PORT_NAMES[] ={"/dev/tty.usbserial-A9007UX1","/dev/ttyACM0","/dev/ttyUSB0","COM7",};

private BufferedReader input;

private OutputStream output;

private static final int TIME_OUT = 2000;

private static final int DATA_RATE = 9600;



public void initialize()

{ Enumeration<?> ports = CommPortIdentifier.getPortIdentifiers();



CommPortIdentifier portId = null;

while (ports.hasMoreElements())

{

CommPortIdentifier curPort = (CommPortIdentifier)ports.nextElement();

for (String portName : PORT_NAMES)

{

if (curPort.getName().equals(portName))

{

portId = curPort;

break;

}

}

}

if (portId == null)

{

return;

}



try {

// open serial port, and use class name for the appName.

serialPort = (SerialPort) portId.open(this.getClass().getName(),

TIME_OUT);



// set port parameters

serialPort.setSerialPortParams(DATA_RATE,

SerialPort.DATABITS_8,

SerialPort.STOPBITS_1,

SerialPort.PARITY_NONE);



// open the streams

input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));

output = serialPort.getOutputStream();



// add event listeners

serialPort.addEventListener(this);

serialPort.notifyOnDataAvailable(true);

} catch (Exception e) {

System.err.println(e.toString());

}

}



/**

* This should be called when you stop using the port.

* This will prevent port locking on platforms like Linux.

*/

public synchronized void close() {

if (serialPort != null) {

serialPort.removeEventListener();

serialPort.close();

}

}



/**

* Handle an event on the serial port. Read the data and print it.

*/

public synchronized void serialEvent(SerialPortEvent oEvent) {

if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {

try {

i++;

String x = "ALBERTO";

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/alberto","root","");

ResultSet res=con.prepareStatement("SELECT * FROM `lcd_data`").executeQuery();

if (res.next())

{

x=res.getString("Data");

}

String inputLine=input.readLine();

Date dat = new Date();

trmp=inputLine.substring(13,inputLine.length()-2);

if(TimeM.format(dat).charAt(1)=='7')

con.prepareStatement("INSERT INTO `room_temperature` (`Sl_No`, `Temperature`, `Date`, `Time`) VALUES (NULL, '"+trmp+"', '"+DateF.format(dat)+"', '"+TimeF.format(dat)+"')").executeUpdate();

con.close();

output.write(x.getBytes());

} catch (Exception e) {}

}

// Ignore all the other eventTypes, but you should consider the other ones.

}



public static void main(String[] args) throws Exception {

SerialTest main = new SerialTest();

main.initialize();

Thread t=new Thread() {

public void run() {

//the following line will keep this app alive for 1000 seconds,

//waiting for events to occur and responding to them (printing incoming messages to console).

try {Thread.sleep(1000000);} catch (InterruptedException ie) {}

}

};

t.start();

System.out.println("Started");

}

}
Categories: Arduino, bikash, c, JAVA, LM35, nist, oksbnw, temperature logger Tags:

Control VLC Player using Android (Wifi Connected)

May 15th, 2014 No comments
    My first application of Android comes here.In my first tutorial on Controlling VLC using JAVA you can see that the VLC provides a Web interface from which it can be controlled and it also accepts certain commands.So that can be used to control the media player in Local Area Network using any programming language.This time its Android

Code:
MainActivity.Java

package com.example.first_app;
import java.net.Authenticator;
import java.net.URL;


import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setDetectEnabled(true);
final TextView tv1 = (TextView) findViewById(R.id.textView1);
tv1.setText("Bikash");
tv1.setTextColor(Color.BLACK);

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

final Button Prev = (Button) findViewById(R.id.button1);
final Button Play = (Button) findViewById(R.id.Button01);
final Button Next = (Button) findViewById(R.id.Button02);
final Button TenS = (Button) findViewById(R.id.button2);
final Button OMin = (Button) findViewById(R.id.button4);
final Button MTS = (Button) findViewById(R.id.button3);
final SeekBar volume = (SeekBar) findViewById(R.id.seekBar1);
//volume.get

TenS.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=seek&val=+20";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
OMin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=seek&val=+60";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
MTS.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=seek&val=-20";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
Prev.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=pl_previous";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
Play.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=pl_pause";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
Next.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=pl_next";
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

});
volume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar,int progresValue, boolean fromUser)
{
progress = progresValue;
try {
String urlString = "http://192.168.0.10:8080/requests/status.xml?command=volume&val="+5*progress;
Authenticator.setDefault(new authoRize());
URL url = new URL(urlString);
url.getContent();
} catch (Exception e) {
tv1.setText(e.toString());
tv1.setTextColor(Color.BLACK);
}

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv1.setText(progress + "/" + seekBar.getMax());
}
});

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void setDetectEnabled(boolean enable) {
Intent intent = new Intent(this, CallDetectService.class);
startService(intent);

}

}




CallHelper.Java

package com.example.first_app;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class CallHelper {

/**
* Listener to detect incoming calls.
*/
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
try {
HttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://192.168.0.10/API/mobileControl.php?NO="+incomingNumber+"&STATE=YES");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String SetServerString=client.execute(httpget,responseHandler);
} catch (Exception e) { }
break;
}
}
}



private Context ctx;
private TelephonyManager tm;
private CallStateListener callStateListener;
public CallHelper(Context ctx) {
this.ctx = ctx;

callStateListener = new CallStateListener();
}

/**
* Start calls detection.
*/
public void start() {
tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

}

/**
* Stop calls detection.
*/
public void stop() {
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
}

}


CallDetectService.Java

package com.example.first_app;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class CallDetectService extends Service {
private CallHelper callHelper;

public CallDetectService() {
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
callHelper = new CallHelper(this);

int res = super.onStartCommand(intent, flags, startId);
callHelper.start();
return res;
}

@Override
public void onDestroy() {
super.onDestroy();

callHelper.stop();
}

@Override
public IBinder onBind(Intent intent) {
// not supporting binding
return null;
}
}

authoRize.Java

package com.example.first_app;

import java.net.Authenticator;

import java.net.PasswordAuthentication;



class authoRize extends Authenticator {

    private String username, password;



    public authoRize() {

      username = "";

      password = "*****";

    }

    protected PasswordAuthentication getPasswordAuthentication() {

      return new PasswordAuthentication(username, password.toCharArray());

    }

  }

NOTE: Download complete code Here