As a bridge for information interaction between people and things, and things and things, IoT devices bring security issues and data privacy protection issues that have always been the main challenges in the IoT environment. In terms of abnormal traffic detection of IoT devices, data sharing between device data is usually not possible. This makes the deep learning method for model training based on a large amount of data unable to fully exert its strength due to the lack of IoT device attack instances, resulting in the problem of low detection accuracy. To this end, we propose an abnormal traffic detection model for IoT devices, FL-DSCNN (Federated Learning and Depthwise separable convolutional neural networks). First, the mayfly optimization algorithm is used to select the traffic features, and the model training time is reduced by reducing the feature dimension. Then, by introducing the FL framework, the depthwise separable convolutional neural network is used as a local model for collaborative training without sharing private data, avoiding the problem of lack of labeled data due to the “data silos” phenomenon while protecting data privacy. In addition, we experimentally verify the proposed method on the existing public dataset Aposemat IoT-23 dataset and compare and evaluate it with existing methods. The experimental results show that the method can achieve two-class and multi-class detection respectively. The detection accuracy rates of 98.52% and 97.73% prove the progress and superiority of the proposed FL-DSCNN model in the detection of abnormal traffic of IoT devices.