Community use case: smart payments for water consumption

Our Lokesh came up with an innovative solution to automate the water payments of his residence.

We love seeing which creative FINN use cases come up from the community. This time it’s our very own Lokesh who came up with an innovative solution to automate the water payments of his residence. Using FINN, there’s no more need to manually check the water meters, and no more need for the residents to manually pay the bills. Lokesh wrote an extensive guide on how he made it all work – let’s dive right in! 


The use case:

As of today, we have water consumption meters installed at our residences by the Water Municipality Board (WMB). On a monthly basis, a person appointed from WMB comes to records the reading from the meter and drops over the bill copy at the residence to pay the water bill within a due date. It’s a dated system with numerous drawbacks, such as:


  • Manual intervention in terms of recording meter readings and bill payment
  • Chances of losing the bill copy before payment
  • Additional training need to be given
  • There could be manual errors, faulty meter and calculation errors
  • No prior notifications regarding the consumption of water, only after billing

Time to innovate!

Automating the payments with FINN 


FINN can be used to automate the payment as well as notify the owner about the volume of water consumed on a timely basis. In order to make use of FINN, residences should have smart meters equipped with an ESP-32 board and a Water Flow Sensor to measure the volume of water consumed. Assuming all meters will be replaced by our new and improved ones, the following will be true after programming:


  • Each smart water meter is uniquely identified by a unique identifier associated with the residence owner id and registered on the WMB portal.
  • Each smart water meter is configured to trigger a notification to user on consumption of every 25 liters of water
  • Each smart water meter is configured to trigger an automatic payment from the linked user bank account on consumption of 100 liters of water and followed by notification on payment receipt


Time to get started.

Hardware components

ESP-32 development board
Water flow sensor
Connecting wires
How to connect ESP32 - DevKitC to Water Flow Sensor

Software Packages:

·     Arduino IDE to develop and flash sketch to ESP-32 Dev Kit for measuring water volume consumed and triggering notifications and actions autonomously

·     BoT ESP32 SDK used as underlying library in the sketch for BoT Service. Download and install into Arduino IDE, refer to link for setting up the SDK on ESP-32 board

·     Flowmeter library used in the sketch to simulate the flow sensor and measure the water volume consumption. Download and install into Arduino IDE.


Defining Actions and Notifications in the FINN Portal:

For using FINN to enable autonomous payments for any use case, the very first step is getting login credentials for the Maker Portal. and define required Actions and Notifications. Below listed are the data points to be noted down from the maker portal:


  • Maker ID available under Account
  • Actions ID available under Actions
  • Notifications ID available under Actions


Configuration and Key-pair details for ESP-32 SDK:

Following the usage instructions provided at ESP-32 SDK Readme page, we need to provide certain information in the form of configuration and private-public key pair. The required files are available in the data directory of ESP-32 SDK GitHub repository, place them into data directory of the sketch to measure water volume consumption. Also, update the Maker ID and Device ID values accordingly in the configuration.json file. Below snippet shows the contents from configuration.json file: 

code 1

ESP-32 Water Meter Sketch Flow:

The ESP-32 Water Meter Sketch mainly contains 3 separate tasks running on 2 ESP32 cores. The main task is responsible for measuring the water consumed using the attached flow sensor, running on Core-1. The other 2 tasks – notificationTask and paymentTask running on Core-0. The main task measures the frequency and flow rate from flow sensor, calculates the threshold notifications for each interval of 25 liters of water consumed and payment for every 100 liters of water consumed. The notificationTask is responsible for any outstanding notification to be triggered when it runs on Core-0. The paymentTask is responsible for checking any payment to be triggered when it runs on Core-0.     


Below pasted is the code snippet from the main task on setting the notification flag for different intervals and the payment action flag.


code 2

As highlighted in the above code snippet from the main task, we can see that there are 4 intervals and by default, the interval threshold value is 25 liters. When the amount of consumed water reaches INTERVAL_THRESHOLD liters in any of the interval, the notify flag is set and the corresponding notifyID to identify the notification to be triggered by the notificationTask. And the consumed volume crosses the last interval threshold, by default it is 100 liters, then the payment action flag is set and the paymentTask is going to trigger the autonomous payment followed by the payment notification to the customer on FINN Mobile Application. All the 3 tasks are running indefinitely with the fixed amount of delay after each run.


