The case of the missing truck cargo

Introduction

An electronics box prototype to track missing cargo during lorry transport. This was implemented by the Sustainable Living Lab (SL2) at the Raitong Organics Farm in Northeastern Thailand. The whole process from ideation, iterative development, testing and deployment spanned about two weeks, including three days at the Raitong Farm in Thailand.

20171219_155903

Raitong Organics Farm entrance

Image: The Raitong Organics Farm at Sisaket, Thailand

Problem Statement

About 5 out of 750 boxes of packaged rice occasionally goes missing during the weekly 10 hour lorry journey to the sea port in Bangkok. This was affecting the farm’s financial bottomline as well as harming its reputation with clients. Due to strict security measures at the sea port, it was ruled out that the boxes went missing at the port. 

P9440910

Image: Loaded truck with a tarp

It was suspected that the thieves carefully removed the tarp and put it back after removing a few boxes at a location where the truck stopped for a while, somewhere during the lorry journey. The farm needed proof of this.

20171220_103428

The owner of the farm, Bryan

Image: Bryan Hugill, the farm owner, talking about the missing cargo

 

Ideation

SL2 came up with the idea of using a GPS system combined with Radio Frequency Identification (RFID) tracking of tags placed on the boxes. The reason why we chose RFID was that the tags were cheap enough, in the order of a few cents per tag, to be “fire and forget”, and we needed a lot of these. Also, we had to pick the UHF frequency range, which has a detection range of up to 10m, because the usual RFID that we are familiar with, which is in the KHz frequency range,  only had a range of a few centimeters. The cargo truck measured 6m in length, 2.45m in width and 2m in height.

P9440876

Image: The cargo truck

The theory was that once any of the boxes goes out of range of the RFID reader (a couple of metres), it could be assumed that the box was being stolen. Once this happened, a Short Message Service (SMS) alert would be sent out indicating that particular time and location. The mobile GSM system also allowed real time commands to be sent via SMS to the electronics box to ask for updates. In addition, all tracking activity would be logged onto a micro SD card for post-mortem data analysis.

 

Selecting the components

RFID reader

We picked the SparkFun Simultaneous RFID Reader – M6E Nano whose specifications fit our requirements, having a range of 4.5m. Sparkfun has a tutorial on how to use this reader, and even provided an Arduino library, called the “Sparkfun Simultaneous RFID Tag Reader Library”. How useful! We also got a heatsink for the reader since it can get hot pretty fast. It is not recommended to run scanning for more than ten minutes since the reader will auto-shutdown if it reaches 85 deg Cel.  

20171213_153032

Image: the Sparkfun RFID reader using the ThingMagic M6E-Nano chipset

UHF RFID antenna

The UHF antenna was a generic one, which we bought it directly from a RFID technology company in Singapore called Tracknet Id located at Woodlands. Interestingly, this UHF RFID antenna cannot be bought in any physical shop in Singapore, nor is it easy to buy on short notice online, being sold out on the Sparkfun store. The RF cable connections were a little tricky. First there was a 10cm u.FL to SMA adaptor from the reader which has to be connected to a 3m long SMA to TNC RF cable which connects to the antenna. We had to make sure the male and female connectors matched. We managed to get a range of 4.5m for detection of the RFID tags at max power and clear line of sight with no obstruction. We read that UHF RFID is blocked by metal and water, which includes human bodies, so if you put an RFID tag in your hand and cover it, there is a chance that the antenna will not pick it up. There is also a safety distance of 21cm from the antenna during operation according to FCC guidelines due to radiation. UHF antennas also interfere with one another, so make sure that their detection fields do not overlap.   

20171215_125601

The UHF RFID antenna

Image: the UHF RFID antenna

SIM module with GPS

