Lightweight Middleware for Seamless HW-SW Interoperability, with Application to Wireless Sensor Networks