Sunday, January 31, 2016

Bundy Clock App: Mila

We are using a finger print scanner coupled with an RF card for good measure in keeping track of our employees' attendance.  Their time records are downloaded from the scanners using the devices' software.  The file is an easy to use spreadsheet that can be processed for our purposes by a small program.

The problem with this set up is the RF card, which some employees don't bother to return, when they don't bother showing up to work anymore.  Each RF card costs P20, and the scrooge in me throws a tantrum everytime an employee decides to go AWOL with the card.  The scrooge feels worse for the unreturned card than the employee not reporting to work.  Weird.

Regular employees can decide to just go AWOL like they were just cancelling a scheduled dinner, so much so new, probationary employees, who virtually have no commitment whatsoever to the company just yet, since they're still on probation.  So it has become my practice not to use the finger scanning device for their attendance just yet as well, because the RF cards are my precious.

Previous practice was they used a time card for their records.  However, there was a time we had 20 new employees.  And encoding the times for 20 people is not pleasant work for the person typing all that, the same person who has other things to do.

So I wrote Mila, named after my MBA economics professor.

Mila is a bundy clock Android app that reads an employee's NFC, and records his/her time in a CSV file.  The app also includes a registration function, which writes employee information in an NFC card for identification when the card is tapped on to the device.

Everyday, I just download the CSV file to know if a new employee is present or absent.  At the end of the week, the attendance file is passed to a program that computes the payroll.  The staff is freed from manual transfer of time card data to the computer, which enables the staff to do other value added activities.

And to solve the problem of employees not giving back the card in case they go AWOL, I don't let them bring the NFC cards home.  Just like time cards, the NFC cards are left on the desk of the security guard, so they only use it when they need it.  And the phone that has Mila in it is managed by the guard, who personally taps the NFC on the phone to ensure that the NFC card is indeed assigned to the person.

To register an NFC card to an employee, tap the "Add Contact" icon on the upper right.

The "Add Employee" screen appears.  Fill up the information required, and tap the NFC card close to the device.  A message will appear when registration is successful.



To record time in or out, tap the button (Clock In, Clock Out) of the applicable time status.  Then tap the NFC card close to the device.  The employee record appears on the main screen, and his/her time record is written to the CSV file log.csv.

log.csv can be viewed at internal memory's 3_mila directory.


Get it on Google Play

Tuesday, January 26, 2016

Automated Weight Recording: Timbang Instructions

Before using Timbang, two files are required:

1.  scrap.csv This is a CSV file that contains the list of items to be weighed.  Each line of the file must contain the item name:

<item_name>

For example, a business that is involved with meat products may contain the following lines in its scrap.csv file:

beef brisket
beef rib
beef short loin
beef sirloin
beef tenderloin
pork bacon
pork belly
pork chops

2.  supplier.csv This is a CSV file that contains the supplier list.  Each line of the file must contain the following:

<supplier_name>

Again, as an example of a business involved in meat products, the file may contain the following lines:

Century
CDO
King Sue
Purefoods

Open Timbang for the first time creates a directory "1_weightrecorder" in the device’s internal storage.

Copy the CSV files in 1_weightrecorder.

Tapping the three vertical dots on the upper right corner of the screen reveals the menu.  Tap "Import Supplier File", and "Import Scrap File".  The CSV files are loaded into the app's internal storage.  After doing this, you may delete the CSV files.

As a company goes along, suppliers, and items may change.  You may edit suppliers by opening the menu, and tapping "Edit Supplier".  A list of supplier names appears.  To add a supplier, tap the plus icon on the upper right of the screen, and the "Add Supplier" dialog appears.  Fill up the name fields, and press "OK".


To change a supplier's name, long press the supplier entry in the "Edit Supplier" screen to show a context menu with "Edit", and "Delete".  Tap "Edit" to show the "Edit Supplier" dialog, which is similar to "Add Supplier" dialog.  Edit the name, and press "OK".  The supplier entry is updated.


You may also delete suppliers by long pressing the supplier entry, and selecting "Delete".

Editing item entries is similar to editing suppliers.  You may start editing items by selecting "Edit Scrap" at the menu of the main screen, and following similar steps as editing suppliers.

Select the connection type by tapping the menu icon, and selecting "Connection Mode".  A dialog box will appear prompting you to select how you want to connect to the weighing scale.


Now you're ready to receive weight from the scale.  Connect the cables:

1.  Connect the null modem to the scale's RS232 port.
2.  Connect the RS232 to USB cable to the modem.
3.  Connect the USB OTG to the RS232 to USB cable.
4.  Finally, connect the USB OTG to the phone.
5.  Press "Connect" (the upload button beside the menu icon's 3 vertical dots).  The app is now connected to the scale.

or

You may also connect via Bluetooth by:

1.  Pair the bluetooth device in the device's bluetooth settings.
2.  Press "Connect" (the upload button beside the menu icon's 3 vertical dots).
3.  Choose the bluetooth device (in our case it's an RS232 to bluetooth dongle).
4.  A message will appear that the connection is successful.

Choose the supplier.  You may do this my tapping on the supplier name.  A generic "Select Item" dialog box appears where you can select the supplier from a list.  You may do the same when choosing the item.
 

Put in the item to be weighed, and wait until the weight stabilizes, then press the "Print M+" button on the scale.  The item name along with its weight appears on the app's main screen.


The item, and weight is also recorded in a CSV file named after the time "Print M+" is first pressed, and the supplier's name.

yyyymmdd_hhmmss_<supplier_name>.csv

This CSV file is located at 1_weightrecorder.



If you need to delete the item, long press the item entry for the context menu to appear.  Select "Delete", and the item will be removed from the main screen, as well as from the CSV file.


Sometimes, you have to return items back to suppliers, and thus the weight should be negative.  You may do this by choosing "Set to Backload" in the menu.  Notice that pork bacon's weight is negative.


In our line of business, which is recycling of plastic, suppliers bring neat rolls of plastic.  Since we only accept plastic, we deduct the weight of the spools these rolls, much like the core of a toilet paper.  However, we don't necessarily weigh them one by one.  To deduct the weigh of the core, choose "Tare Spool" from the main menu, and a dialog box asking for the spool weight appears.  Input the weight, and this comes out as a deductible weight.


After the weighing session is through, select "Close Connection" from the main menu to terminate the connection between the app, and the weighing scale.

As for the weighing scale, the FIO3 indicator's serial port setting (F16), should be set as such:
BAUD:  9600
PARITY:  none
BITS:  8
AC:  off
CH:  off
ST:  yes
FR:  20d
LAB:  2
COPY:  1

The serial bluetooth dongle should be set to DCE (IF).

Automated Weight Recording: Timbang

Being involved in recycling, we receive scrap frequently.  Suppliers bring scrap in the plant aboard their own trucks, the largest of which is a 6 wheeler.  Scrap are usually packaged in bales for ease in stacking inside the vans.  Another advantage of packaging in bales is that it is makes weighing faster on our pallet scale, since more than one bale can be stacked vertically on the scale's platform.  However, not all suppliers neatly organise their scrap in bales.  Weights were recorded by the receiver in a materials receiving report, which was where we write the type of scrap, and its corresponding weight.  We do this until all the contents of the supplier's truck has been weighed.  After finishing the truck's entire contents, this report was brought to the office, where the handwritten report was encoded, weights summed, and payment issued to the supplier per kilo of scrap.

Unloading time depends on how much the supplier brought, so it's variable.  Recording weights was quite fast, since all the receiver needed to do was to write down the correct weight under the proper scrap category.  The real latency occurred at the office.  Since the report was handwritten, it needed to be encoded in a spreadsheet.  If the supplier brought the scrap in bales, only a few weights would be recorded.  The weights would be few, but big in value.  But if the supplier is not organised this way, there would be many weights in the report, since loose scrap cannot be weighed all at once.  Weight records of loose scrap tend to be many, and small in value.  For example, say the total contents of a supplier's truck is 100 kg.  If it's organised in bales of 50 kg. each, then the report will only have 2 weights needed to be encoded.  But if the supplier did not organise the contents, so they're loose, only a few kilos can be weighed at a time, because the mound of scrap would cave.  Let's say each weighing is around 5 kg., that would be 20 weights that need to be encoded.  And that takes time.

Another problem we encountered with the handwritten method is unpredictable handwriting.  We have 3 receivers, who each has his own handwriting quirks the encoder has to decipher.  There were times a four at the report got encoded as a nine.  That situation would not be in favor for us, since we would have to pay the supplier more than what we got.  The opposite can also happen leaving the supplier shortchanged.  One thing is definite though: we want the correct weights to be recorded for us to have a clean, honest transaction.  In this way, we don't lose money, and the supplier would continue supplying.  There were more things that could go wrong in the handwritten method we used before such as misread weighs, encoding keystroke errors, etc., so a better, and faster method was needed.

The solution adopted by the company was to employ an automated, mobile approach in recording weights.  Luckily, the platform scale in service was using First Philippine Scale's FI03, which features an RS232 connection for printing.  This interface provided flexibility in connecting peripherals, such as a mobile phone running Android OS.  The challenge was that additional hardware was required.  An RS232 to USB converter cable was needed to connect the weighing scale to the phone.  However, having the cable alone is not enough.  Since the cable cannot directly connect to the weighing scale, and to the phone, some converters were required, with one being sourced from the US.  When the hardware part was complete, the next challenge was to develop an Android app to read weight data sent by the scale to be used in recording.  It was also realised later on that not all Android phones support USB Host API feature, which enables a phone to communicate with peripherals connected through its micro USB port.

After the challenges were hurdled, the app was deployed to the receivers.  Scrap is still placed on the platform scale, but no writing on paper is involved.  After the connection has been set up, the receiver only has to press a button on the weighing scale, and the weight data is transmitted to the phone, then this is recorded in a CSV file.  When unloading is done, the receiver uploads the file to a cloud storage  where it is retrieved by the purchasing staff.  Since it's a CSV file, it can be opened through a spreadsheet, where payment calculations are made depending on the types of scrap that was brought.  Tedious encoding is eliminated, along with its associated risks.  However, opening the CSV file, and summing weights for different scrap types (e.g. probably by alphabetizing the scrap types, removing duplicates, then using a conditional summing function), recording for inventory (e.g. copy and paste), and finally, printing a report seemed too tedious even when scrap receiving has been automated.

Summing weights, recording for inventory, and printing a report was mechanical task that took the time of our purchaser, which can be used for some other valuable task (i.e. looking for cheap suppliers).  It was in fact too mechanical, that I thought of having the computer do it instead of our purchaser.  Spreadsheets have a feature that can be used to automate tasks.  In this case, the task was to:

1.  Open the CSV file.
2.  Determine the scrap types delivered.
3.  Once unique scrap types have been determined, sum the weights of each scrap type.
4.  Record the scrap receiving in the inventory.
5.  Check the price per kilo of each scrap type received, and calculate payment.
6.  Print a report.

These are now all done by a small program in the spreadsheet.  Now, once the receiver uploads the CSV file of the scraps received, it only takes a press of a button to run the small program that does everything.  Time is conserved, and the purchasing staff is left to do more value added tasks.

Efficiency has its price.  Disregarding the price of the weighing scale, which we already had, we had to purchase a second hand, but high end phone that supports USB Host API, the cable, and adapters.  The cost was around P7000+ to automate the process, bulk of which went to the price of the phone.  It was only later on that a cheaper alternative was suggested in Google Developers Group Hackfair 2015.  Interestingly, a wireless solution is a cheaper approach.  I was able to source an RS232 to bluetooth dongle, which is relatively cheap compared to the price of buying a high end phone.  And after some development, bluetooth communication is now supported by the app.

Get it on Google Play