# Design and Implementation of a Mixed IoT LPWAN Network Architecture
## 4 Electronic Design
### Meter Data Acquisition and IoT Connectivity  
The device described here is intended to collect data from residential water meters and send them to an information infrastructure over a specific IoT radio link. The water consumption data is acquired in the form of electrical impulses whose frequency depends of the current flow and is generated either by the meter itself if it is remote metering ready, or adding to the meter a module which detects the needle movement and generates the impulses. Unlike other commercially available solutions, this unit is also capable of performing remote control on an external electrical device through a potential-free output. An application example could be acting on a solenoid valve and in this way take control over the subscriber's water supply service. To receive the remote control command the IoT downlink is used and once the new condition is established, no additional energy supply is required to hold that state. IoT connectivity capabilities are multiple and links can be established to the Sigfox network, any available LoRaWAN network, or to the own gateway device described in point 4.3 using LoRa modulation and enabling connectivity in shadowed areas without direct link to the aforementioned networks. The data frame sent to the IoT network has a specific format defined for this application and shown in Figure 8. The first field named Frame Type conditions the rest of the frame both in length and in all other defined fields. In this way, and although a particular frame type for this application is described below, it is easily adaptable to other cases and ready to future improvements only setting a new Frame Type. The maximum frame length will depend on the used network, being currently Sigfox the most restrictive with a maximum uplink payload of 12 bytes. The next field is the accumulated consumption value. Due a typical residential water meter shows the accumulated value in 8 number wheels and therefore a range from 0 to 99999999 litres, the field size has been set to 4 bytes (32 bits) which means it is able to represent unsigned values from 0 to 4.294.967.296, enough for this case. Following, a device identification byte is present to distinguish between 256 units using the same gateway described below in Section 4.3. The status field is a byte containing an error code for remote fault diagnosis. At the end, the battery field carries the power level of the battery. In the example shown in Figure 8, the device number 5 sends a water consumption value of 471 litres without error and with a remaining battery power of 88%. Optionally, and using the downlink from network to device, a frame with the format shown in Figure 9 can be received. It contains the new output value for remote control, data delivery interval and current date and time to update the internal RTC (Real Time Clock). The first frame field named Frame Type determines the other fields in the frame. For this particular application, the frame shown in Figure 9 has been set up, but it can be adapted to other cases setting a new Frame Type. The maximum frame length will depend on the used network, being currently Sigfox the most restrictive with a maximum downlink payload of 8 bytes. In this application, the device output is digital and can be set to two possible states: activated or deactivated, but the Output field has been defined as a byte (values from 0 to 255) in order to enable controlling analog loads using PWM (Pulse Width Modulation). For instance, a solenoid valve capable to adjust its aperture to deliver the fluid at different flow rates. In the example shown in Figure 9, the output is deactivated, the delivery interval is set to 7 min and the current time is supplied. Figure 8: Uplink frame and fields description.