# Novel Internet of Things Platform for In-Building Power Quality Submetering
## 4 IoT PQ Sensor Cloud Integration  
The novelty of this paper is the ability to measure and send aggregated on-time PQ data to the Cloud, as well as process data and check with the standard compliance. The important point here is that this information is accessible by any device that has an internet connection and a search engine. A mobile phone can access all data, without requiring any additional configuration or application, but there are several free applications with a friendly interface that can be used if the user prefers a faster way to access the platform. Compared to platforms such as Kaa, ThingsSpeak is less time consuming in terms of development as users must only use an API, and, compared to Carriots or Particle, ThingSpeak is free for non-commercial small projects (<3 million messages/year or around 8200 messages/day). The mentioned advantages make ThingSpeak the chosen platform in the developed IoT PQ sensor to collect, analyze and visualize data from the developed IoT PQ Sensor presented here. Another reason is the compatibility feature between this cloud platform and the software MATLAB, allowing better analysis from the data, apart from a proper visualization. The integration of MATLAB code is possible within the platform, so authors have implemented extra features for better data analysis. ThingSpeak offers a flexible and easy way of storing the information collected by sensors into the cloud, so the used platform has been used to show data recorded by the designed IoT PQ sensor. To do that, ThingSpeak introduces the concept of channel. Each channel allows storage of up to eight fields of data, using up to 255 alphanumeric characters each. There are also four dedicated fields for positional data: description, latitude, longitude, and elevation. All incoming data is time- and data-stamped, and receives a sequential ID. Furthermore, a channel can be setup to be either private or public. In the developed IoT PQ sensor, a public channel has been created to store four energy variables (V\({}_{\text{RMS}}\), I\({}_{\text{RMS}}\), Active Energy, Apparent Energy) which are obtained after analyzing the information received from the current and voltage sensors in the ADE7758, and read by the MCU. Moreover, two other fields are used to monitor information when a sag occurs, one of them containing in a coded way the joint information of the minimum V\({}_{\text{RMS}}\) and the sag duration, and the other field and most deterministic, the start time of the sag, i.e., the timestamp, which is given by the hardware equipment (RTC). As ThingSpeak is not a real-time but an on-time platform, the exact time of the sag occurrence is provided to the cloud system with this extra variable. There is a data limitation in the ThingSpeak version that is used in this experiment, meaning that only one datum every 15 s can be uploaded, so the compromise followed here is to send both V\({}_{\text{RMS}}\) and I\({}_{\text{RMS}}\) every 30 s. However, using another IoT platform from the above, described in Section 1, will allow data to be uploaded in shorter time scale, if required by the application. The information collected by the IoT PQ sensor can be written into the ThingSpeak channels through two different methods: Representational State Transfer (REST) [47] and Message Queue Telemetry Transport (MQTT) [48]. The former is designed as a request/response model that communicates over HTTP and it is advisable to be used to retrieve large amounts of data, as well as to create, view, clear or delete a channel, or even when a response to your GET or POST request is needed. However MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSocket [49] which should be used if the device updating the channel is power-constrained, as the MQTT publish operation is faster and consumes less energy. This is the main reason the MQTT method has been chosen to manage the information flow from the data registered by the designed IoT PQ sensor. Figure 12 depicts the MQTT publish/subscribe model.