The notificationTask, when it gets chance to run on Core-0, it checks for any outstanding notification pending through notify flag and if so, then it identifies the right notification to be triggered with the help of value stored in notifyID field, followed by triggering the notification with the help of BoT Service instance. The below pasted code snippet is from notificationTask:

code 3

Finally, the paymentTask is responsible for autonomous payment of any pending payment. When it gets chance to run on Core-0, it checks for any pending payment with the help of value stored in action flag and then triggers the payment if the payment is pending and the board is connected to Internet, followed by enabling the payment notification to be handled by the notificationTask when it gets next chance to run on Core-0. Below pasted code snippet from paymentTask of the sketch depicts the flow for autonomous payments:

code 4

With these 3 concurrent tasks running continuously on ESP-32 board making use of Core-0 and Core-1 with agreed upon delay between each of them are going to help in calculating the water consumed with the help of flow sensor and the regular notifications for every 25 liters of water consumed, autonomous payment for every 100 liters of water consumed.

Steps to execute ESP-32 Water Meter Sketch:

This section provides the step by step instructions to execute the ESP-32 Water Meter Sketch available on BoT-ESP32-SDK GitHub repository. Refer to above provided Software Packages Section to setup the required Software Components on ESP-32 board. Follow the steps below to ready the sketch and execute on the ESP-32 board:


  • Define 5 push notifications on Maker Portal. 4 for every 25 liters of water consumption, 1 for payment notification and record their IDs
  • Define 1 payment action on Maker Portal for 100 liters of water consumption and record it’s ID
  • Download the ESP-32 Water Meter Sketch and the data directory into Arduino/sketches path on the system from the BoT-ESP32-SDK GitHub repository
  • Update MakerID and unique UUID4 as DeviceID in configuration.json file located within data directory
code 5
  • Update the WiFi credentials in ESP32-water-meter.ino sketch to enable the board to connect to the internet:
code 6
  • Update the push notification IDs defined and recorded from Maker Portal in ESP32-water-meter.ino sketch:
code 7
  • Update the payment action id in paymentTask body present in ESP32-water-meter.ino sketch:
code 8
  • Update the ESP-32 board pin number to which the flow sensor connected in ESP32-water-meter.ino sketch otherwise the sketch uses simulated flow sensor assuming it’s connected to Pin-3:
code 9
  • Make ready the circuit connections to connect flow sensor to ESP-32 board and connect the ESP-32 board to system, select the port in Arduino IDE
  • Change Partition Scheme to No OTA (Large APP) in Arduino IDE -> Tools
  • Compile and Upload the sketch onto ESP-32 board
  • Flash data directory contents using Arduino IDE -> Tools -> ESP32 Sketch Data Upload option
  • Wait for a couple of seconds, the sketch should start running and connect to specified WiFi Network as provided in the sketch.
  • Blink of built-in LED (blue color) on ESP-32 board indicates that the board has successfully connected to provided WiFi Network, make a note of it's IP Address
  • Specified deviceID present in configuration.json is new, then SDK internally generates and saves QR Code for the device.
  • Pair the new device through FINN Mobile Application using BLE or using saved QR Code
  • The QR Code can be accessed using the webserver's end point /qrcode running on ESP-32 board
  • Once the device gets paired, add the services on FINN Mobile application then the tasks get start to measure water consumption and trigger the events accordingly
  • The BoT-ESP32-SDK also supports RemoteDebug feature through telnet. From any of the remote system connected to the same WiFi network as that of ESP-32 board run telnet client to connect to ESP-32 IP Address for remote monitoring of the events.
  • The push notifications can be monitored on FINN Mobile Application
  • We can also monitor the actions triggered through Maker portal dashboard


In this blog, we have briefly described how to use FINN to enable autonomous payments and notifications for amount of water consumed. We have detailed out about the hardware components requirements; software packages need to be used to achieve the solution explained through this blog. We have also explained the sketch flow implemented to autonomously measure the water consumption and perform the required notifications and payments. Finally, we have given the sequence of steps to execute and monitor the result of the explained solution. With the solution described through this blog,  the Municipality Water Board and the consumers can make their lives simpler by adopting FINN service for autonomous payments and water consumption notifications at required intervals for water consumption.