The Internet of Things is made possible by the recent developments in communication and 5G networks, which enable real-time sensory data transfer between billions of devices. Raw data has no value until it is processed to extract its features. The features can be extracted using a machine learning technique, a common way to use these data. Federated learning (FL) is a platform that enables a group of clients to train a model cooperatively without disclosing their personal information. Traditional federated learning has issues such as data and model poisoning attacks, free-riding attacks, and model divergence caused by clients' non-independent and identically distributed (non-IID) datasets. Because the conventional federated averaging (FedAvg) aggregation algorithm in FL lacks an evaluation technique, it is unable to detect dishonest users or correct the global model's divergence. In this study, we suggest Shapley averaging (ShapAvg), a Shapley-based aggregation technique, to aggregate the global model by analyzing the models of the clients more effectively. Each client's weight in the weighted average under this approach will be proportionate to how much it contributed to the overall model performance. The results demonstrate that while employing non-IID datasets and in the presence of data poisoning or free-riding attacks, our suggested technique overperforms the FedAvg.