субота, 2. јун 2012.

Science festival report and Virtual blackboard using Kinect and Android

  Hello everybody, it's been a while, but we are once again here with some new interesting posts. Last week you've got our post about WIFI chat, and we hope it was interesting to find out something new about that. So, what we will talk about in this post ? You remember when Science festival "nauk nije bauk" was that we 've promised some photos and videos about all that. So, we were preety lazy and we apologize, but this post will be our excuse. Frst of all, festival went great, so many visitors, so many people interested in our projects, and our stand was one of the most visited.  First, you can have a look at some photos form the festival, and after that you can see a video about Kinect project that our colleague Stefan worked on. It was one of the biggest attractions in the festival, among kids and students and professors also. We hope to put some more videos about our projects in the future. Also, one notification, recently we've started doing some work about  artificial intelligence, Natural language processing and stufs like that, so in our next posts we will start writting some stufs about that. Oh yes, Stefan's video is in Serbian, it may be usefull for students who are currently doing their porojects at "Elektronski fakultet" u Nisu, if anyone wants, download the video, make english subtitles and send it back so we can post it. Keep in touch, peace !














VIDEO - Here is the link for the video, so hust click it, and enjoy :)  http://www.youtube.com/watch?v=OsAdbeTH9RU


субота, 26. мај 2012.

Wireless chat application using portable WiFi hotspot


Introduction
The Android platform includes support for the wireless network stack, which allows a device to wirelessly exchange data with other devices. The application framework provides access to the wireless functionality through the Android wireless APIs. These APIs let applications connect wirelessly to other devices, enabling point-to-point and multipoint wireless features.

This application allows 2 or more Android devices to communicate without using any external resorces (without Internet at all, also chat servers). What separates this application from the ordinary ones is usage of only tethering.

Depending on your model of Android device and your carrier, you may be able to share your Google™ Android™ device’s mobile data connection with a single computer via a USB cable or via Bluetooth. You may also be able to share your Android device’s data connection with up to five devices at once, by turning your phone into a portable Wi-Fi hotspot.

Establishing connection


   You can turn your Android phone into a portable wi-fi hotspot and get another Android phone to share some information. For this you will need to have Android 2.2 installed on your phone.
The Android  platform introduces many new and exciting features for users and developers.
SHARE YOUR DATA CONNECTION AS A PORTABLE WI-FI HOTSPOT
Open the Settings application.
Touch Wireless & networks > Tethering & portable hotspot.
Check Portable Wi-Fi hotspot.
After a moment, the device starts broadcasting its Wi-Fi network name (SSID), so you can connect to it with up to 8 computers or other devices. An ongoing notification is added to the System bar, to the left of the time.
When Portable Wi-Fi hotspot is checked, you can change its network name or secure it. See Rename or secure your portable hotspot.
Uncheck Portable Wi-Fi hotspot to stop sharing your data connection via Wi-Fi.
Below are setup instruction.



If you want co configure Wi-Fi hotspot,below are next steps





Android chat application

Main goal with this application is making wireless chat communication between android devices.  Application enables tethering (via wifi) for handsets running android. Clients (another android devices) can connect via wifi (ad-hoc mode) and get access from access point, in this case this is android device. When communication is established as described above, application opens a connection and it is possible to send messages between devices.




One device simulates the server side, while another client. To open a connection between devices, you need to make tcp/ip connection using a Socket and ServerSocket in Java.
A socket is a software endpoint that establishes bidirectional communication between a server program and one or more client programs. The socket associates the server program with a specific hardware port on the machine where it runs so any client program anywhere in the network with a socket associated with that same port can communicate with the server program.
A server program typically provides resources to a network of client programs. Client programs send requests to the server program, and the server program responds to the request.

One way to handle requests from more than one client is to make the server program multi-threaded. A multi-threaded server creates a thread for each communication it accepts from a client. A thread is a sequence of instructions that run independently of the program and of any other threads.
Using threads, a multi-threaded server program can accept a connection from a client, start a thread for that communication, and continue listening for requests from other clients.


уторак, 20. март 2012.

Arduino and Android on Science Festival



Hello everybody,

     it has been a while, but we are back in action. This post is little different because it contains some news about our future work and activities. It also contains explanation why we haven't written anytning in past 2 weeks. It is because we are currently focused on something else. We are very proud to announce that we will be participants  in Science festival "Nauk nije bauk" which will be held for the forth time at  Faculty of Electronic Engineering in Nis, Serbia. It is a big honor and also big award for all the work we have put to make our Arduino Android projects, and also big obligation to be very good in Science Festival "Nauk nije bauk". 

  and time was passing and passing and  passing and something happaned :)

 So, after few days, we finally have something to say about our projects on Science festival "Nauk nije bauk". We said earlier that festival will be held for the fourt time at Faculty of Electronic Engineering in Nis, Serbia on the 30th and the 31st of March, 2012. There will be stands about...well, just everything, from history to modern technology and also big number of interesting lectures on both days of the festival. Here is schedule for all the lectures (it is in Serbian language) - http://www.juznevesti.com/Drushtvo/Brojna-predavanja-na-Festivalu-nauke.sr.html. Now, something more about our stand. As we know untill now, we will be in the big main hole.  Beside many projects on our stand, visitors can see Arduino projects we have written about on this blog. Here is the official poster for our stand (in Serbian language).



