MyThings 2 Android App (IoT)

MyThings App

This app is to store a list of own things, location and bar code scanner of items. The list will be saved on the device locally and it can be synchronized over Rest Api both ways in cloud.

Introduction

Based on my previous app MyThings App v.1 I have further developed on it and built MyThings app version 2.

It is basically containing the minimum of following requirement plus some extra fancy creative and technical features.

1. The minimum requirement is:

  • Local database using SQLlite.
  • Create/Delete/View things from database.
  • Rest Api Synchronization
  • Ability of scanning bar-codes for new created things.
  • Search for thing based on scanning bar-code data in database.

2. Smart fancy features

  • Force update database by swiping on My Things fragment.
  • When screen get rotated the fields and searching result will keep remembered.
  • Icon added to the tab layout
  • When press overview button on phone hardware button it changes the tabs with logo and name of MyThings App.
  • Refreshing list view on fragment transparently without using intent (This was problem I have had in my previous assignment, it is fixed now)

3. Futuristic features

  • Building own Restful API to MyThings to sync both ways, it is build half way right now and because of time running out, it is put to side.
  • Adding Camera/Images of things to the list view.

Backend structure

MyThings App v.2 has the similar structure as previously, but it has got improvement on naming and variable conventions, Class are well structured, and in addition it has got google zxing barcode reading class library.

In my opinion the best documentation for coding is to make self-explaining code and structure. That makes it easier for team to understand. This is the case also in MyThings App.

When app get fired, the main activity launcher calls ThingsMainActivity class. Which is the skeleton of the app.

onCreate method must call super class implementation of this method which is part of life cycle, so in the beginning of onCreate I call CreateDummyThings.dummyCreate(this) method in class, it creates 3 dummy book in our local database. Off course we are able to create or delete more if we want so.

1.1.    Local database

Our database structure under Database folder contains 3 class inspired directly from the Android Programming 2nd Edition book that we use in our course. I could have also used some example from Android Source site or Internet in general, but I found the examples are nice and well presented. Under Entity I have a Thing class that has the definitions of fields.

I have also a ThingLab class inspired from the book as well. It is the bind logic between database calls and the controller.

1.2.   CREATING, DELETE AND VIEW THINGS

Our ThingLab class contains the required method required to get, add and delete things from database.

Our Adapter ThingListAdapter showing things in list view by calling getThings method as instance of ThingLab

public List<Thing> getThings() {
   List<Thing> Things = new ArrayList<>();
   ThingsCursorWrapper cursor = queryThings(null, null);
   cursor.moveToFirst();
   while (!cursor.isAfterLast()) {
       Things.add(cursor.getThing());
       cursor.moveToNext();
   }
   cursor.close();
   return Things;
}

The method simply iterates our database and add all things table rows in our ArrayList elements, and return it as List that we can use to view it on our list view.

In case we want to search by barcode to find specific thing we simply create new method similar to getThings call it getThingsBarcode (String input) and the method works in the same way, the only difference is we add query inside the method like:

ThingsCursorWrapper cursor = queryThings(
    MyThingsTable.Cols.BARCODE + " = ?",
    new String[]{input}
);

And we will get a list of things that has the same barcode.

This is to demonstrate the concept, else it is possible to search everything and get single results or list (multiple) of results.

Deleting things require us to specify which element to delete, so our code snippet will look like this, it is similar to search query but here we ask for deleting the finding results. The method delete single results, as is right now.

public Thing deleteThing(UUID id) {
    ThingsCursorWrapper cursor = queryThings(
    MyThingsTable.Cols.UUID + " = ?",
    new String[]{id.toString()}
);
 
try {
        if (cursor.getCount() == 0) {
        return null;
    }
 
    mDatabase.delete(MyThingsTable.NAME, MyThingsTable.Cols.UUID + " = ?", new String[]{id.toString()});
 
    cursor.moveToFirst();

    return cursor.getThing();
    } finally {
        cursor.close();
    }
}

Finally creating new things at the other hand requires us to pass data like what and where information as minimum and barcode is optional. So for example our dummy thing creating method called doCreate that pass the mentioned data to our addThing method and it will create those data in our table.

doCreate method under CreateDummyThing class under Util folder

doCreate(Activity activity, String what, String where, String barcode) {
    mThing = new Thing(what, where, barcode);
    ThingLab.get(activity).addThing(mThing);
}

addThing method under ThingLab class

addThing(Thing c) {
    ContentValues values = getContentValues(c);
    mDatabase.insert(MyThingsTable.NAME, null, values);
}

 

You can download source code: https://github.com/maythamfahmi/mythings-app

Computer vision project

I have worked with 2 other students on different computer vision project using OpenCV.

A part of the project was about pupil and glint detection for eye tracking, here is a picture of the process in OpenCV.

Eye Pupil Process
The other part was about person tracking from side view and draw a tracking map from top view:

Homography Person Tracking

