Project in progress
Smart Wardrobe

Smart Wardrobe © LGPL

wardrobe which can suggest you which cloth to wear, notify you which cloth has been ignored.

  • 19,673 views
  • 8 comments
  • 50 respects

Components and supplies

Necessary tools and machines

Microsoft PC runing Windows10 with Visual studio 2015 installed
Android Phone
Raspberry Pi usb wifi dongle

Apps and online services

About this project

Overview

People nowadays like to shopping and buy clothes. However most of the clothes will be storing inside wardrobe for long time even up to several years. Especially in those countries with high humidity, clothes can easily get molded while putting it aside for long time.

Smart wardrobe will help them to manage their clothes inside wardrobe. Besides an attached screen, it can also push all data into cloud and further sync up data with mobile application. User can get suggestion on what to wear today from their phone app base on what event are there in their calendar and also the weather. The application will provide a dashboard to show that which cloth having the highest frequency of wearing and which is never touch for long time. Application can further suggest user to sell it into second hand platform or make a donation for charity.


Description

Background

Girls will tend to buy more clothes than their need and ended keep inside wardrobe for years but never wear it. While buying clothes, girls will be controlled by emotion rather than rational. They will likely buy without thinking and this ended up as a result paying more money and occupied more spaces.

Besides, living in the high humidity and warm weather country such as Singapore, new clothes can easily become moldy and smelly.

The idea integrated IoT units together with mobile app. It is not only an inventory tracking system but an established mobile personal inventory management system. With a better management of clothes, user have a better view on which clothes they wear the most frequent at the same time which is least frequent. This may help them to further decide for those least frequent clothes to either give to friend or make a donation for charity.

Value proposition and practical concept

Nowadays RFID technology is becoming more mature and common. The usage of RFID tag has become very common and even printable using a printer. Also, the RFID reader module become cheaper and cheaper at the same time better performance. This can greatly reduce the set up cost of an inventory tracking system.

The system only require one time set up and one time registration of cloth, the rest of the process will be automated. Whenever user taking or putting in a cloth, it will be tracked automatically. Once the data is collected, it can be processed further and analyzed to give user suggestion on what to wear today, which cloth has been ignored etc.

This concept simply help user understand what their need and help them to save money for buying clothes or suggest them to make a better arrangement for their unused clothes (donate, exchange or sell). As a result, small investment bring user great saving.

The whole idea

Smart wardrobe idea has been around for many years, however a low cost and practical solution is not yet available in the market. This idea is implemented using a low cost RFID reader and IoT processing units, and integration of mobile app just simply make this idea easier to use and sync up with user's daily life. It can further developed into a mobile wardrobe or a personal fashion manager.

The project will consist of 4 main components: user terminal (phone, pc, tablet), Raspberry Pi2, RFID reader, and Microsoft Azure. For first time registration, user will need to let RFID reader read the tag and a push notification will be shown inside user’s mobile phone application. User will need to key in further details about this cloths for example color, type, name, etc.

Once record is created, system will automatically track the item taking out or putting in from wardrobe. After consolidating data, a report will be generated and give user better idea of which cloth is most preferred or which is most unwanted.

The server (Raspberry pi 2 running on Windows 10Iot core) is running at your bedroom attached to an Arduino board connecting to UHF RFID module. All clothes hanging/storing inside wardrobe is attached an RFID tag on that. Whenever clothes is putting in or taking out from wardrobe, that will be tracked by RFID reader and arduino board. The sensor data will then send over to Raspberry pi 2. After processing the data, Raspberry Pi2 will then send the data to Azure SQL database (db shared with Universal app).

The Universal app system back end running on Microsoft Azure VM is able to support high traffic and allow users to register an account. Without setting up Raspberry PI and RFID, the app will act as normal digital wardrobe to help user manage their clothes on their phone/windows10 devices. The app will have the functionality to suggest user on which cloth to wear base on any scheduled event in the event planner, and also weather forecast.

Once wardrobe data is sync up with universal app, the app will further show user which cloth is having highest frequency of wearing and which one has least frequency. If there is any cloth has been ignored for more than one year, app will then suggest user to wear it, sell it or donate.

For future development, data stored inside cloud may further being processed by machine learning algorithm in order to understand user’s preference and habit then suggest user what to wear base on event (pull from device’s calendar) or weather (pull from weather forecast). The app will also suggest user to donate, exchange or sell the unwanted clothes.

Arduino Setup

I'm using Arduino UNO to collect data from JT-2850 UHF RFID reader module. The reader module using universal asynchronous Receiveer/transmiter (UART) communication. Connect TX pin on RFID module to RX pin on Arduino UNO, and connect TX pin on Arduino UNO to RX pin on RFID module as the schematic below:

Before the module is connected, Arduino UNO need to connect to your PC and upload the Arduino Code attached here for Arduino UNO to keep sending read command over to RFID module, at the same time write the data returned back to USB port.

Once the setup on Arduino UNO is done, the next thing is to make Raspberry Pi2 able to read data transmitted from Arduino UNO and make further processing.


Raspberry Pi setup:- The Background App running at Windows IoT core

I deployed this background app into Raspberry Pi2 running Windows IoT core, the source code can be found under my GitHub Repository (under SmartWardrobeBackgroundApp folder).

Take note of capability setting under the Package.appxmanifest file as the app need to access USB port. The capability setting should include this:

<Capabilities> <Capability Name="internetClient" /> <DeviceCapability Name="serialcommunication"> <Device Id="any"> <Function Type="name:serialPort"/> </Device> </DeviceCapability> </Capabilities>

Logic behind:

The background app will first look for Arduino UNO, make the connection and start receiving data from Arduino UNO. Once an array of RFID data is received, the background app will compare the RFID list with existing RFIDs stored under Azure SQL database through web API. If the RFID list length is same as RFID list stored under Azure SQL database, It means that all the clothes are stored back to wardrobe. The Web API functions will then look for all clothes with status = "-1" (took out before) and update the "1"(put back). At the same time, a new activity record will be added into SQL database to store the rfid, status, and time.

If RFID list in database is longer than RFID list read, that means a cloth has been taken out. The cloth record will be updated with status "-1" and frequency +1, at the same time an activity record with rfid, status, and time will be added.

If RFID list read by UHF RFID module is longer than existing RFID list in database, that means a new cloth is going to register into system. The Web API will then create a new record with the new RFID tag value and time. At the same time send push notification to mobile application to notify user to complete the entry, by inserting image, cloth name, color and type. Once user finished the entry, the new cloth will be traced by the system and record the wearing frequency.


Web API server set up and Software Development

I'm using 3 services provided by Microsoft Azure. The web API server as a Asp.NET web application is hosted under smartwardrobe.azurewebsites.net. The clothes details and reader data are stored inside Azure SQL database server: smartwardrobe1.database.windows.net. While the third services I used is the notification hub under service bus. The notification hub may help me to send push notification to mobile app or Windows Universal app. The notification hub service is running at: https://smartwardrobe.servicebus.windows.net/notification. For notification hub setup you may refer here: https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-android-get-started/

The Azure environment setup:

The web api together with database setup is deployed using Visual studio 2015, it is a MVC base RESTful API. But frankly, I've failed to configure PUT and DELETE method on Azure Web (sorry for my poor knowledge, I'm not able to solve this by submission deadline, azure web service default setting is not allow those method and while i tried to call, it returned "HTTP Error 405 method not allowed"). The RESTful API currently support GET and POST method only.

The project under smartwardrobe folder in github repository https://github.com/seeyouu87/smartwardrobe is using MVC with Entity Framework. So if you have downloaded the code, remember to run Enable-Migrations and Add-Migration command in your nuget console before you try to run in local debug mode. You may follow this guide: https://msdn.microsoft.com/en-sg/data/jj591621.aspx

After tested the code, if you feel like deploy it onto azure web API server, you may follow this tutorial http://docs.asp.net/en/latest/tutorials/publish-to-azure-webapp-using-vs.html and make sure you checked the "Execute Code First migrations (run on application start)" before you clicked the published button:

After you have clicked "Publish" button, Visual Studio 2015 will launch your default browser once the website is published. And you will then try to make a simple GET call (/api/clothes) to see result. It should look similar to the following screen shot:

Mobile APP development

The mobile application serve as a client terminal in order for user to update their cloth detail, get suggestion, manage their clothes inside wardrobe. This project currently only Android application is available. Mobile app for other platform is in progress.

The workflow on mobile app started from push notification which notify user regarding the new cloth is added. User will need to click on the notification and continue on app.

User is required to fill in the details of the cloth from mobile app, once completed, the cloth will be listed on dashboard with frequency of wearing showing on top right corner.


Here is the flow chart of creating new cloth

Upon created a new cloth, system will monitor the frequency of wearing of new cloth, it will then send a random notification for user to take care on those clothes have been ignored for long time.

This android mobile app is currently in progress, there are more features will be coming in due course.


You may refer to my GitHub repository if you're interested to find out more https://github.com/seeyouu87/smartwardrobe


REFERENCE LINKS:

  1. Step by step guide to setup Windows10 Iot Core:- http://ms-iot.github.io/content/en-US/GetStarted.htm
  2. Setting up Visual Studio 2015 on your PC:- http://ms-iot.github.io/content/en-US/win10/SetupPCRPI.htm
  3. Step by step instruction to setup Windows10 IoT Core on Raspberry Pi2:- http://ms-iot.github.io/content/en-US/win10/SetupRPI.htm
  4. How to develop IoT application (Blinky sample):- http://ms-iot.github.io/content/en-US/win10/samples/Blinky.htm
  5. Windows IoT serial sample:- http://ms-iot.github.io/content/en-US/win10/samples/SerialSample.htm
  6. Ms-IoT GitHub repositories:- https://github.com/ms-iot
  7. Windows on GitHub:- http://microsoft.github.io/windows/
  8. Arduino Software Serial Example(using UART) :- https://www.arduino.cc/en/Tutorial/SoftwareSerialExample
  9. SparkFun serial communication tutorial: - https://learn.sparkfun.com/tutorials/serial-communication
  10. Get started with Azure Notification Hub:- https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-android-get-started/
  11. Add push notifications to your Mobile Services app:-

    https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-push/

  12. Code First Migrations:- https://msdn.microsoft.com/en-sg/data/jj591621.aspx
  13. Publish to an Azure Web App using Visual Studio:- http://docs.asp.net/en/latest/tutorials/publish-to-azure-webapp-using-vs.html
  14. Publish the App to Azure Azure App Service:- http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-10

Code

RFID module codeC/C++
The arduino code to send read command over to RFID module, it will then return the RFID tag data back to serial port.
/*
  read command will be sent over to RFID module
once tag is read, it will return back to serial port

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() { // run over and over
  if (mySerial.available()) {
    //send the read command over to RFID module
    byte message[] = {0xA0,0x06,0x80,0x00,0x01,0x02,0x01,0xD6};
    mySerial.write(message, sizeof(message));
    //send the data back to serial
    if(Serial.available())
      Serial.write(mySerial.read());
  }
}
BackgroundApp IoT codeC#
the background app task running in raspberry pi2
using System;
using Windows.ApplicationModel.Background;
using System.Threading.Tasks;
using System.Threading;
using Windows.Storage.Streams;
using Windows.Devices.Enumeration;
using Windows.Devices.SerialCommunication;
using System.Collections.ObjectModel;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace SmartWardrobeBackgroundApp
{
    public sealed class StartupTask : IBackgroundTask
    {
        private SerialDevice serialPort = null;
        DataReader dataReaderObject = null;

        private CancellationTokenSource ReadCancellationTokenSource;
        private string rfidTags
        {
            get; set;
        }

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            //run core function to read and send tags over to Web API
            while(true){
                read_RFID();
            }
        }
 
        private async void read_RFID()
        {
            try
            {
                string aqs = SerialDevice.GetDeviceSelector();
                var dis = await DeviceInformation.FindAllAsync(aqs);
                foreach(DeviceInformation info in dis) {
                    if (info.Name == "Arduino Uno")
                    {
                        serialPort = await SerialDevice.FromIdAsync(info.Id);
                        // Configure serial settings
                        serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                        serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
                        serialPort.BaudRate = 9600;
                        serialPort.Parity = SerialParity.None;
                        serialPort.StopBits = SerialStopBitCount.One;
                        serialPort.DataBits = 8;

                        // Create cancellation token object to close I/O operations when closing the device
                        ReadCancellationTokenSource = new CancellationTokenSource();
                        await ReadAsync(ReadCancellationTokenSource.Token);
                    }
                    
                }
                
            }
            catch
            {
                //don't think need to write error log at the moment
            }
        }

        private async Task ReadAsync(CancellationToken cancellationToken)
        {
            try
            {
                Task<UInt32> loadAsyncTask;

                uint ReadBufferLength = 1024;

                // If task cancellation was requested, comply
                cancellationToken.ThrowIfCancellationRequested();

                // Set InputStreamOptions to complete the asynchronous read operation when one or more bytes is available
                dataReaderObject.InputStreamOptions = InputStreamOptions.Partial;

                // Create a task object to wait for data on the serialPort.InputStream
                loadAsyncTask = dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cancellationToken);

                // Launch the task and wait
                UInt32 bytesRead = await loadAsyncTask;

                if (bytesRead > 0)
                {
                    //get the RFID tags returned by Arduino + RFID module
                    this.rfidTags = dataReaderObject.ReadString(bytesRead);
                    //run the send RFID function:
                    sendRFID(this.rfidTags);
                }

            }
            catch
            {
                //don't think need to write error log at the moment
            }
        }

        /// <summary>
        /// CancelReadTask:
        /// - Uses the ReadCancellationTokenSource to cancel read operations
        /// </summary>
        private void CancelReadTask()
        {
            if (ReadCancellationTokenSource != null)
            {
                if (!ReadCancellationTokenSource.IsCancellationRequested)
                {
                    ReadCancellationTokenSource.Cancel();
                }
            }
        }

        /// <summary>
        /// Process RFID data and send over to web api
        /// </summary>
        private void sendRFID(string myrfid)
        {
            try
            {

                List<string> rfidList = JsonConvert.DeserializeObject<List<string>>(myrfid);
                //get all clothes records in database:
                HttpWebRequest getrequest = (HttpWebRequest)HttpWebRequest.Create("http://smartwardrobe.azurewebsites.net/api/clothes");

                getrequest.Method = "GET";
                getrequest.ContentType = "application/json;charset=utf-8";

                getrequest.BeginGetResponse((x) =>
                {
                    HttpWebResponse response = (HttpWebResponse)getrequest.EndGetResponse(x);
                    Stream mystream = response.GetResponseStream();
                    StreamReader sr = new StreamReader(mystream);
                    string returnval = sr.ReadToEnd();
                    List<string> existingRFIDList = JsonConvert.DeserializeObject<List<string>>(returnval);

                    if (existingRFIDList.Count > rfidList.Count)
                    {
                        //cloth has been taken out
                        //find the missing rfid:
                        foreach (string existRFID in existingRFIDList)
                        {
                            if (rfidList.Contains(existRFID))
                            {
                                continue;
                            }
                            else
                            {
                                //add action
                                string actionbody = JsonConvert.SerializeObject(new ActionObj()
                                {
                                    rfid = existRFID,
                                    status = "1"
                                });
                                HttpWebRequest actionrequest = (HttpWebRequest)HttpWebRequest.Create("http://smartwardrobe.azurewebsites.net/api/actions");

                                actionrequest.Method = "POST";
                                actionrequest.ContentType = "application/json;charset=utf-8";

                                actionrequest.BeginGetRequestStream((ar) =>
                                {
                                    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                    byte[] bytes = encoding.GetBytes(actionbody);
                                    Stream arStream = actionrequest.EndGetRequestStream(ar);
                                    arStream.Write(bytes, 0, bytes.Length);
                                    actionrequest.BeginGetResponse((arRes) =>
                                    {
                                        HttpWebResponse actionresponse = (HttpWebResponse)actionrequest.EndGetResponse(arRes);

                                    }, actionrequest);
                                }, actionrequest);
                            }
                        }
                    }
                    else if (existingRFIDList.Count < rfidList.Count)
                    {
                        //new clt is added:
                        string clothbody = JsonConvert.SerializeObject(new ClothObj()
                        {
                            rfid = myrfid,
                            status = "0",
                            img = new byte[] { },
                            name = "test",
                            type = "dress",
                            color = "yellow",
                            createdAt = DateTime.Now,
                            lastUpdatedAt = DateTime.Now,
                            frequency = 0
                        });

                        HttpWebRequest clothrequest = (HttpWebRequest)HttpWebRequest.Create("http://smartwardrobe.azurewebsites.net/api/clothes/" + myrfid);

                        clothrequest.Method = "POST";
                        clothrequest.ContentType = "application/json;charset=utf-8";

                        clothrequest.BeginGetRequestStream((a) =>
                        {

                            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();


                            byte[] bytes = encoding.GetBytes(clothbody);

                            Stream requestStream = clothrequest.EndGetRequestStream(a);
                            // Send the data.
                            requestStream.Write(bytes, 0, bytes.Length);
                        }, clothrequest);

                        //after sending data, get the response
                        clothrequest.BeginGetResponse((cr) =>
                        {
                            HttpWebResponse clothresponse = (HttpWebResponse)clothrequest.EndGetResponse(cr);

                        }, null);
                    }
                    else
                    {
                        //all clothes are back inside wardrobe, update all status:
                        //add action
                        string actionbody = JsonConvert.SerializeObject(new ActionObj()
                        {
                            rfid = "",
                            status = "1"
                        });
                        HttpWebRequest actionrequest = (HttpWebRequest)HttpWebRequest.Create("http://smartwardrobe.azurewebsites.net/api/actions");

                        actionrequest.Method = "POST";
                        actionrequest.ContentType = "application/json;charset=utf-8";

                        actionrequest.BeginGetRequestStream((ar) =>
                        {
                            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                            byte[] bytes = encoding.GetBytes(actionbody);
                            Stream arStream = actionrequest.EndGetRequestStream(ar);
                            arStream.Write(bytes, 0, bytes.Length);
                            actionrequest.BeginGetResponse((arRes) =>
                            {
                                HttpWebResponse actionresponse = (HttpWebResponse)actionrequest.EndGetResponse(arRes);

                            }, actionrequest);
                        }, actionrequest);
                    }

                }, null);
            }
            catch {
                //have no idea what to catch, but this process cannot fail and halt the background app.
            }
        }

        private class ActionObj
        {
            public int id;
            public string status = "0";
            public string rfid;
            public DateTime createdAt = DateTime.Now;
        }


        //Generic object for Clothes
        private class ClothObj
        {
            public int id;
            public string status = "0";
            public string rfid;
            public Byte[] img;
            public string name;
            public string type;
            public string color;
            public DateTime createdAt = DateTime.Now;

            public DateTime lastUpdatedAt = DateTime.Now;

            public int frequency = 0;
        }

    }
}
Smart Wardrobe
This repo will inlcude server side api code, Android app source code and Windows10 IoT Universal App source code to be deployed and run on Raspberry Pi2

Custom parts and enclosures

UHF RFID reader schematic
UHF RFID reader module. it is used for reading RFID tag.
uhf_reader_jt2850.svg
UHF RFID reader module PCB file
UHF RFID reader module. it is used for reading RFID tag
uhf_reader_jt2850.svg
UHF RFID reader module breadboard
UHF RFID reader module. it is used for reading RFID tag
uhf_reader_jt2850.svg

Schematics

Smart Wardrobe Schematic
The connection for Arduino to UHF RFID module. Please check the fritzing repository below for more info. http://fritzing.org/projects/smart-wardrobe
Smartwardrobe bb
Smart Wardrobe
sketch is uploaded to fritzing

Comments

Similar projects you might like

Where is my thing?

Project tutorial by Tan See Youu

  • 11,129 views
  • 8 comments
  • 26 respects

Home Smart Home

Project tutorial by Syed Sanoor

  • 68,539 views
  • 10 comments
  • 193 respects

Windows IOT - Automate your power outlets

Project tutorial by Syed Sanoor

  • 22,136 views
  • 13 comments
  • 48 respects

MannyBot365

Project showcase by 3 developers

  • 2,939 views
  • 0 comments
  • 26 respects

RF BASED SMART HOME AUTOMATION SYSTEM

by Dennis Mwanza

  • 28,739 views
  • 4 comments
  • 45 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 297,267 views
  • 98 comments
  • 706 respects
Add projectSign up / Login