Middleware for distributed IoT applications