Current Date and Time using php
<?php
echo date("Y/m/d") . "<br>";
echo date("Y.m.d") . "<br>";
echo date("Y-m-d");
date_default_timezone_set('Asia/Calcutta');
$date1 = date("Y-m-d H:i:s");
echo "<br>".$date1;
?>
SMS retrieve using AT commands and store data in mysql database(For Wave II mobile)
import javax.comm.*;
import java.io.*;
import java.net.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ListPortClass3
{
public static void main(String[] s)
{
String str="AT+CMGF=1\r";
int k=1;
try{
input(str,0);
Thread.sleep(1000);
input("AT+CPMS=\"SM\"\r",0);
Thread.sleep(1000);
while(true){
input("AT+CMGR="+k+"\r",1);
Thread.sleep(1000);
k++;
}
}
catch(Exception e){}
}
public static void input(String mValue,int flag)
{
//String mValue = null;
//strcpy(mValue,str1);
try
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("COM14");
if (portIdentifier.isCurrentlyOwned())
{
System.out.println("Port in use!");
}
else {
System.out.println(portIdentifier.getName());
SerialPort serialPort = (SerialPort) portIdentifier.open("ListPortClass", 9600);
int b = serialPort.getBaudRate();
System.out.println(Integer.toString(b));
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
OutputStream mOutputToPort = serialPort.getOutputStream();
InputStream mInputFromPort = serialPort.getInputStream();
//String mValue = "AT+CPMS=\"SM\" \r";
System.out.println("beginning to Write . \r\n");
//while(a<=2)
//{
mOutputToPort.write(mValue.getBytes());
System.out.println("AT Command Written to Port. \r\n");
mOutputToPort.flush();
Thread.sleep(500);
//a++;
//}
byte[] mBytesIn = new byte[1024];
int i=0;
int len=-1;
while(true)
{
//len=mInputFromPort.read(mBytesIn);
if ( (len = mInputFromPort.read(mBytesIn))> -1)
{
String s=new String(mBytesIn,0,len);
System.out.println(s);
//System.out.println(len);
//mBytesIn=null;
//len=0;
if(flag==1){
String str2[]=s.split("\"");
data(str2[3],str2[5],str2[6]); // for database
for(int j=0;j<str2.length;j++)
{
System.out.println(j+"="+str2[j]);
//System.out.println("2="+"="+str2[4]);
}
}
//if(s.charAt(len-1)=='K' && s.charAt(len-2)=='O')
break;
}
else
{
System.out.print("*");
break;
}
}
//mOutputToPort=null;
//mInputFromPort=null;
//serialPort=null;
serialPort.close();
}
}
catch (Exception ex)
{
System.out.println("Exception : " + ex.getMessage());
}
}
public static void data(String first,String second,String third)
{
String url = "jdbc:mysql://localhost:3306/";
String db = "phd";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass= "";
String data1=null;
try{
Connection con=null;
System.out.println("database");
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st=con.createStatement();
Statement st1=con.createStatement();
st1.executeUpdate("insert into sms(mbno,dateandtime,content) values('"+first +"','" +second + "','"+third+"')");
ResultSet rs=st.executeQuery("select * from sms");
while(rs.next())
{
data1 = ":" + rs.getString("id") + ": " + rs.getString("mbno")+":"+rs.getString("dateandtime")+":"+rs.getString("content")+":";
System.out.println(data1+" ");
}
}
catch (SQLException s){
System.out.println("No any table in the database");
}
catch (ClassNotFoundException e){
System.err.println(e.getMessage());
}
catch(Exception e){System.out.println(e);}
}
}
Android Program
Activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello_world"
android:textSize="30sp"
/>
<Button
android:id="@+id/addButtonn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:text="@string/Add" />
<Button
android:id="@+id/subButtonn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/addButtonn"
android:layout_below="@+id/addButtonn"
android:layout_marginTop="18dp"
android:text="@string/Sub" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/subButtonn"
android:layout_below="@+id/subButtonn"
android:layout_marginTop="28dp"
android:gravity="right"
android:text="@string/present"
/>
</RelativeLayout>
Activity_main.java
package com.example.addsubtract;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int
counter;
Button
add,sub;
TextView
tv;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
tv=(TextView)findViewById(R.id.textView1);
add=(Button)findViewById(R.id.addButtonn);
sub=(Button)findViewById(R.id.subButtonn);
add.setOnClickListener(new
OnClickListener() {
@Override
public
void onClick(View arg0) {
//
TODO Auto-generated method stub
counter++;
tv.setText("Your
Result is"+counter);
}
});
sub.setOnClickListener(new
OnClickListener() {
@Override
public
void onClick(View arg0) {
//
TODO Auto-generated method stub
counter--;
tv.setText("Your
Result is "+counter);
}
});
}
@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;
}
}
AndroidMainFest.xml
<?xml version="1.0"
encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.addsubtract"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.addsubtract.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AddSubtract</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Your Total is 0</string>
<string name="Add">Add By One</string>
<string name="Sub">Sub By One</string>
<string name="present">Presented By Ashok</string>
</resources>
How to install The Java Communications API and RXTX API
How to install The Java Communications API
There is a trick to install the Java Communications API correctly on a Windows system Machine. The following files are the core of JAVA Communiccation API, and they are very important to have them installed on your system for a proper operation:
- comm.jar
- win32com.dll
- javax.comm.properties
For the jdk (Java Developnment Kit) to recognize the serial ports on your machine, it is important to properly place these files in the right folders on your local machine :
%Java_HOME% = the location of your jdk directory.
To Find your JDK directory, Use the Following steps:
1. Click on Start
2. Click on Search
3. Click on For Files or Folders …
4. In the Left hand Side, Click on All Files and Folders
5. Type in jdk* in the textbox under All or part of the file name:
6. Click Search
7. Look for yellow icon that looks like a folder
8. Double Clikc on the folder to open the jdk folder
2. Click on Search
3. Click on For Files or Folders …
4. In the Left hand Side, Click on All Files and Folders
5. Type in jdk* in the textbox under All or part of the file name:
6. Click Search
7. Look for yellow icon that looks like a folder
8. Double Clikc on the folder to open the jdk folder
comm.jar should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext
win32com.dll should be placed in:
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32
javax.comm.properties should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
RXTX INSTALLATION
Windows RXTXcomm.jar goes in \jre\lib\ext (under java) rxtxSerial.dll goes in \jre\bin Mac OS X (x86 and ppc) (there is an Installer with the source) RXTXcomm.jar goes in /Library/Java/Extensions librxtxSerial.jnilib goes in /Library/Java/Extensions Run fixperm.sh thats in the directory. Fix perms is in the Mac_OS_X subdirectory. Linux (only x86, x86_64, ia64 here but more in the ToyBox) RXTXcomm.jar goes in /jre/lib/ext (under java) librxtxSerial.so goes in /jre/lib/[machine type] (i386 for instance) Make sure the user is in group lock or uucp so lockfiles work. Solaris (sparc only so far) RXTXcomm.jar goes in /jre/lib/ext (under java) librxtxSerial.so goes in /jre/lib/[machine type] Make sure the user is in group uucp so lockfiles work.
Android Program
Activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello_world"
android:textSize="30sp"
/>
<Button
android:id="@+id/addButtonn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:text="@string/Add" />
<Button
android:id="@+id/subButtonn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/addButtonn"
android:layout_below="@+id/addButtonn"
android:layout_marginTop="18dp"
android:text="@string/Sub" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/subButtonn"
android:layout_below="@+id/subButtonn"
android:layout_marginTop="28dp"
android:gravity="right"
android:text="@string/present"
/>
</RelativeLayout>
Activity_main.java
package com.example.addsubtract;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int
counter;
Button
add,sub;
TextView
tv;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
tv=(TextView)findViewById(R.id.textView1);
add=(Button)findViewById(R.id.addButtonn);
sub=(Button)findViewById(R.id.subButtonn);
add.setOnClickListener(new
OnClickListener() {
@Override
public
void onClick(View arg0) {
//
TODO Auto-generated method stub
counter++;
tv.setText("Your
Result is"+counter);
}
});
sub.setOnClickListener(new
OnClickListener() {
@Override
public
void onClick(View arg0) {
//
TODO Auto-generated method stub
counter--;
tv.setText("Your
Result is "+counter);
}
});
}
@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;
}
}
AndroidMainFest.xml
<?xml version="1.0"
encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.addsubtract"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.addsubtract.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AddSubtract</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Your Total is 0</string>
<string name="Add">Add By One</string>
<string name="Sub">Sub By One</string>
<string name="present">Presented By Ashok</string>
</resources>
Subscribe to:
Posts (Atom)
using avrdude with AVR studio(for windows 10 only)
Requirements 1. arduino-1.6.5-r2-windows.exe 2. as6installer-6.0.1843.exe When I try to configure avrdude in avr studio 6 then wina...
-
Requirements 1. arduino-1.6.5-r2-windows.exe 2. as6installer-6.0.1843.exe When I try to configure avrdude in avr studio 6 then wina...
-
How to install The Java Communications API There is a trick to install the Java Communications API correctly on a Windows system Mac...
-
1. select state of india 2. district dropdown box appear Requirements 1. xampp 2.knowledge of PHP 3.jquery C...