The GSM SIM5320e 3G has both GPS as well as GSM capability. You can make calls and SMSes to this module if you insert a valid prepaid SIM card and hook up a speaker and mic. It can also locate itself using the GPS satellites. So it has two antennas, one for GSM and one for GPS. As with most Arduino compatible accessories, you can search for information about this component online. There is this nifty YouTube video on how it can be used to track stolen vehicles, which is a somewhat similar use case to ours! There is also this helpful starter guide which explains on how you can program the SIM5320 with AT commands directly over the serial port. Best of all, Adafruit has a tutorial and a special library for this component called the ‘Arduino Fona 3G library’! The library is essentially a wrapper around the AT commands and has a bunch of error checking utilities and multi-command routines to make it easier to program the SIM5320. It also converts the raw longitude latitude output of the GPS data which is in something called NMEA format (e.g. 0117.093867 N,10350.701970 E) into Decimal Degrees (e.g. Decimal degrees (DD): 41.40338, 2.17403) which can be directly input into Google Maps. It is interesting to note that the NMEA data also includes velocity (including direction) and time, extremely useful for our use case. We can know how fast the truck is moving or whether it is stationary at any point in time! Coming back to the Fona 3G library, considering that the document for the SIM5320 AT Commands runs into 550 pages, this library removes the need to figure out the AT commands you need by abstracting it into self-explanatory function calls such as getGPS() and getSMS(). Very useful!

A side note about the GPS antenna – it has the interesting property of being magnetic, which means that it sticks easily and securely on the roof of any vehicle. Do note that the antenna has to be oriented correctly to point upwards to the sky for best results. Do also note that in urban areas, it can take anywhere between 5 to 20 min to get a GPS fix from cold start, due to buildings interfering with the signal. At the Raitong farm in Thailand, it was clear open sky, and the first GPS fix came in almost immediately at around 1 min or less. In Singapore, even when positioned near a window, it is not guaranteed that a GPS fix can be obtained at all. If there is no GPS fix within 20 min, you can assume that you need to move to a more open area away from tall buildings.

20171213_114535

Image: It took 15min to get a GPS fix at this open space in between tall buildings

sim5320e module

Image: The GSM SIM5320e 3G module

SD card module

We bought a generic Arduino compatible microSD card reader and used the inbuilt Arduino ‘SD’ library, modifying the ReadWrite example program to suit my needs.

microSD card module

Image: generic micro SD card module

So the resulting block diagram looked like this:-

Raitong_ver1_block_diagram

Image: block diagram

You can see the power calculations for the phone bank batteries in the Appendix at the end of this article. I used SoftwareSerial to communicate with all the components.

20171217_005711

Electronics box

Image: Inside the electronics box

 

Technical challenges

Sparkfun RFID library limitation

After exploring all the examples in the Sparkfun RFID library, I discovered that there was no library function to count the number of unique tags within the antenna’s tracking range. What was happening was that the reader was randomly reading all the tags in random order, so for a particular tag that was nearer to the antenna could be read multiple times while a tag that was further away would only be read once. Since the reader could read up to 150 tags per second, in theory, it should be able read all the tags within the antenna’s range at least once. So I came up with a simple algorithm that would use an array to keep track of the number of unique tags read. If the current tag number is not in the array, it is a new tag, so add it to the array. If it is already in the array, skip this tag and read the next tag. Do this for a few seconds to ensure all tags are read at least once.

Screen Shot 2017-12-17 at 8.23.42 PM

Image: repeated tag number readings

I was not sure if this would work, so I posted my hypothesis to both the Sparkfun forum and Arduino forum. The Sparkfun forum answered one day later and was immediately helpful, even providing the entire implementation of the code for my hypothesis. The Arduino forum replied four days later and was not very helpful but I thanked the person anyway.

In Thailand, I tested the code for 70 tags and lo and behold, all 70 unique tags were read within 10 seconds! Thanks to the open source community!

Screen Shot 2017-12-19 at 11.41.24 AM

Image: screenshot of my question and reply

A side note related to this issue is the difference between EPC and TID numbers for each RFID tag. EPC stands for Electronic Product Code and is a 12 byte number meant to identify the category of product, e.g. a milk carton, eggs, whereas the 20 byte TID or Tag Identification number is a 20 byte number which is truly unique for each RFID tag. The library function created only reads the EPC but not the TID, and there does not seem to be an easy way to read multiple TID tags simultaneously, based on the available functions in the library. Luckily for us, Sparkfun randomises the EPC numbers on their tags, so there is only a 2^96 chance of two tags having the same EPC number, which means the probability is almost 0 (12 bytes x 8 bits = 96 bits), and we can ignore this issue.

