# The Design and Deployment of an End-To-End IoT Infrastructure for the Natural Environment
## 4 Design and Deployment
### Weather Proofing
#### 4.2.3 Link Nodes  
Link nodes are used to collect data received from our sensor nodes and to deliver them to the cloud. In our IoT system, we have two kinds of link node: a long-range relay and a gateway node.  
The relay node is a Raspberry Pi model A+, sited in the field of study. We note that our initial network design used an Arduino as the relay; however, it quickly became clear that the Arduino's relatively low-power CPU was unable to cope with forwarding the volume of data from the rest of the IoT nodes in the field. The relay node serves to receive data from the sensor nodes in the field and to send them to the gateway node via a long-range local area radio transmitter. This design gives us much higher flexibility in the physical locations of the field of study and the (Internet link) gateway node. The relay node receives data from both the soil nodes and the livestock tracking nodes, being in the local radio range of both kinds of node. The location of the relay was carefully chosen to maximise its radio signal propagation profile both in terms of the other IoT nodes in the field of study and the gateway node half a kilometre away.  
The relay node is equipped with two different radios: a short-range Xbee and a long-range Xbee, each with their own antenna. The first Xbee (Xbee1) is used to receive data from soil/livestock nodes. The second Xbee (Xbee2) is then used to send data from the relay to the gateway. As we were aware that various weather and other local interference effects could disrupt the communication between the relay and the gateway, we implemented a simple store-and-forward system at the relay. Each data packet received by the gateway node from the relay is acknowledged, and any unacknowledged packets are stored locally at the relay node (using a TinyDB database) until their reception is confirmed by the gateway. Figure 8 shows how the relay works. The radio xbee1 (step 1) receives data packets from the sensor network, and these are stored in a queue (step 2) at the relay node. They are then processed in a FIFO (First In First Out) method (step 3), where each data packet is forwarded by the radio xbee2 (steps 5 and 6). If the relay does not receive any acknowledgement from the gateway about a received data packet, then this data gets stored at the TinyDB database (step 4).  
The relay node (Raspberry Pi A+) was powered via its USB socket. To facilitate this, a DC/DC regulator of 12 V/5 V (CPT, CPT-UL-1) was installed inside the enclosure (see Figure 4 for an image of the relay node in its enclosure). The output was attached to a USB charging cable and the input to the bucanneer connector. This enabled a 12-V, 200-Ah deep cycle battery to be connected externally. This could be maintained with a solar panel, but this was unnecessary due to the high capacity and the availability of these batteries in our stores.  
The gateway node is a Raspberry Pi model B and works in a similar way to the relay node, using a store-and-forward approach to push data into the cloud. Specifically, whenever a data packet is received from the relay node, the gateway node stores that data in a local TinyDB database. The gateway then periodically opens a connection to our cloud server (via a 3G cellular connection) and sends all data from its TinyDB database that has not yet been acknowledged as received by the cloud server.  
Figure 8: The relay node.  
We use TinyDB databases on the relay and gateway nodes as they are extremely lightweight, occupying minimal storage space on the relatively limited Raspberry Pi secondary storage. The location for the gateway provided 3G signal coverage and access to the mains power. Therefore, the gateway was powered via USB using a mains adapter plug for continuous power.