The Internet of Things (IoT) plays a fundamental role in contemporary society, necessitating an in-depth comprehension of its application layer protocols, intertwined technologies, security issues, and effective countermeasures. This survey delivers an exhaustive analysis of these protocols, emphasizing the escalating significance of Explainable Artificial Intelligence in IoT (XAIoT). To elucidate its practical implications, we conducted a case study examining a real-world scenario where XAIoT significantly bolstered IoT security. This case study demonstrated XAIoT's potential to enhance transparency and trustworthiness in IoT systems. Furthermore, the survey critically evaluates existing literature, pinpointing specific opportunities and gaps in the present state of IoT application layer security. For instance, our analysis revealed a pressing need for more robust security protocols and the integration of advanced machine learning techniques for anomaly detection in IoT applications. This survey, designed to provide a comprehensive perspective, seeks to stimulate additional innovation and research in the realm of secure and intelligent IoT applications. In doing so, it contributes to the ongoing dialogue on improving IoT security, offering valuable insights for researchers and practitioners alike.