UHF RFID blocked

UHF RFID is blocked by metal and water, including human bodies. After testing the UHF RFID detection range with cartons of rice at the Raitong farm, we realised to our disappointment, that the antenna could only detect tags behind a SINGLE box. Anything more than one box placed between the tag and the antenna, and the tag could not be picked up. This is a problem, since the boxes were stacked 8 or 9 high, by 6 wide and 15 in length, and the antenna needed to be able to penetrate at least 6 boxes in order to track all the boxes at the last vertical layer the back of the truck. This was assuming that the boxes would be stolen from the back of the truck since the sides of the truck had metal railings 2m high, whereas the metal railing was only about 0.6m high at the back.

20171220_144144

Image: Testing detection range with the antenna on the chair and RFID tags placed behind the column of boxes.

20171220_154839

Testing the RFID on rice boxes

Images: Testing another configuration with the antenna pointed downwards. Similar results – detection range of only one box.

We found out from Bryan that the rice had 14% moisture, so the water content could be interfering with the signal. Apart from the awful detection range of the antenna, there were also other factors that could complicate things. For example, how and where could we secure the antenna since the boxes were densely packed with no space inbetween? Would the metal flooring and railings of the truck interfere with the signal? Would the human thief be able to block the antenna inadvertently since human bodies block UHF RFID? Also, the detection lobe of the antenna is rather limited. What if the boxes were stolen from the top instead of the back of the truck?

IMG-20171222-WA0005

Image: densely packed boxes. Where to put the antenna?

We decided to scrap the RFID idea, so it was back to the drawing board for us. The next best idea was to install a Raspberry Pi computer with webcam, but we ran out of time to implement this. We resorted to a simple trick – using a tripwire. We would rig a couple of strings over some of the boxes. If any of the boxes were moved, the tripwire would trigger, and an SMS alert sent out indicating the time and location.

The block diagram for the actual deployed box looked like this:-

Raitong_ver2_block_diagram

Image: Block diagram for actual deployed box

P9440937

Image: Setting up the tripwire after removing the RFID reader

 

P9440953

Setting up the tripwire

Image: Tripwire

20171221_202622

Image: Setting up the tripwire

 

Other challenges

Airport security

As with any maker projects concerning lots of electronics and wires, there have been stories of running into problems with security at the airport. We took several precautions against this. We asked the Raitong farm for an official letter stating our order of business and the list of electronic components. And more helpfully, we disassembled everything and separated all components into individual boxes, so giving no excuses of looking like any sort of ‘bomb’. In the end, we had no issues except for forgetting to put the phone bank into hand carry luggage instead of check in, which is a common requirement for all passengers. The airport security did not ask about the big UHF RFID antenna and we did not have to produce our letter from the Raitong farm.

Screen Shot 2017-12-26 at 4.03.03 PM

Image: Official signed letter from Raitong Farm

Prepaid card value

While testing out the SMS system in Thailand between the sim card in the box and the sim card on my phone, I was not able to send or receive SMSes after a few successful times. It took me about an hour to figure how why. The prepaid card came with a value of only 15 baht for SMSes, whereas each SMS cost 3 baht to send out. Luckily for us, the Raitong Thai staff were able to help us quickly top up the card value using their local bank account.

20171221_180020

Image: Thailand SIM card. See the pathetic 15-baht call credit at the bottom right?

Operational deployment

Data logging

The datalog.txt file would record all GPS data at every 30 second interval, including position, speed and time. The log file would also report the status of the tripwire and note where the truck was stationary for more than 3 min.   

Screen Shot 2017-12-17 at 1.19.19 AM

Image: Sample of data logging on the SD card

SMS interactivity

Screenshot_20171221-210313

SMS interactivity

Image: SMS interaction

