November 6, 2013

Windows Mobile platform kick off by Afiq

Below is the post written by Afiq on hist first kick start with Windows App development :

Afiq Here and this is my first update.

This blog post is about my attempt at setting up the windows phone 8 development environment nad my experience playing with the environment in visual studio. I will reference all the websites that I went to in my attempt to install the necessary files

1. First I installed this file as recommended by Raf. It wasn't much, It just provided me with some of these tile apps.

http://www.microsoft.com/en-us/download/details.aspx?id=17284






2. Then I installed visual studio express 2012 from this website. This one took quite long to install and with some errors. The whole suite came with Blend for Visual Studio. It is so far running without errors but at one point during the installation it said that some features were missing. So I think it only partially installed correctly. I ran a repair install afterwards and I think it should be better now.

http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products


3. Seeking reference I then found this MSDN blog article that I used to verify all the steps that I achieved so far. I followed all the instructions and I find that this was the clearest and easiest set of instructions to follow. Everything went about without a hitch.

http://blogs.msdn.com/b/cdndevs/archive/2013/10/01/setting-up-your-windows-phone-development-environment-in-30-minutes-or-less.aspx



4. This is the development environment that I have so far. It is compliant with the picture in the file taken from the W8 guide given before the holidays given by Mr. Ling.


I watched this YouTube video that showed exactly the same platform and introduced some programming conventions that I had to be aware of for windows phone 8 development.

http://www.youtube.com/watch?v=blU9rBiVURM



My progress is now shalted because the emulator is having some problems. Apparently my brand new computer is missing the prerequisite of being windows 8 professional version but all the prerequisites for running the hyper-v virtualisation machine are all there.

Some of these basic prerequisites include
4 GB RAM
x64 architecture
Supports SLAT (Second Level Address Transition)






All of which I already satisfy the needs of.

Everytime I want to run the simulator an error occurs, unlike the YouTube video tutorial in which the Emulator is easy fast and accessible, mines does not want to function at all. This is what I get when I run the emulator.




My proposed solution ...
Go Pirate, RRrrrrrrr....
And run the same installation steps over again. I Think it will be faster on a clean slate.
Thats all from me,

Afiq Hamid,
6/11/2013

October 22, 2013

Querying RSSI by the App

I have mentioned before that we have 2 ways to check for signal strength (which then approximates distance) of the bluetooth communication in our system, particularly between the App and the Rpi.

    1. Query done by Rpi
    2. Query done by Android App

I have not yet checked on how I can get the first step done programmatic-ally, for the purpose of integrating it into our Server program. This example showed how it is done via terminal : forum link.

However, I have a written a simple app for the 2nd method. This App catches the RSSI values of every bluetooth devices it found during 'discovery' by requesting an extra field in ACTION_FOUND intents of the discovery : EXTRA_RSSI. This value (of data type Short) contains the RSSI value of the remote devices found.

Here is the snippet on how it is done:

// Create a BroadcastReceiver for ACTION_FOUND
BroadcastReceiver receiver;
receiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
           
    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
           
    // Get the BluetoothDevice object from the Intent
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
               
    // Add the name and address to an array adapter to show in a ListView
     mArrayAdapter.add(device.getName() + "\n" + device.getAddress() + "\n" + rssi + " db" + "\n" );
              
    //add notify discovery is done
    Toast.makeText(getApplicationContext(),"Bluetooth devices discovery done...", Toast.LENGTH_SHORT).show();
       
     }
     }
};

In short, we can get the signal strength of any discovered bluetooth devices, without even having to connect to those devices. Hence, 'signal strength' or more correctly, 'distance between the user and the door' verification can be done first before 'key' verification. Refer HERE to see the methods we proposed earlier.

Here is the updated version of the App (remove the RSSI values display through toast, put them into the list view instead).



Downloads:
Apk
MainActivity (main code)
Project files (all)



October 11, 2013

Measuring distance between user and the door



We have no way of measuring distance directly between the user (the phone) and the door. However, we can safely approximate the distance by querying the "strength" of the received signal of the Bluetooth communication. The term is called Bluetooth Received Signal Strength Indication (RSSI). RSSI is the relative received signal strength in arbitrary units.

In short, the closer the distance, the bigger the strength of the received signal, the bigger the RSSI numbers.

