Maker.io main logo

How to Use Cloud Storage on the Atmosphere IoT

2020-04-01 | By Maker.io Staff

So far in this blog series we have examined how we can use the cloud to store single variables. In this how-to, we will expand to not only save specifically named values, but also retrieve cloud data.

Improving Cloud Storage

Previously, we observed how the cloud storage element could be used to store counter and sensor values. However, the method was crude, and saving multiple variables would require multiple cloud storage elements. Instead, it is better to assign variable names, so we can access those variables with greater ease of identification when creating visual dashboards.

In addition to learning about variable names, we will also be learning how to query data from the cloud storage element to retrieve past variables. This can be highly advantageous in IoT designs where IoT devices send commands to each other. For example, an IoT button that controls whether a window is open or closed and an IoT receiver that reads the state of this variable to mechanically open or close the window.

How to Use Cloud Storage on the DK IoT Studio

BOM

Scheme-It

How to Use Cloud Storage on the DK IoT Studio

Scheme-It

The Hardware: Pi Weather Shield, TEMT6000, and a HUZZAH32

This project will require two sensor boards and the Adafruit HUZZAH32 so we can demonstrate how to store multiple sensor readings in the same cloud storage element. The two sensor boards in use are the TE Connectivity Raspberry Pi Weather Shield and the TEMT6000 ambient light sensor.

The weather shield uses the I2C bus and therefore only requires four wires, combining multiple sensors (the HTU21 and the MS5637). Meanwhile, the TEMT6000 is a purely analog device that uses A2 to read the phototransistor’s state. The Adafruit HUZZAH32 is mounted on a breadboard with jumper wires that connect to the sensors.

The Software: An Interval Element

The device software is very simple and consists of an interval element probing the sensor elements. The values are then sent to individual Bluetooth elements. By default, the sensor elements shown in this design are not included, so they must be added to the design by clicking the Add Element button at the bottom of the element toolbox in Atmosphere IoT. Then, search for the sensor names. While not required, all of the Bluetooth elements should have their data-types changed from string (their default) to floating point, as floating-point numbers use less memory than strings.

How to Use Cloud Storage on the DK IoT Studio

Device Application

The device application is where half of the magic happens. A single interval element is used to read the latest data from individual Bluetooth elements. This data is both sent to a corresponding label to alert the user of the recorded values, as well as to the cloud for storage using the cloud event element. Simultaneously, a single button is used to get the latest light data by sending a request command to the cloud. A cloud command element, which returns the latest value, then shows this value on a label.

How to Use Cloud Storage on the DK IoT Studio

The Benefits of Cloud Storage

The cloud is where the other half of the magic happens, and each cloud event is connected to a single cloud storage element. The three cloud events that correspond to storing data (pressure, temperature, and light) all use the Add Data trigger. However, instead of leaving the value as “value”, a piece of JavaScript is used. The formula that allows you to store data under a specific variable name is shown below:

How to Use Cloud Storage on the DK IoT Studio

The VariableName string is replaced with the variable’s name you wish to save to, while “value” corresponds to the value passed to the element via the connector. The images below show the differences in the connectors between the different cloud events.

How to Use Cloud Storage on the DK IoT Studio

How to Use Cloud Storage on the DK IoT Studio

Not only can we store data using the cloud storage element, but we can also retrieve the latest value from a variable using the Query Data ability and using the code below:

How to Use Cloud Storage on the DK IoT Studio

This function will return all variable data, so we will need to use an array code to choose a specific value. The result of this query will be a single array variable called “value”. Individual values can be accessed using the code below:

How to Use Cloud Storage on the DK IoT Studio

How to Use Cloud Storage on the DK IoT Studio

Being able to store and receive data from the cloud is a key element for more intricate projects on Atmosphere IoT. We’ll build upon this critical functionality in future posts!

制造商零件编号 3591
HUZZAH32 ESP32 FEATHER MALE HDR
Adafruit Industries LLC
制造商零件编号 BOB-08688
TEMT6000 LIGHT SENSOR
SparkFun Electronics
制造商零件编号 PRT-12794
JUMPER WIRE M/F 6" 20PCS
SparkFun Electronics
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum