Inspiration

We worked together on a previous devpost hack, the Postman API hackathon. One of the ideas we had for the Postman API hackathon was a watering system. Ultimately, we decided to focus our efforts on CoinStop which ended up winning the moonshot prize!

When we saw that Microsoft was doing a hack for sustainability off of Azure IoT, we decided it was a sign that we should work on our IoT watering system.

What it does

It waters your outdoor plants, or crops, while bringing awareness to your water consumption - with the ultimate goal of trying to conserve water. You can turn on the water for a specified duration, or just decide to turn the water on/off. If you turn on the water and forget about it, don't worry, the water will automatically be turned off when the soil moisture detector exceeds a certain threshold. A proof of concept for a flow sensor was also implemented to measure water consumption. Based on rules set, this consumption could be reduced greatly while watering your garden.

How we built it

We decided to write the code for the Raspberry Pi in Python. It turned out that we were able to find Python3 modules for all of the sensors we had, with the exception of the flow sensor (but even that we were able to start off with a SmoothedInputDevice). We started with the sample code for azure-iot-sdk-python for communicating with Azure IoT Central. Most of the sample code was rewritten due to the sample using deprecated APIs.

We created a new Device template for our smart water valve, with all of the Telemetry, Commands and Properties we needed. We also added a few Cloud properties, which are used in the Rules. We customized the properties so that the proper schema was applied (when possible). We created views for visualizing the device (Overview tab) and for configuring the device (Device Setup tab).

We created rules in IoT Central, but the majority of the workflow is actually managed in Logic app. In Logic app we talk to 3rd party MSN Weather service and also make calls back to IoT Central to turn on/off the water.

Challenges we ran into

IoT Central didn't have a way for our "Volume Flow Rate" to be expressed as "Liters per minute" (the dropdown only had L/sec, mL/sec, L/hr, mL/hr. We ended up using "None" and then just filling in our own display unit. This had the disadvantage that now text isn't localized ("Liter" vs. "Litre", etc.)

IoT Central didn't seem to have easy way to do formulas on our input data. We solved this by only sending telemetry once per minute for values that are Liters/Minute; so when you sum up the telemetry values you get consumption in Liters/Day.

We couldn't figure out how to have two people (not in the same organization) share admin access to an Azure Logic app. We ended up each creating our own Azure Subscription. We had to create separate logic app instances to create our own rules. It was really hard to collaborate on that.

Logic App had an "Execute a device command (Preview)" but for whatever reason we couldn't get it to communicate with the device regardless of the parameters we passed (getting either HTTP 400 or HTTP 404 errors). We eventually just switched to using a POST HTTP command with a runcommand.

The location of the device wasn't automatically passed to our logic app, which made getting the weather forecast a challenge. We eventually made an additional callback to IoT to retrieve the properties (/api/devices/@{device}/properties).

The team didn't both have the same hardware sensors. This resulted in added support for both BME280 and DHT11/DHT22 sensors. We also made it so if a value of SIM is used, we do our best to approximate what the sensor would give you (for example, making API call to openweatherapi with the device lat/long).

The water flow sensor wasn't the proper threading to attach to the pipe. If you set a value of SIM you can put in your typical water flow values.

Accomplishments that we're proud of

We were able to use Azure IoT Central, Azure Logic Apps, Python and Raspberry Pi to implement our vision of a smart water valve that promotes environmental sustainablity.

The azure-iot-sdk-python project we started with used APIs that were deprecated in since 2.3.0 so we rewrote that code to use the new APIs like (on_method_request_received & on_twin_desired_properties_patch_received).

What we learned

We learned a lot about Azure IoT Central. We also learned enough of Azure Logic Apps to be able to make conditional API calls. One team member learned Python for the first time. We also learned the convenience Azure IoT has to offer as a personal and business solution.

What's next for The Smart Valve 2049

It would be nice to try to put all of the pieces together that we have to actually make the watering system. Track down a better flow meter that works with our pipe while not significantly impacting the flow rate. 3D print some waterproof enclosures & figure out how to safely get power to the solenoid. Instead of using simulated data, we will want to order sensors and get it setup to water a garden.

Built With

Share this project:

Updates