Up to this point, we have only used half of Digi-Key IoT Studios capabilities. In this how-to, we will learn how to connect our devices to the cloud and fully realize the Internet-of-Things, allowing our Bluetooth-enabled device to send data to the cloud storage system on the Digi-Key IoT Studio platform.
To send data to the cloud storage system, we will need to use the cloud event element. But, before we can use it, we should first know what the element does and how to use it.
The Cloud Event element can be found in both the device programming window as well as the application designer. The cloud element used in the device programming window requires a Wi-Fi connection and, as such, will not be covered in this how-to, whereas the Cloud Event element in the application designer is reliant on the smartphone's Wi-Fi.
While Wi-Fi can be useful for providing internet connectivity to devices, it is not always the most appropriate method. One of the biggest issues with Wi-Fi is its high-power requirement, which can be problematic for small devices that rely on batteries. If a device is only required to send small amounts of data and only requires a short connection range, then Bluetooth may provide a better wireless connection. In this how-to, we take advantage of the Bluetooth connection between our IoT device and our smartphone, allowing the smartphone to act as a bridge between the IoT device and the cloud.
In a new project, we start by adding an interval, GPIO, and Bluetooth element. The interval is set to trigger once every second, where it will trigger the GPIO element to toggle IO13. At the same time, the interval will also trigger the GPIO read and the GPIO element. Once read, it will send the value of IO13 over Bluetooth.
The app in our project consists of an interval, Bluetooth, label, and cloud event element. The interval element is triggered once every second, and upon each trigger, the Bluetooth element is read. This read value is sent to the label element so that we can see changes to the IO pin in real-time. The read value is also passed to the cloud event element which, upon receiving the value from the Bluetooth element, initiates a cloud event which has the value of the GPIO attached to it.
At this point, we can head over to the cloud side of our project. The first thing you will see is a cloud event element already in place. The cloud event element works in a very similar fashion to the Bluetooth element in that cloud event elements are linked.
However, unlike the Bluetooth element, the cloud event element is event-based and does not use an interval or another trigger source to work. As soon as data is sent to a cloud event, it appears on the corresponding cloud event and the data requires immediate processing.
In our cloud designer, we have access to many elements including buffers, conditions, expressions, and notifications, but in this tutorial, we will only be storing the data. To do this, we insert a Cloud Storage element, which allows for manipulation of data on the cloud (add, remove, update etc.), and then connects the cloud event to the cloud storage element.
The connection between the two must be set to Event Received as the trigger and the ability set to Add Data. The value that we send is “value,” which corresponds to the value that we sent to the cloud event in the application designer (the GPIO value). You may note that the cloud storage element can be given a name. This name is similar to a variable name and can allow for storing specific variables such as temperature, humidity, and pressure (the name can be anything you want).
The Digi-Key IoT Studio allows data storage of up to 10.49MB for each device. While this may not seem like a large amount of storage space, it is plenty for IoT devices that store temperature, humidity, and other simple sensory readings. There may be times when devices can send large amounts of data in a short time, and in these cases, it can be beneficial to check how much storage space has been used. Storage on the Digi-Key IoT Studio platform is done per device, as opposed to per project, so your device will need to be provisioned before you can check how much storage it has used.
Under the device menu, select your device and then click the Storage tab. This page will show you the storage used, as well as specific variables. These variables can be deleted and exported to CSV for importing into other applications such as excel.