Top view of Person Tracking

This is a top view of IT University in Copenhagen

And one of the last parts was to create a primitive Augmented Reality concept as seen in the image below:

augmented reality

Thank to

  • Dan Witzner Hansen (Associate Professor), IT University of Copenhagen
  • Zaheer Ahmed
  • Fabricio Narcizo

Team mates

  • Gediminas Kučas
  • Alexandru Gheorghiasa

GuideBelt Project (IoT)

GuideBelt

We see every day new technologies coming out to market but a few of those technologies are focused for people with special needs.

We have just finalized a research project called GuideBelt. It is simply a Bluetooth-based indoor navigation system for the visually impaired.bluetooth based indoor navigation system for the visually impaired

The GuideBelt, which is the product of this research, is such a solution that takes advantage of cheap Bluetooth beacons attached to places/objects of interest within an indoor space.

The implementation of the GuideBelt that has been the focus of this work is an early prototype, which uses phones to simulate the Bluetooth receivers (coupled with a vibration module). This was to allow us to focus on development of the algorithm rather than electronics. Therefore, the direction of this research is towards the implementation of the system with the actual technology necessary meaning with assembled electronic components (including Bluetooth modules and vibrators).

We have also wrote a research paper of our experiment that contains important details of the project.

We have made a little image site to present some images of the development:

https://dev.itbackyard.dk/guidebelt

We have also produced a video of the experiment:

Research and Development

  • Abdulrashid Mohammed
  • Maytham Fahmi
  • Tanase Comboeanu

Feedback for development
Thomas Pederson, Shahram Jalaliniya, Alexandre Alapetite

Technical support
Sebastian Büttrich

SPECIAL THANKS
Birgit Christensen and all participants

How to protect image from public view in Laravel 5?

It is possible to protect images from public view in Laravel 5.x folder.

  • Create images folder under storage folder (I have chosen storage folder because it has write permission already that I can use when I upload images to it) in Laravel like storage/app/images.
  • Move the images you want to protect from public folder to the new created images folder. You could also chose other location to create images folder but not inside the public folder, but with in Laravel folder structure but still a logical location example not inside controller folder. Next you need to create a route and image controller.

Create Route

Route::get('images/users/{user_id}/{slug}', [
     'as'         => 'images.show',
     'uses'       => 'ImagesController@show',
     'middleware' => 'auth',
]);

The route will forward all image request access to Authentication page if person is not logged in.

Create ImagesController

class ImagesController extends Controller {

    public function show($user_id, $slug)
    {
        $storagePath = storage_path('app/images/users/' . $user_id . '/' . $slug);
        return Image::make($storagePath)->response();
    }
}

You can modify your storage path and file/folder structure as you wish to fit your requirement, this is just to demonstrate how I did it and how it works.

You can also added condition to show the images only for specific members in the controller.

It is also possible to hash the file name with file name, time stamp and other variables in addition.


Addition: some asked if this method can be used as alternative to public folder upload, YES it is possible but it is not recommended practice as explained in this answer. So the same method can be also used to upload images in storage path even if you do not intend to protect them, just follow the same process but remove 'middleware' => 'auth',. That way you won’t give 777 permission in your public folder and still have a safe uploading environment. The same mentioned answer also explain how to use this method with out authentication in case some one would use it or giving alternative solution as well.

Augmented Reality for doctors (IoT)

Hospital Journal

A project that enables doctors to see patience hospital journal virtually through augment reality, at the same time it is possible to navigate thought the journal with hand gesture.

Code only accessible for group members: https://bitbucket.org/maytham/hospital-journal

Read paper PDF: Hospital journal

 

Context Awareness Project (IoT)

Context awareness

In this paper we describe the concept, development and reflection for Pervasive Computing course (Spring 2015) at IT University of Copenhagen
where we built a context-aware mobile phone utilizing an iBeacon infrastructure.

Code available for group members

PDF download: ITU Contextphone platform

Full guideline to make VHOST (Virtual Host) on XAMPP/WAMP

Note: To start with, the only difference for this guideline, between XAMPP and WAMP or other Apache packages for Windows, is question where those packages are installed on your computer.

Introduction: vhost (virtual host) is a great solution if you intend to develop many independent project in php and keep them isolated from each others, like:

  • Project 1 is based on php and has local url address php.localhost
  • Project 2 is a Laravel project with url laravel.localhost
  • Project 3 is a Codeigniter with url codeigniter.locathost
  • Project 4 is a WordPress with url wordpress.locathost

You are expected to have installed the latest version of XAMPP/WAMP. Btw, in my case, I have only installed Apache and MySQL.

*Note: By default, most web servers will uses port 80 as default port, in some situation if you have another web server installed like (Microsoft IIS), it uses port 80 as well OR in other cases SKYPE does also some times use port 80 like it is the case for some in Windows 8/10 for some users, in that case you can do two thing’s

  • Change your Apache port to port 8080, 8081 etc. or some other free ports (note: 8080 can some times also give some problems)
  • OR Change your others software/IIS port and keep Apache to default port 80 in case of Skype, just kill the Skype app and restart it after installing Apache on port 80, Skype will automatically get new port.

