Solution #1: Data storage

Estimated time: 5–10 minutes

You will want to complete the prior sections of this workshop before starting with this one.

Previously, you learned that you could watch your virtual plant UI and click the irrigation button to keep your plant alive. But there is a better way.


nio is the better way

Up to now, your system has been comprised solely of streaming data. Nothing was stored. Signals came and went, and all of the visualizations and actuations were driven by in-transit, ephemeral data. This is, in fact, one of the core features of the nio Platform–it allows you to intelligently minimize throughput, storage, and latency by letting you make informed decisions at the edge, rather than in the cloud.

In real life, though, a farmer may want to store soil moisture data to examine how irrigation and rain are absorbed or evaporated by the soil. If she is able to analyze historical trends over time, she can become a better farmer and a better steward of her resources.

It's all about choice: nio lets you decide what makes the most sense for your data.


The Data_Storage service

Using data storage in nio is one way to help keep your plant alive.

From your VirtualPlant instance, double-click the Data_Storage service.

You'll see a Subscriber block named PlantStatus:

  1. Double-click the Subscriber block to open up its block configuration.
    • The Topic field tells the block what data to subscribe to.
  2. Type plant.soilmoisture into the Topic field and click accept.

The Data_Storage service is now subscribed to the soil moisture data published by the Plant_Simulator service.

If you look at the Plant_Simulator service and double click the final PlantData block, you'll see that it's publishing to the exact same topic, plant.soilmoisture.

This is an example of the communication method used within nio systems called pub/sub, which stands for publish/subscribe.



[info] Topic matching

If the topics match exactly and your pub/sub is successful, you will see corresponding blue circles on the bottom (output) of the publisher block and on the top (input) of the subscriber block.

The only other block in this service is the CSVWriter block. This block allows you to save historical soil moisture data to a spreadsheet in the form of comma-separated values or CSV.

[info] Storage with nio

nio is interoperable with all data storage services, and already has blocks built for many. If you'd rather store information in MongoDB for example, just drag the MongoDBInsert block from the block library, configure it, and connect it instead of (or in addition to) the CSVWriter block.


Retain the hounds!

  1. In the UI, toggle irrigation on until it reaches 80%, then toggle irrigation off.
  2. In the System Designer, start the Data_Storage service by clicking the play () button in the contextual toolbar.
  3. Wait 30 seconds.
  4. Find the file named DemoPlant.csv in your plant_demo project folder (you can use your OS's search tool to locate it).
  5. Open the file.

If all went according to plan, nio added a row to the file every second with a soil moisture value and a corresponding timestamp.

You could now run some simple analysis to determine the evaporation rate ((x2 - x1) / time), giving you a ballpark estimate of when you should be irrigating. If you determined the evaporation rate to be 1% per hour and your current soil moisture was at 80%, you'd know that you have 80 hours before your plant is completely dry. That means you could spend 79 hours enjoying life before you had to run back and click the button again.

Not bad for 10 minutes work!

Using historical data to manage/estimate your schedule for when you need to water from the UI rather than watching the graph at all times is a simple way to help solve your problem. However, it is still fairly imprecise, subject to changing environmental variables, and requires quite a bit of manual work.


Next, explore how you can overcome many of these pitfalls by easily setting thresholds and configuring notifications with nio to keep your plant alive.

 

proceed to solution #2: thresholds and notifications »
 

results matching ""

    No results matching ""