Tuesday, April 26, 2016

A MQTT application with QR code and OpenCV


Once a cake sent to us, bought back to package-center and next 2 days, as we were not able to pick it.
However at the same day we were rounding near by package-center for few times.

While get back home, it was late and 2 days later we'd a cake with feet-smell.

It often happen with us, delivery package from DHL/Post or others arrive, while nobody is at home. So at the evening, while back home, found the note from postman - either collect it from neighbour or report to postoffice / collection center.

However, it would be nice to know, as well saves time and effort, that a package was at my door. So, I can pick it while coming back home, if time allows.

For such scenario let me to grab the idea of building an automated system, so absent of recipient, postman will scan a QR code, with the camera attached with doorbell and bring the packet back to package collection center.

So how does it will work ?



To build my prototype solution, I'm using raspberry pi 1[B], a webcam [logitech c170], opencv and zbar for scan the QR-code via webcam, and MQTT to transport the QR-code data to a remote MQTT client.

Installing OpenCV in Raspberry-pi is sometimes problematic, due to its huge size, takes few hours to compile.

The best option for this project is, install the opencv library through apt-get.

             -->It gives some dependencies, google with the error - you'll find the
                 right packages.

Installing MQTT-broker [here i used mosquitto] also asks few more dependencies, e.g. -

1. shared libraries: libcares.so.2 & fatal error: ares.h:
 [sudo apt-get install libc-ares-dev]
2. fatal error: uuid/uuid.h: [sudo apt-get install uuid-dev]

You also need to install mosquitto-dev library.

sudo apt-get install libmosquitto-dev

So, now the Raspberry pi is ready to use as mqtt-broker with mosquitto api.

Zbar, i found most popular and easily understandable among other QR-code scanner. Install of libzbar0 and libzbar-dev is required.

sudo apt-get install libzbar0 libzbar-dev

That's it, now grab the source code qrMqtt.

compile and run it like


 You can also use android MQTT-client MyMQTT and subscribe to topic 'pcktatDoor'.

So, while done and the program is running, point your webcam to a QR-code, QR data will arrive to subscriber. Once read and published a message, the webcam will stop [webcam light will be off] for 5 seconds and then webcam will active again to read another QR-Code.

 You may have a look a video -



I've a future idea too for this product as, a packet box can build infront of door,
and order id [that you made order in ebay, amazon, aliexpress etc],
description may supplied to MQTT broker, and once QR-code scanned with
supplied order-id and description, the packet box door will open.
The postman will put the packet and close it.

No comments:

Post a Comment