The system recognises only one command sent via SMS which is “Loc”. It will then send back a status string, including the number of SMSes left, whether the tripwire has activated, the date, time, speed and google maps link to its current location.

The system will automatically send out an SMS alert when the wire has tripped and when the truck has been stationary for more than three minutes.

Conclusion

Screenshot_20171222-160712

Tracked the truck journey

Image: route tracking of the truck journey

No boxes were stolen during this particular journey although we discovered some interesting things. For one, the truck took a longer time than expected – about 14 hours instead of the 10 hours promised by the transport company. We found out that the truck stopped for a long time at certain places, for up to 1 hour. This was not normal.

IMG-20171222-WA0004

Image: top layer of boxes came loose. Picture taken at the sea port.

Also, the tripwire indicated to us that some of the boxes got loose during the journey since the top layer of boxes was not a complete layer. This is good feedback so that it can be ensured that the top layer of boxes should be securely fastened the next time.

P9440947

The SL2 team with Bryan

Image: SL2 staff with Bryan Hugill

Bryan from the Raitong farm was grateful to us for the prototype and attempting to find proof of stolen cargo. We also learnt from this trip about teamwork and improved our technical knowledge.

Future improvements

Tamper proof box

Since the thieves would be able to see the box, they might attempt to tamper with it. The box should be securely locked and is only be able to be opened by a key or password. The box should be permanently sealed and all access to the internal components should be via exposed ports on the outside of the box. This includes charging ports for the phone banks and reading from the SD card.

Raspberry Pi (RasPi) with webcam

We did not have time to implement the next best idea which was to have a Raspberry Pi connected to a webcam. We could set up the RasPi to talk to the Arduino easily, each controlling different components, since the Arduino handles the SIM5320 very well, and the RasPi can handle the data flow from the webcam. The idea would be to add another SMS command to ask the webcam to send a low res image of whatever it sees at the back of the truck. The box could also automatically send out an MMS of the low res pic whenever the truck is stationary for more than X minutes.

APPENDICES

A. Cost breakdown

Item Qty Unit price Total
RFID reader 2 270 540
RFID antenna with RF cable 1 180 180
RFID tags 70 0.28 20
GSM SIM5320e with GPS antenna 1 90 90
Micro SDcard module 1 30 30
Arduino Mega 1 80 80
Power bank 3 25 75
Box enclosure IP65 1 80 60
Total: 1095


B. Power calculations

Note: Each of the following three components is connected to a dedicated 10000mAh power bank with a 2.1A max current draw rating. Each power bank has to last for more than 10 – 12 hours for the truck journey.

RFID reader

It has a peak power draw at 3.6W, or 0.72A at 5V while scanning at max power of 27.0dB. Using a 10000mAh (or 10Ah) power bank with 5V output, the power bank can output 0.72A for 10Ah/0.72 = 13.9 hours. But it will not be scanning continuously due to overheating. So we programmed it such that it scans for max 20s per min, or 20min per hour. So the power can last for 13.9/0.33 = 41.7 hours.

GSM SIM5320e 3G with GPS antenna

Sending SMSes can draw up to 2A from the power bank. This means that the 10Ah power bank can last for 5 hours which translates to 3600 SMSes, assuming each SMS takes 5 sec. In comparison, we would not have hit anywhere near 500 SMSes during the 10-12 hour journey. Assuming 500 SMSes at 5 seconds each, it will draw 2A for 0.7 hours, which is 1.4Ah. The power left from the power bank would be 10Ah – 1.4Ah = 8.6Ah. Assuming 100mA constant current draw for the GPS, which is conservative, the power bank can last for 86 hours.

Arduino Mega with microSD card

Assuming a constant current draw of 200mA, which is conservative, the 10Ah power bank can last for 50 hours.

C. Software code

First version created in Singapore with working SD card, GSM and GPS. See README for all Arduino pin and wiring connections. No RFID. (link)

Actual deployed version with tripwire and SMS interactivity. No RFID. (link)

Useful test program for RFID range testing and tag counting (link)

Useful test program for GSM SIM5320 module, including SMS and GPS (link)

Advertisements