During our last posts you were able to read about connection between Arduino parking assistens systems and matrix led displays. Visitors will have opportunity to see how Arduino can interact with SmartHome systems and be used in Fluid heating control. Also, one project which is in my modest personal opinion very good and worth to see is not connected with Arduino boards, but never mind about that when project is so good. It is connection between Android and Windows Kinect, so vicitors will be able to draw shapes and change colors on the screen with use of their hands moving through the air. So, no keyboard and no mouse for that.  For all ones who are not form Serbia and can't come, we will try to make lot of pictures and videos and post them here after the festival. Here are images  for the first two pages of our official flyers (also in Serbian language), and at the end, we can just invite anyone who have interest in Science to come and see what is new in science.











понедељак, 27. фебруар 2012.

Arduino and Android parking assistance 2 (ANDROID communication part )


Hi guys,

hope you have enjoyed reading our last post about „Matrix led display controlled by Arduino and Android - the coding part“. Now we want to build on the previous post about Arduino and Android parking assistance. Just now we’ll talk about Android Parking assistance app. As we could see in  previous post how look like Android app interface,  in this post we’ll describe how were implemented bluetooth protocol.

We all know Android is very popular now, especially ADK (Android Open Accessory Development Kit), which allows external 0pen source hardware to connect with Android system by USB and interact with an Android-powered device in a special “accessory” mode.
To make the communication between Android and Arduino easy, we would like show you a new way that android interact with Arduino and other similar boards. Bluetooth for example.

Step one: Make a APP to Android which could communicate with other devices by bluetooth.
Step two: Android APP connect to Arduino by Bluetooth Mate Silver.

This APP allows Android connect to each other by bluetooth, so you need at least two Android devices for this app.

Bluetooth

            The Android platform includes support for the Bluetooth network stack, which allows a device to wirelessly exchange data with other Bluetooth devices. The application framework provides access to the Bluetooth functionality through the Android Bluetooth APIs. These APIs let applications connect wirelessly to other Bluetooth devices, enabling point-to-point and multipoint wireless features.

The Basics

All of the Bluetooth APIs are available in the Android bluetooth package. Here is a summary of the classes you will need to create as below.

ü  BluetoothAdapter: Represents the local Bluetooth adapter (Bluetooth radio)
ü  BluetoothDevice: Represents a remote Bluetooth device, query information such as its name, address, class, and bonding state.
ü  BluetoothSocket: Represents the interface for a Bluetooth socket (similar to a TCP Socket).
ü  BluetoothServerSocket: Represents an open server socket that listens for incoming requests (similar to a TCP ServerSocket).
ü  BluetoothClass: Describes the general characteristics and capabilities of a Bluetooth device.

Bluetooth Permissions

                In order to use Bluetooth features in your application, you need to declare at least one of two Bluetooth permissions: BLUETOOTH and BLUETOOTH_ADMIN.
Declare the Bluetooth permissionin your application’s AndroidManifest.xml as below.

AndroidManifest.xml
<manifest ... >
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  ...
</manifest>
Let us see some code, really start from here. In order to connect by bluetooth, there should be four steps as below:
  • Setting Up Bluetooth
  •  Finding Device
  •  Connecting Device
  •   Managing Device


Setting Up Bluetooth

We made the App include eight java files. For now, we only need to use:

·         Main.java,
·         DiscoveryActivity.java
·         ClientSocketActivity.java

Before your application can communicate with Bluetooth, you should verify Bluetooth is supported on the device and make sure that it is enabled. If Bluetooth is not supported, you should gracefully disable any Bluetooth features. If Bluetooth is supported, but disabled, you are able to request the user enable Bluetooth without leaving your application. So, at Main.java in Tab Settings we get five buttons, as below:

  Select “Enable Bluetooth” button make the device’s own Bluetooth adapter (the Bluetooth radio) working. There is one Bluetooth adapter for the entire system, and your application can interact with it when it is open.


public BluetoothAdapter _bluetooth = BluetoothAdapter.getDefaultAdapter(); 
...
public void EnableBluetooth(View v)
{
                Toast.makeText(this, "Bluetooth enable", Toast.LENGTH_LONG).show();
                _bluetooth.enable();  
               
                Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                startActivityForResult(enabler, REQUEST_DISCOVERABLE);
                               
}

/*
   There are two ways to enable bluetooth
1)
   Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
   startActivityForResult(enabler, REQUEST_DISCOVERABLE);
2)
   _bluetooth.enable();
*/




