Code for SmartPlug project