A middleware approach to provide security in IEEE 802.15.4 wireless sensor networks