I have chosen to change my Apache to port 8080.

Note:
– For next section, we need to use text editor like notepad or regular IDE. I used sublime text editor.
– If you keep Apache to default port 80, skip this part and move on to Virtual hosts

Change XAMPP/WAMP port (only if necessary)
if left default, then jump to Setting virtual host

Step 1. Edit httpd.conf

Click on Config -> Apache (httpd.conf)
Or you find the file here C:XAMPPapacheconfhttpd.conf, C:XAMPPapache2confhttpd.conf, C:Bitnamiwampstackapacheconfhttpd.conf or C:Bitnamiwampstackapache2confhttpd.conf or similar location.

Change the line with

Listen 80

To 8080 or other, free ports.

Listen 8080

While we have httpd.conf file open we need to ensure that httpd-vhosts.conf is included:
Include conf/extra/httpd-vhosts.conf

Virtual hosts

Note: By default server documents are locate on C:XAMPPhtdocs or C:Bitnamiwampstackapache2htdocs that’s fine if you have only one project or many small test files. However, if you need to develop many projects then it suggested separating them by virtual host, as mentioned earlier.

Step 2. Setting Virtual host

  1. Create a folder for your projects; I have create one in c:vhost you can call it projects etc.
  2. In c:vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you (c:vhostproject1)
  3. Open httpd-vhosts.conf file C:XAMPPapacheconfextrahttpd-vhosts.conf Add following code in line depending on how many vhost you want to create:
<Directory C:/vhost>
    AllowOverride All
    Require all granted
</Directory>

#this is the default address of XAMPP    
<VirtualHost *:8080>
    DocumentRoot "C:/XAMPP/htdocs/"
    ServerName localhost
</VirtualHost>

#this is the first vhost address in XAMPP
<VirtualHost *:8080>
    DocumentRoot "C:/vhost/project1/"
    ServerName php.localhost
    SetEnv NS_ENV variable_value
</VirtualHost>

#this is the second vhost address in XAMPP for project like Laravel
<VirtualHost *:8080>
    DocumentRoot "C:/vhost/Laravel-Blog/public"
    ServerName laravel.localhost
</VirtualHost>

etc

Note: If you work on Laravel projects you can create unlimited Laravel projects as well as other frameworks like codeigniter, Yii, etc., the point is to
have your Laravel project/s on c:vhostlaravel1,
c:vhostlaravel2 etc and make c:vhostlaravel1public as
DocumentRoot etc as showed before. Each Laravel project will have own
VirtualHost URL.

Save and close the file

Some additional information and notes:

  • If port is remain default 80 then the URL address will be localhost
  • If port is remain default 80 then the the VirtualHost tag should be changed to <VirtualHost *:80>
  • If port is changed to 8080, the URL address will be localhost:8080
  • And the vhost URL address could look like this project1.localhost:8080 etc
  • You can add unlimited projects and virtual host like this way.

We are not ready yet, read more.

Step 3. Edit Windows Host file

  1. Stop Apache and MySQL services from XAMPP/WAMP.
  2. Open hosts file in C:windowssystem32driversetc
    you need Administrator privilege to edit the file.
    I suggest to edit the file directly with Sublime text editor.
  3. Add 127.0.0.1 project1.localhost at the end of the file, Save and close the file.
127.0.0.1       localhost
127.0.0.1       php.localhost
127.0.0.1       laravel.localhost
127.0.0.1       codeigniter.localhost
127.0.0.1       wordpress.localhost
127.0.0.1       laravel2.localhost
etc. those are just examples

save the file

Final Step.
Start/Re-start your Apache and MySQL again.


Addition (Suggestion)

Note: You might need to delete your cache in your browser and also it
is good to disable php cache under development process.

Open file php.ini under php folder in your XAMPP or WAMP folder and
change opcache.enable to 0

[opcache]
zend_extension=php_opcache.dll
; Determines if Zend OPCache is enabled
opcache.enable=0

Addition (Alternative solution)

It is possible to deploy temporary Virtual Server with out necessarily configuring XAMPP/WAMP Virtual Host, start CMD console and run following php command:

php -S localhost:8001 -t c:vhostLaravel-Projectpublic
  • Port 8001 can be change to any available port number and be sure nor conflicting with other software ports.
  • c:vhostLaravel... path should be changed to what ever your project path.
  • It is possible to start multiple servers but should have different port numbers.

In your browser you need only to right

https://localhost:8001/

Note on 403 Access forbidden error

If you get a 403 Access forbidden error when you browse to your site, you may need to add this to your httpd.conf file:

<Directory path_to_dir>
    AllowOverride none
    Require all granted
</Directory>