The Internet of things (IoT) is becoming an increasingly popular subject all around the world. Most of the people will use IoT devices that big companies produce in near future. But Makers like me always try to build their own solutions. I am working quite long time on internet of things. I love the IoT concept and there are lots of DIY projects, opensource examples and communities working together to bring up some solutions to our everyday problems. There are many industrial application that use IoT technology and there will be a lot more in coming years. The analyst firm Gartner says that there will be over 26 billion connected IoT devices by 2020.
Part of this storm is The Smart Homes which was a great topic to work on as a Maker. Smart Homes make life easier and more comfortable. We all love being able to control lighting, entertainment and temperature from our couch. When we are away we also love to be sure about our home security system which will inform us in case of an emergency. You can always connect to your IP camera and see your lovely pets are eating their meals. Anyway we all sure that our homes will become smarter and smarter. Open source solutions that you can add some intelligence to your life whenever you are free for the weekend will be a trending topic hobby in these days.
This writing is about a WiFi RfID reader for my smart home. The problem I have is; I want my home know if I am at home or away. This is the most important info for my house because the rules will be activated or deactivated according to my presence. For example the alarm system will be armed when I am away and must be off when I am home. If my home knows who entered the home then it can decide the appropriate settings for me or for my wife. There are different solutions for this problem. I look at them in detail and understand that this is not an easy task. There are location based systems that use your smart phone's GPS. Holding your GPS open all the time is not battery efficient. I saw some other solutions for android phone users but most of them are not working with IOS. I plan to solve this with a semi-automatic way. I will carry a small RfID tag with my keys and when I am home I will bring it closer to the RfID reader which is near the door and my home will understand my presence. My wife will carry a different key-fob so her id will be different. This way, my smart home will understand which one of us reached at home.
There are very cheap RfID readers around for a while and bringing them together with our great hero esp8266 WiFi chip seems to me a good idea. You of course can find other palaces to use this device. You can easily record the data in a database. The id and the time-stamp of reading the key-fob or RfID card can be used as workman attendance control system for your factory. I will try to code some applications and I want to hear from you some ideas for the other usages.
The main components for my design is like below:
The communication between our micro controller and the RfID reader is SPI. Do not worry about the details because we have a great Arduino library who is responsible with the details. The other communication protocol is serial communication between Esp8266 and our micro controller. We will simply send the scanned RfID number to Esp8266 over serial. The important part is we will add a new line character at the end so that Esp8266 will understand that it received one id. The embedded code inside Esp8266 then publish this id over MQTT. Let me quote here one sentence about MQTT from mqtt.org/faq.
MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks
MQTT is our messaging protocol and we will use it in all our IoT projects. Please take some time and watch some MQTT videos from YouTube.
There isn't so much to say about the schematics. The problem I faced here is the RfID connection headers. The SPI protocol needs robust connection so I replaced the regular headers with the precision headers. Please keep in mind this detail. You can always solder some wires to make the connection permanent.
You can find the source files including the firmware at MakerStorage Github Repo
Actually we have two micro controllers in this project so we have two embedded code here. Our Atmega328p will be responsible to read the RFID and send it to Esp82266 over serial. The other code inside Esp8266 which will listen to the serial bus and when it receive the RfID number it will publish it over MQTT. Please find our repo above about these software.
Our device publishes MQTT messages with a payload of the scanned RfID. So what about the receiving part.
In order to see and debug the coming messages the great tool is MQTTLens
But This is not enough for MQTT communication. If you read about it you know about the Broker. MQTT Broker is a server which is a bridge between the communicating parties. Every party must connect to the broker in order to send and receive messages. In MQTT jargon sending messages means Publishing a message and this message will be send to the Subscribers over the broker. This mean that we need a MQTT broker. For this example I use mosquitto public broker The other important part about this example is we do not use any secure communication. If your ids or your application is important please consider to make communications over a secured network. People who have experience on secure MQTT please tell us about it in the comments.
We set our MQTT server and adjust the MQTT settings pointing to our broker so we are ready to see the incoming messages. Please set the MQTTLens Host name to Tcp://188.8.131.52 (this is the ip address of the mosquitto public broker) in the configuration.
More will come about this project. In this tutorial we just send our ID to the MQTT broker. In next tutorial I will write about a server side code which will subscribe to these messages and write them to a Database. You can extend the usage of this board according to your needs. Please feel free to ask or comment here.
You can start playing with this board and software by ordering it from our store.