Create a new Intent as  
“Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)”, a dialog box will appear and request user permission to enable Bluetooth. Select “Yes” and the system will enable Bluetooth and focus will return to your application once the process completes.

            You need to ensure that Bluetooth is enabled and allowed other devices could discover it. Add the below code, and a dialog box will appear also, you should click “Yes”.
A part of code for each button activity in Main.class as bellow:

Main.java
public void openBluetooth(View v)
    {
       Toast.makeText(this, "Bluetooth enable ...", Toast.LENGTH_LONG).show();
       _bluetooth.enable();      
       Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
              startActivityForResult(enabler, REQUEST_DISCOVERABLE);
             
    }

       public void closeBluetooth(View v)
    {        
             ........

       _bluetooth.disable();
       Toast.makeText(this, "Bluetooth disable ...", Toast.LENGTH_LONG).show();
      
              ........
    }
   
    public void searchDevices(View v)
    {
       Intent search = new Intent();
       search.setClass(c, DiscoveryActivity.class);
       startActivity(search);
    }
   
    public void openClientSocketButton(View v)
    {
       Intent enabler = new Intent(c,ClientSocketActivity.class);
       startActivity(enabler);
    }




Finding Device

            With Discovery Activity.java file, we will find around device. The process is asynchronous and the method will immediately return with a boolean indicating whether discovery has started successfully. The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each found device to retrieve its Bluetooth name. Your application must register a BroadcastReceiver for the ACTION_FOUND. Intent in order to receive information about each device discovered.

/* Register Receiver*/
IntentFilter discoveryFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(_discoveryReceiver, discoveryFilter);
IntentFilter foundFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(_foundReceiver, foundFilter);

/**
 * Receiver
 * When the discovery finished be called.
 */
private BroadcastReceiver _foundReceiver = new BroadcastReceiver()
{
       public void onReceive(Context context, Intent intent) {
       /* get the search results */
       BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
       /* push in ArrayList */
       _devices.add(device);
       /* show the devices list */
       showDevices();
       }
};

private BroadcastReceiver _discoveryReceiver = new BroadcastReceiver() {
              @Override
       public void onReceive(Context context, Intent intent) 
       {
       /* unRegister Receiver */
       Log.d("EF-BTBee", ">>unregisterReceiver");
             
       unregisterReceiver(_foundReceiver);
       unregisterReceiver(this);
       _discoveryFinished = true;
       }
};
      


After discovery will return remote device’s MAC address, device name and class. Using this information, the device performing discovery can then choose to initiate a connection with the discovered device. The following figure is click the “Search Device” button.


Connecting Device and Managing Device

            In order to create a connection between your application and two devices, you must implement the both server-side and client-side mechanisms, because one device must open a server socket and the other one must initiate the connection (use the server device’s MAC address to initiate a connection). So you must used a same UUID.

As Client:
UUID for Android App
socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));




The full code of class ClientSocketActivity.java
package com.android;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

public class ClientSocketActivity  extends Activity
{
  private static final String TAG = ClientSocketActivity.class.getSimpleName();
  private static final int REQUEST_DISCOVERY = 0x1;;
   private Handler _handler = new Handler();
   private BluetoothAdapter _bluetooth = BluetoothAdapter.getDefaultAdapter();
   private BluetoothSocket socket = null;
      
       protected void onCreate(Bundle savedInstanceState)
       {
              super.onCreate(savedInstanceState);
              getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
              WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
              setContentView(R.layout.client_socket);
              if (!_bluetooth.isEnabled())
             {
                     finish();
                return;
              }

             Intent intent = new Intent(this, DiscoveryActivity.class);   
             /* Prompted to select a server to connect */
             Toast.makeText(this, "select device to connect", Toast.LENGTH_SHORT).show();
              /* Select device for list */
              startActivityForResult(intent, REQUEST_DISCOVERY);
       }
      
      
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
/*The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from */
             
             if (requestCode != REQUEST_DISCOVERY)
              {
                     return;
              }
/*resultCode  The integer result code returned by the child activity through
               * its setResult() */
              if (resultCode != RESULT_OK) {
                     return;
              }
             
             final BluetoothDevice device = data.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
              connect(device);          
       }
      
      
       protected void connect(BluetoothDevice device)
       {
              //BluetoothSocket socket = null;
              try {
    //Create a Socket connection: need the server's UUID number of registered
              socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
                    
                     Singleton.remote_soket=socket;
                     Intent i=new Intent();
                     i.setClass(this.getApplicationContext(), Main.class);
                     startActivity(i);
                     finish();
                     return;
                    
              } catch (IOException e) {
                     Log.e("EF-BTBee", "", e);
              }
       }
}




When user selects device which he wants to connect, it looks like on picture above:


So, if anyone have some problem, with code, leave a comment and we will try to answer and solve the problem. As we mentioned earlier, we hope to post some more videos about how system is working and also write about some new projects (some stuff about using Arduino in Smart houses, so very interesting topics)...anyway, see you soon

M&M