Cross layer optimization of wireless sensor and sensor-actuator networks