The arrival of IoT has brought constant innovation. This innovation has allowed many “things” (sensors, wearable devices, smart appliances, among others) to be connected to the Internet to deliver the information they collect. This need for connection has set the tone for the development of new protocols that adapt to the IoT environment, taking into consideration low energy consumption and low computational cost. These protocols are known as Low Power Wide Area Network (LPWAN). In this context, one of the most used is LoRaWAN. As many other IoT protocols, it is exposed to security threats. These threats aim to compromise security principles like confidentiality, integrity and availability (CIA Triad) of the information. This paper aims to analyze weaknesses between end-nodes and gateway communication of LoRaWAN to then propose a lightweight security protocol to address the detected vulnerabilities. This protocol uses lightweight cryptographic functions to achieve this goal as it is intended to be deployed over IoT devices which are very limited in terms of hardware and power resources. Likewise, this protocol has gone through a formal security analysis with the use of a tool called Scyther, in order to validate the security of the proposed protocol.