## 3 LORAWAN Operation
### LoRaWAN Joins and Communications  
A LoRaWAN can comprise a handful of sensors and a gateway with an inbuilt NS or tens of millions of motes and thousands of gateways tied together by one NS. A mote may be pre-joined to a network or need to \"join\" a network. The joining process [42] requires the mote and the network to share some prior knowledge of each other and share an application key. An application group is defined in the NS database and  
Figure 1: LoRaWAN Topology comprising LoRaWAN motes, Gateways, the Network Server, databases and feeds to data owners. given an eight-byte identifier. The eight-byte hardware addresses of all motes belonging to this group are associated with the application group in the database. A sixteen-byte application key is generated for the mote, then the application group eight-byte identifier and the sixteen-byte application keys are programmed into the mote. To join the network, the mote transmits a join request consisting of the eight-byte device address, the eight-byte application address, and a two-byte random number with a Media Access Control (MAC) layer Integrity Check (MIC) value is generated and the application key is shared. The gateway/gateways hearing this request forward radio packet along with the associated meta-data to their NS. If the NS recognises the mote hardware address and the MIC generated by the server matches the MIC sent, the NS generates a unique four-byte network address and a three-byte random number. The server uses the random number to generate the sixteen-byte network and application session keys stored in the database. The NS builds a join-accept packet consisting of a three-byte network identifier, the three-byte random number, the four-byte mote network address, and some network management information. The NS then sends the Join-Accept packet to the gateway with the best Received Signal Strength Indicator (RSSI), and the gateway forwards join-accept to the mote at a specific time. Finally, the mote generates the application session key and network session key by the use of join-accept packet. Unless the mote rejoins the network, from this time on, it will use the four-byte network address and encrypt data with the generated network and application session keys. An example of the network address is visible in Figure 2, identified as the \"DevAddr.\"  
For a mote that has pre-joined the network, the mote's four-byte network address and the network and application session keys are generated by the NS and programmed into the mote. Deduplication: Because the LoRaWAN can include many gateways with overlapping coverage, it is expected that multiple gateways will receive the same packet from a mote. Every receiving gateway will forward this packet to the NS, which will identify duplicate packets and associate them together. Since a packet includes RSSI information, the NS can direct any return packets to the gateway with the best RF path to the mote. Because the mote listens at specific times for ACKs, the NS must begin processing the received packet and prepare to send the ACK to the gateway in time for the mote to receive it. If the latency on a gateway to NS server link is excessive, the NS can send the ACK back via a less optimal gateway. The NS may have already forwarded the packet to the application owner when the duplicate packet arrives. In this scenario, the NS still has to recognise the duplicate packet and should not send an ACK but should still forward the duplicate packet to the application owner. The example in Figure 2 shows a \"'gateway_count\":1' indicating that this message was only received by one gateway. If multiple gateways had received the same message, the gateway count would be higher, and the array \"gateway_info\" would contain a set of gateway information for each receiving gateway. Reply Delay: If a mote is intended to send data and have the receiving system respond with instructions, there will likely be a transmit/receive cycle delay.