Netduino is an open source electronics platform using the .NET Micro framework. I was using Netduino to create an IoT application which allows me to turn on the lights in the garage as I come closer to the garage.
- Gimbal (Proximity Sensor)
- Netduino Plus 2
- VeraLite (Z-wave controller)
- Z-wave enabled outlet.
- Azure Service Bus Queue – Setup to hold the commands/messages sent from the mobile App, consumed by Netduino/WCF service.
- Xamarin – To build the mobile app to detect the proximity sensor and send commands to the Netduino using the Azure Service Bus Queue.
This is the way I envisioned it to work:
- The proximity sensor will be in the garage.
- The mobile app will get the proximity information from the sensor as the phone approaches the garage.
- If the user is close, the App will send a message to the Azure Service Bus queue.
- Netduino will poll to the queue for new messages.
- If Netduino finds a message, the command passed in the message is checked.
- The Netduino then connects to Veralite (Z-wave controller) and sends a command to turn the light on/off based on the command in the message queue.
In theory this all should work and it does in most part. I ran into a couple of issues here which I thought might be useful to anyone working on such projects.
- Proximity values from any sensor are always fluctuating. They are never precise. It only provides information that sensor is nearby. Don’t rely on the distance value. It is based on the strength of the signal and not reliable.
- Netduino runs on .Net micro framework. Currently, it does not support SSL. All the blogs I read said that SSL implementation takes up too much memory and Netduino does not have enough to support it. So, you cannot directly connect to the Azure Service Bus queue. Hopefully, someone will implement the SSL stack soon.
But if we modify the architecture a bit, we can overcome the SSL support issue. Here is the modified architecture that worked.
I added an additional layer which acted as proxy between the Netduino and the Service Bus. Instead of Netduino connecting to the Azure Service Bus Queue endpoint, Netduino connects to the WCF service implemented behind the firewall. The WCF service checks for messages in the Azure Queue and returns the messages to the Netduino.
By using the Azure Service Bus Queues, we don’t have to open up ports on our router or setup port forwarding. Doing so, opens our network for all kinds of attacks. Not being a security expert, I would rather have all incoming ports shut tight than try and implement an authentication mechanism.