In our case, we have two ways to implement this:
  1. The Rpi does the query for signal strength and responses (to command the microcontroller to unlock the door) only when the signal strength is within the safe operating range.
  2. The App (instead of the Rpi), which initiates the connection, sends the signal ("within range" or "not within range") along with key based on the received signal strength (Android is able to provide this automatically on each Bluetooth connection or we can use one of the public methods to query manually) of the Rpi.
However, both methods relies heavily on the actual Bluetooth devices that we are using. We need to do some test on our own to approximate better (sadly we only have one Bluetooth dongle that works with Rpi at this moment).

This is one example I've got from the net which should give us some approximations:

          RSSI              Position
          38                   Phone touching Bluetooth dongle
          25                   Phone an inch away
          10                   Phone about 6 inch away
          0                     From 2 feet to opposite side of room
          -3                    In next room (with a wall between)
          -10                  2 walls away

source:
Link1
Link2
Link3





October 10, 2013

Unlocking : sending keys and verification

In the last meeting, we discussed on how we can implement the verification of the key in the most efficient way, while not risking the security aspect of the system.

We agreed that we would be implementing a distance measuring mechanism (I'll write about it in another post), in which the door is to be set "ready to be unlocked" only when the user is within the safe distance from the door (2-3 meters).

This adds another type of verification which is the distance between the user and the Rpi itself.

The figure above shows how Rpi is used to validates both 'distance' and 'key'. Alternatively, 'distance' can be validated via the Android App itself.

September 24, 2013

Substitution Cipher - Java

Downloadable file : Substitution Cipher


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class subs_cipper { 
      public static void main(String[] args) { 
  
      System.out.println("This is to demonstrate the Substitution Cipher");
      System.out.println("Each alphanumeric char is mapped to a String (arbitrarily, of two chars length)");
      System.out.println("For example, 'A' is mapped to \"OA\", 'B' is mapped to \"9B\", and so on...");
      System.out.print("\nTest String = ");
      String plaintext = "WHYAMIDOINGTHISWHYAREWEHEREWHATAREWEDOING";
      //string to be ciphered
      //String plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 
      //use this to check. With this, 
      //...plaintext = Keys, and Ciphertext = Values
      System.out.print(plaintext);
      
      //Encryption
      System.out.println("\n\nCiphertext = ");
      Cipher ObjCipher = new Cipher();
      String ciphertext = ObjCipher.Encrypt(plaintext);  
      //output ciphered string
      System.out.println(ciphertext);
      
      //Decryption
      System.out.print("\nPlaintext = \n");
      String outplaintext = ObjCipher.Decrypt(ciphertext);  
      //output deciphered string
      System.out.print(outplaintext);
   }
}


//the class that that implements the actual encryption
class Cipher {
String keys, values;  
     //Keys & Values for HashMap
String plaintext, ciphertext;
HashMap<String, String> map = new HashMap<String, String>(); 
     //HashMap to do the mapping


//constructor, instantiates the HashMap
public Cipher(){
//one-to-one mapping (Keys - Values) of different length. In this example, 
//A:OA, B:9B, C:8C &  so on...
 keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
values = "0A9B8C7F6E5R4F3T2J1K4LX2VN18K9LC42B7" +
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";


//use for loop to fill up & map the Keys to the respective Values
for (int i=0; i<keys.length(); i++){
char charkey = keys.charAt(i);  
       //get each char from the Keys & convert to String
String tempkey = Character.toString(charkey);

char charval1 = values.charAt(i*2);  
       //get every two chars from the Values & convert to String
String tempval1 = Character.toString(charval1);  
       //...and concatenate both chars to form a single String
char charval2 = values.charAt(i*2+1);
String tempval2 = Character.toString(charval2);
String tempval = tempval1 + tempval2;

map.put(tempkey, tempval);  
       //fill the HashMap
}

}


//Encrypt method, do the Encryption, takes Plaintext as argument
public String Encrypt(String plaintext){
String output = "";
char ch;

for (int i=0; i<plaintext.length(); i++){  
   //go through the plaintext 
ch = plaintext.charAt(i);    
       //take each chars as 'Key'
String str = Character.toString(ch);  
       //..and map to its corresponding 'Value'
output = output + map.get(str);
}
 
   return output;  
   //returns the the encrypted String
}


//Decrypt method, do the Decryption, takes Ciphertext as argument
public String Decrypt(String ciphertext){
String output = "";
char ch;
String str = "";

for (int i=0; i<ciphertext.length(); i = i+2){  
  //get next two adjacent chars from the Ciphertext
ch = ciphertext.charAt(i);    
       //concatenates them into a single String
str = Character.toString(ch);
ch = ciphertext.charAt(i+1); 
str = str + Character.toString(ch);

Iterator j = map.entrySet().iterator();  
       //look up through HashMap by the Value 

while (j.hasNext()) {  
       //...to find the corresponding Key
Map.Entry entry = (Map.Entry) j.next();
if (str.equals((String)entry.getValue())){  
                //concatenates the output with each Key found
output = output + (String)entry.getKey();
}
}
}

return output;  
  //return the Decrypted String
}

}


September 6, 2013

UI design (again!)

Since we have passed the first demonstration, it's time now to design for the final prototype. I have considered a few ideas of how our App will look like, and what kind of functionality that we will be offering. Unline UniKey, we don't have our system connected to the net, which makes our system simpler than theirs (apart from more secured, that's it). These are the interfaces that I came out with, as of now.

  


What do you think?


August 26, 2013

First prototype

So we decided that 3D printing service will take quite a little bit of time and we are not yet ready to finalize the design for it, among other things (the cost is a headache too!). Since the first presentation is just around the corner, we gonna go with a quicker solution : a prototype made wholly out of wood. We have been going around the hardware shops nearby and finally able to get some good looking woods for our project with cheap cost.

Due to the lock requires drop bolt hole component to be mounted, a stand for it is needed. The lock senses the component in order to drop the bolt. Since we need to build that stand, we thought it is a good idea to have the electronic lock able to swing just a little bit. At the end, we got ourselves a smaller scale door, which looks 'okay' enough for the presentation. We probably need more than this to impress the moderator, though.

You can get the Sketchup file here : First Prototype




Time for part timer carpenters to go to work.


August 25, 2013

A sample RFID based electronic door lock

During the last meeting, Mr Cheong showed us the sample of the electronic door lock from the market. We were informed with some useful information on the regulation of the general door lock (before they can be marketed) here in Malaysia. The sample is a RFID based electronic door lock that also comes with the manual keyhole for the backup. It is actually a better idea to have the similar basic design for our project, albeit it comes with a higher cost.

The sample looks good, and I hope we can build something similar for our demo as well.






August 21, 2013

2nd try on demo box

So, we had ourselves a barrier : the 3D printing service can only print at most 20cm X 20cm in size. Our electronic lock itself is already about 19cm, which tells us that we can't print the whole previous design in one shot. What we can do is to print them part by part and combine them together with screws or glue.

So, I gave another shot on how it will sorta look like if we were to go that way. You can get the Sketchup file here : Second Design
































August 17, 2013

Building the prototype for demo

For obvious reason, we can't put our system on a real door during demonstration. So, we need a smaller, nice looking way of showing that our system can work.

The Kevo's demonstration uses a small box made of wood, which is actually looks nice and serve the purpose (shows how the system works) nicely. You can watch it from the video:


However, due to lack of time and resources, we have opted to build our prototype for demo by using 3D printing service. With some serious lack of creativity, I tried designing using the same idea, just to see how we can arrange our system components inside the box. This is, by no mean, the final design.







As you can see, there are pretty big empty spaces inside the box which can fitted with other components if needed (a battery, perhaps?). After asking around on 3D printing service available, I found out that the maximum of the printable size is 20cm x 20cm x 20cm volume. That is one big concern, our lock itself is already 199mm (19.9cm) in length. Trouble!

Well, not entirely true. We have the option to print part by part and gluing them together, but I'm not sure how strong can it be. The material provided are mostly ABS or PLA. ABS is stronger, the kind of material that the car's bumper are made of, but the maximum printable size is about 10cm x 10cm x 10cm due to the warping problem. We still need to design correctly (if you notice, I haven't plug in the Bluetooth dongle into the Rpi yet) and we still need to seek answers!

Here's a little conversation of me and one of the 3D printing service providers:


Hi

I'm gathering info about 3D printing service, which I need for my fyp. I was given your contact...I hope you don't mind, I'd like to ask a few questions:

1. Can I know the price rate for the service? How it depends on the size, weight of material used, complexity...any other applicable etc

2. What is the maximum printable size?

3. Which materials do you guys provide?

4. How to make order? Expected delivery period?

Thanks


The reply:

Hello

1. For 3D printing targeted towards the consumer market, the prices can range from RM5 all the way to RM1,000. For our company, Makerzone, we charge based on weight and time taken (Rm30 per hour) to print an object. The more complex the object is, the longer time it takes to print it so higher cost too. However, we do have substantial discount for students.

2. For our printers currently, our maximum printable size is 20cm x 20cm x 20cm volume. ABS is limited to 10cm x 10cm x 10cm to prevent warping.

3. We provide both ABS and PLA filaments. Honestly after selling products the past few months, the type of filaments that we use do not matter much to our consumers. We also provide post-processing for customers if they want such as polishing the printed object which will make it looks smooth and shiny, painting and chroming.

4. Customers can make orders through our online platform where we host our marketplace of products. We own three websites currently but they are all still under development and not fully functional yet. Please feel free to check them out too.

www.makerzone.net    www.makerzone.com.my    www.makerzone.sto.my 

Please do like our page below too! 
https://www.facebook.com/makerzone

It is good that you have a sketch of your design, it makes it so much easier for us to provide a quotation for you. Therefore, you could drop an email to mak@makerzone.net together with your sketchup design for him to provide validation and quotation. Expected delivery period is within 5 working days.



August 3, 2013

Python - GUI and MySQL

Since we are going to deploy the system to consumer level, the interface of our application should be intuitive, more or less, looking the same as with other typical desktop applications. And to some extent, it should resemble our Android App in the design.

We have decided to use MySQL for the database of our application. For web application, I am most certain that PHP would be the best to use. However, we would want a standalone desktop application for our system. The desktop application should be able to execute these 3 main general functions:

   1. Communicate with our MySQL database (of course!)
   2. Communicate with Rpi via bluetooth
   3. Communicate with Android App via bluetooth.

Since we're using Python on Rpi itself, perhaps it's good for me to explore on how we can use Python in this area as well, eliminating the needs for PHP. We basically know that Python bluetooth communication with Rpi and Android App is implementable. So, what I need to know for now are:

How Python can be used to write a desktop application?
What GUI tools do I need?
Can it be installed in main PC platforms (Windows, Linux, Mac)?
How Python can be used along with MySQL database?

A quick research led me to PyQt, a Python way of using cross-platform GUI toolkit, QT. From the Wiki page of PyQt, there are other GUI toolkits available for Python as well. However, we'll stick to PyQt for now due to the fact that it is cross-platform. I have implemented Qt before in my Object Oriented programming course - I wrote a Hang Man's words game and used Qt for the drawing.

Below is the introductory video on PyQt and here is a good tutorial site for PyQt : Link.





I also found out that, similar to PHP, Python can also be used with MySQL with ease. These two links below shows how it is done. I'll try these out later when I want to get started with our desktop application.

Link 1 : Connecting to MySQL with Python and PHP
Link 2 : MySQL Python tutorial

August 2, 2013

New GUI Design

I just saw this App and I thought it looks simple, clean and nice. I am a big fan of simplicity. So, I decided to draw using the similar theme for our App. I'll code this later.





GUI Design

I have not been focusing on GUI design yet as I prefer to make sure some basic functions for the App are working first. The idea is to write these different functions separately into multiple temporary Apps for testing/debugging and then I'll combine these into our final App. Even so, I did play around with the Android GUI just to get the feel of them.

The Eclipse provides basic drag and drop with their graphical tools but sometimes they could go wrong. The attributes of each view that we use can be incorrectly set up by the tools and although it looks nice on Eclipse, it isn't so on your phone. Also, we need to cater to different screen sizes, ensuring that the looks do not go wrong.

So, the best way is to study on these different layout properties first i.e. Grid Layout, Linear Layout, Relative Layout and also Android views. There is also a guidelines for the GUI design at Android Developer site. I have read a good book on this, I'll get back to attaching it here later.

So far, these are a couple of GUI designs that I played with






I think the best looking one at this moment is the one below. But I still can think of some changes that I can make on the look (Especially our faces right there, haha). If you have any suggestions, comments or samples, go ahead and let me know.

On Phone

On Galaxy Tab