A water tank level sensor **Built With WisBlock** to detect overflow and low level conditions.

Overview


RAK12014 Laser TOF sensor coming soon



WisBlock Watertank Level Sensor

Modules RAKstar RAKstar

Watertank Overflow detection using the RAKwireless WisBlock modules. It implements as well a trick to wake up the device from sleep by knocking on the enclosure.

REMARK

The code is based on my low power event driven WisBlock API ⤴️


Background

Here in the Philippines it is essential to have a water tank, because it is (unfortunately) still quite common that the water supply is cut off.
After I got my tank installed, I experienced several time that the floating valve that controls the refill of the tank got stuck and the tank was overflowing for hours before I detected it.
As there is no outlet close to the water tank, I needed a low power, solar recharged overflow sensor that can transmit the data over a longer distance.

RAKWireless WisBlock has all components I needed to build my overflow sensor.

  • RAK19003 & RAK4631 ==> The base board, battery supply, solar charger, MCU with LPWAN capability
  • RAK12014 ==> WisBlock Laser ToF sensor to measure the water level
  • RAK1904 ==> Acceleration sensor. This is not used for the overflow detection, it is used to wake up the system and activate the BLE. As the system is sleeping most of the time the BLE is of course switched off to save battery. I needed a solution to wake up the MCU and activate the BLE, so that I can access the device and setup its parameters. To wake up the system, you knock-knock on the enclosure. This vibrations are detected by the acceleration sensor, which generates an interrupt to wake up the system.
  • Solar Board => A small 5V solar panel to recharge the battery during the day.

The enclosure is not IP65 but can protect the electronics from water intrusion unless the device is submerged into the water. It was designed using Fusion 360. The data files for the enclosure and the small solar panel can be found in the ./assets/3D folder.

Enclosure Enclosure Enclosure

Dataflow

The sensor wakes up every 1 minute (configurable) and measures the distance between the Laser ToF sensor and the water surface. It packs the data into a data packet in Cayenne LPP format ⤴️ which includes:

  • Alarm status Overflow (digital output). Triggered when the distance between the water surface and the sensor is 20mm or less.
  • Alarm status Low Level (digital output). Triggered when the distance between the water surface and the sensor is 1000mm or more.
  • Measured distance to water level (analog output). It is not the calculated water level, just the value read from the Laser ToF sensor. For my water tank the distance between the sensor and the bottom is around 1200mm. If the measured distance is larger than that, the value is discarded. The reason that such values are measured is because the water surface is not an ideal surface for measurement with the Laser ToF. Waves, sprinkling water while refilling can lead to false values.
  • The battery level of the system (analog output) in volt.

The data format is

uint8_t data_flag0 = 0x01; // 1 Channel # 1
uint8_t data_flag1 = 0x02; // 2 Analog Input
uint8_t level_1 = 0;	   // 3 Water level
uint8_t level_2 = 0;	   // 4 Water level
uint8_t data_flag2 = 0x02; // 5 Channel # 2
uint8_t data_flag3 = 0x02; // 6 Analog Input
uint8_t batt_1 = 0;	   // 7 Battery level
uint8_t batt_2 = 0;	   // 8 Battery level
uint8_t data_flag4 = 0x03; // 9 Channel # 3
uint8_t data_flag5 = 0x66; // 10 Presence sensor (Alarm)
uint8_t alarm_of = 0;	   // 11 Alarm flag overflow
uint8_t data_flag6 = 0x04; // 12 Channel # 4
uint8_t data_flag7 = 0x66; // 13 Presence sensor (Alarm)
uint8_t alarm_ll = 0;	   // 14 Alarm flag low level

The data is sent as a LPWAN packet over a RAK7258 gateway ⤴️ to a local Chirpstack LPWAN server.
The Chirpstack LPWAN server has two integrations enabled:

Once Chirpstack has received a data packet for the Overflow sensor, it forwards the data to the two integrations.

Datacake

I used Datacake because it is a very comfortable tool to visualize the data. Here is the live data: Datacake

Datacake Dashboard

In Datacake you can setup rules that can send out on email on events. I use it to send an email if the Alarm value is true:

Datacake Email

Cayenne LPP MyDevices

And I added Cayenne LPP MyDevices, because it has more features to take actions on events by using triggers. Here is the live data: Cayenne LPP

Cayenne Dashboard

The data Overflow is connected to a Cayenne LPP MyDevices trigger that sends an email and a text message if the overflow sensor sends an alarm:

Cayenne Alarm Trigger

The received alarm messages:

Modules RAKstar

Power supply and assembly of the sensor

The sensor uses a small 400mAh battery, which is sufficient for this application, as the sensor is only 10 seconds active every 1 minute.
The battery is recharged during the day by a solar panel. The panel I used is 5V output panel, so that I can directly connect it to the WisBlock Base board.

Overview Sensors Assembled

Installation

The sensor is installed in an unused refill hole of the watertank. The 3D printed enclosure has a pipe that matches the diameter of the refill opening:

Mounting Detail 1 Mounting Detail 2

The sensor is just loose in the refill opening and the solar panel is placed on top of the water tank:

Mounting Detail 3 Mounting Detail 4

To protect the inside of the enclosure against condensing water from the tank the opening at the Laser ToF sensor is sealed with a peace of plastic glued to the enclosure:

Window Sealing


How to wake up the sensor

To lower battery consumption, the device advertise its services (LPWAN setup and BLE UART) only for 30 seconds after power up. After that the BLE advertisement is shut off.
But sometimes the BLE connection is required to change settings, update the firmware over BLE or debug over BLE UART. To avoid opening the device or do a power cycle to restart the BLE advertising, I added the RAK1904 accelerometer and set it up so that it triggers an interrupt if it detects a movement in any direction. If the interrupt is triggered, the device wakes up and enables the BLE advertising for 15 seconds, so that the WisBlock Toolbox can connect to it.

To trigger the interrupt, a simple knock-knock on the enclosure is sufficient to be detected by the accelerometer.


Hardware used

Power consumption

The application does switch off the Laser ToF module and the MCU and LoRa transceiver go into sleep mode between measurement cycles to save power. I could measure a sleep current of 20-40uA of the whole system.


Software used

REMARK

The libraries are all listed in the platformio.ini and are automatically installed when the project is compiled.


Setting up LoRaWAN credentials

The LoRaWAN settings can be defined in three different ways.

1) Setup over BLE

Using the WisBlock Toolbox ⤴️ you can connect to the WisBlock over BLE and setup all LoRaWAN parameters like

  • Region
  • OTAA/ABP
  • Confirmed/Unconfirmed message
  • ...

More details can be found in the WisBlock Toolbox ⤴️

The device is advertising over BLE only the first 30 seconds after power up and then again for 15 seconds after wakeup for measurements. The device is advertising as MHC-WL-xx where xx is the BLE MAC address of the device.

2) Setup over USB port

Using the AT command interface the WisBlock can be setup over the USB port.

A detailed manual for the AT commands are in AT-Commands.md ⤴️

Here is an example for the typical AT commands required to get the device ready (EUI's and Keys are examples):

// Setup AppEUI
AT+APPEUI=70b3d57ed00201e1
// Setup DevEUI
AT+DEVEUI=ac1f09fffe03efdc
// Setup AppKey
AT+APPKEY=2b84e0b09b68e5cb42176fe753dcee79
// Set automatic send frequency in seconds
AT+SENDFREQ=60
// Set data rate
AT+DR=3
// Set LoRaWAN region (here US915)
AT+BAND=8
// Reset node to save the new parameters
ATZ
// After reboot, start join request
AT+JOIN=1,1,8,10

REMARK

The AT command format used here is compatible (with a few small differences) with the new RAKWireless AT command standard used in the RAK3172.

3) Hardcoded LoRaWAN settings

void api_set_credentials(void); This informs the API that hard coded LoRaWAN credentials will be used. If credentials are sent over USB or from My nRF Toolbox, the received credentials will be ignored. It is strongly suggest NOT TO USE hard coded credentials to avoid duplicate node definitions
If hard coded LoRaWAN credentials are used, they must be set before this function is called. Example:

g_lorawan_settings.auto_join = false;							// Flag if node joins automatically after reboot
g_lorawan_settings.otaa_enabled = true;							// Flag for OTAA or ABP
memcpy(g_lorawan_settings.node_device_eui, node_device_eui, 8); // OTAA Device EUI MSB
memcpy(g_lorawan_settings.node_app_eui, node_app_eui, 8);		// OTAA Application EUI MSB
memcpy(g_lorawan_settings.node_app_key, node_app_key, 16);		// OTAA Application Key MSB
memcpy(g_lorawan_settings.node_nws_key, node_nws_key, 16);		// ABP Network Session Key MSB
memcpy(g_lorawan_settings.node_apps_key, node_apps_key, 16);	// ABP Application Session key MSB
g_lorawan_settings.node_dev_addr = 0x26021FB4;					// ABP Device Address MSB
g_lorawan_settings.send_repeat_time = 120000;					// Send repeat time in milliseconds: 2 * 60 * 1000 => 2 minutes
g_lorawan_settings.adr_enabled = false;							// Flag for ADR on or off
g_lorawan_settings.public_network = true;						// Flag for public or private network
g_lorawan_settings.duty_cycle_enabled = false;					// Flag to enable duty cycle (validity depends on Region)
g_lorawan_settings.join_trials = 5;								// Number of join retries
g_lorawan_settings.tx_power = 0;								// TX power 0 .. 15 (validity depends on Region)
g_lorawan_settings.data_rate = 3;								// Data rate 0 .. 15 (validity depends on Region)
g_lorawan_settings.lora_class = 0;								// LoRaWAN class 0: A, 2: C, 1: B is not supported
g_lorawan_settings.subband_channels = 1;						// Subband channel selection 1 .. 9
g_lorawan_settings.app_port = 2;								// Data port to send data
g_lorawan_settings.confirmed_msg_enabled = LMH_UNCONFIRMED_MSG; // Flag to enable confirmed messages
g_lorawan_settings.resetRequest = true;							// Command from BLE to reset device
g_lorawan_settings.lora_region = LORAMAC_REGION_AS923_3;		// LoRa region
// Inform API about hard coded LoRaWAN settings
api_set_credentials();

REMARK!
Hard coded credentials must be set in void setup_app(void)!


Packet data format

The packet data is in Cayenne LPP format. Every time the sensor data are collected, they are stored in a structure that is build in a format that most LPWAN servers and Integrations can easily parse. See Dataflow for details of the packet data format.


Compiled output

The compiled files are located in the ./Generated folder. Each successful compiled version is named as
WisBlock_WL_Vx.y.z_YYYY.MM.dd.hh.mm.ss
x.y.z is the version number. The version number is setup in the ./platformio.ini file.
YYYY.MM.dd.hh.mm.ss is the timestamp of the compilation.

The generated .zip file can be used as well to update the device over BLE using either My nRF52 Toolbox repo ⤴️ or Nordic nRF Toolbox ⤴️ or nRF Connect ⤴️


Debug options

Debug output can be controlled by defines in the platformio.ini
LIB_DEBUG controls debug output of the SX126x-Arduino LoRaWAN library

  • 0 -> No debug outpuy
  • 1 -> Library debug output (not recommended, can have influence on timing)

MY_DEBUG controls debug output of the application itself

  • 0 -> No debug outpuy
  • 1 -> Application debug output

CFG_DEBUG controls the debug output of the nRF52 BSP. It is recommended to keep it off

Example for no debug output and maximum power savings:

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
build_flags = 
	; -DCFG_DEBUG=2
	-DSW_VERSION_1=1 ; major version increase on API change / not backwards compatible
	-DSW_VERSION_2=0 ; minor version increase on API change / backward compatible
	-DSW_VERSION_3=0 ; patch version increase on bugfix, no affect on API
	-DLIB_DEBUG=0    ; 0 Disable LoRaWAN debug output
	-DMY_DEBUG=0     ; 0 Disable application debug output
	-DNO_BLE_LED=1   ; 1 Disable blue LED as BLE notificator
lib_deps = 
	beegee-tokyo/SX126x-Arduino
	beegee-tokyo/WisBlock-API
	sparkfun/SparkFun LIS3DH Arduino Library
	pololu/VL53L0X
extra_scripts = pre:rename.py
Owner
Bernd Giesecke
Bernd Giesecke
DIY Zigbee CC2530 Motion sensor (AM312/ AM412/ BS312/ BS412), Temperature /Humidity /Pressure sensor (BME280), Ambient Light sensor (BH1750), 2.9inch e-Paper Module

How to join: If device in FN(factory new) state: Press and hold button (1) for 2-3 seconds, until device start flashing led Wait, in case of successfu

Sergey Koptyakov 5 Feb 13, 2022
DIY Zigbee CC2530 Motion sensor (AM312/ AM412/ BS312/ BS412), Temperature /Humidity /Pressure sensor (BME280), Ambient Light sensor (BH1750), 2.9/2.13/1.54 inch e-Paper Module

How to join: If device in FN(factory new) state: Press and hold button (1) for 2-3 seconds, until device start flashing led Wait, in case of successfu

Sergey Koptyakov 28 Jul 27, 2022
WisBlock API takes care of all the LoRaWAN, BLE, AT command functionality

WisBlock-API Targeting low power consumption, this Arduino library for RAKwireless WisBlock Core modules takes care of all the LoRaWAN, BLE, AT comman

Bernd Giesecke 11 Jul 29, 2022
Techniques based on named pipes for pool overflow exploitation targeting the most recent (and oldest) Windows versions

Table of Contents Table of Contents Introduction Named-Pipes Introduction Exploitation Spraying the non-paged pool Memory Disclosure/Arbitrary Read Co

null 131 Jul 2, 2022
Sandbox binary and source code for the Siggraph 2017 paper "Water Wave Packets" by Stefan Jeschke (NVIDIA) and Chris Wojtan (IST Austria)

----------------------------- Manual for wave packet viewer ----------------------------- System requirements: Windows8/8.1/10 with DirectX runtime e

Stefan Jeschke 35 Feb 10, 2022
Low level library to develop GBA games that can also be built for PC.

Universal GBA Library 1. Introduction This is a library for development of GBA games. It can be used to build actual GBA game ROMs, but it can also ta

Antonio Niño Díaz 33 Jul 31, 2022
RRxIO - Robust Radar Visual/Thermal Inertial Odometry: Robust and accurate state estimation even in challenging visual conditions.

RRxIO - Robust Radar Visual/Thermal Inertial Odometry RRxIO offers robust and accurate state estimation even in challenging visual conditions. RRxIO c

Christopher Doer 56 Jul 26, 2022
High-level interface for low-level programming

Singeli Singeli is now able to compile useful programs to C, but it's very rough around the edges, with poor error reporting. We are beginning to use

Marshall Lochbaum 27 Jun 14, 2022
Sensirion Mass Flow Sensor Arduino library, modified from MyElectrons and Nabilphysics Arduino repositories for SFM3300 Digital Mass Flow Sensor

Sensirion Mass Flow Sensor Arduino library, modified from MyElectrons and Nabilphysics Arduino repositories for SFM3300 Digital Mass Flow Sensor. When the sensor data gets stuck, the library has a hard reset function to ensure that it is read continuously.

Paul Ryan Santiago 3 Apr 11, 2022
My new zigbee project. Wireless temperature and humidity mini sensor with electronic ink display 2.13 inches, low power consumption, compact size, enclosure with magnets.

My new zigbee project. Wireless temperature and humidity mini sensor with electronic ink display 2.13 inches, low power consumption, compact size, enclosure with magnets. The device use SHTC3 sensors, chip CC2530, battery CR2477.

Andrew Lamchenko 13 Feb 22, 2022
multispectral monitoring of a sourdough starter; esp32 eink module, scd30 co2 sensor, vl6180 distance sensor

EINK STARTER MONITOR See full blogpost here Tracks height of starter with a VL6180 i2c distance sensor, and CO2/temperature/humidity with an SCD30. A

AKA 15 Feb 16, 2022
🪴💧 A Bluetooth Low Energy (BLE) soil moisture sensor.

b-parasite b-parasite is an open source Bluetooth Low Energy (BLE) soil moisture and ambient temperature/humidity sensor. Features Soil moisture senso

null 520 Aug 7, 2022
CC2500 Low-Cost Low-Power 2.4 GHz RF Transceiver driver for esp-idf

esp-idf-cc2500 CC2500 Low-Cost Low-Power 2.4 GHz RF Transceiver driver for esp-idf. I ported from this. 2.00mm pitch External Antena 1.27mm pitch PCB

null 3 May 29, 2022
A list of excellent resources for anyone to deepen their understanding with regards to Windows Kernel Exploitation and general low level security.

WinKernel-Resources A list of excellent resources for anyone trying to deepen their understanding with regards to Windows Kernel Exploitation and gene

Vector Security 37 Jun 29, 2022
S2-LP driver library, low-level and easy-to-port

S2-LP Library This library provides a simple way to use S2-LP transciever module. This library is WIP, but mostly done. https://www.st.com/en/wireless

Wojciech Olech 5 Jul 6, 2022
A low level Operating System designed using Linux Kernel

Conqueror A low level Operating System designed using Linux Kernel To develop the basic low level operating system, we need following Virtual Machine

mahendra gandham 8 May 27, 2022
Volatile ELF payloads generator with Metasploit integrations for testing GNU/Linux ecosystems against low-level threats

Revenant Intro This tool combines SCC runtime, rofi, Msfvenom, Ngrok and a dynamic template processor, offering an easy to use interface for compiling

Red Code Labs 54 Aug 10, 2022
Tiny - low-level library for minimizing the size of your types

foonathan/tiny Note: This project is currently WIP, no guarantees are made until an 0.1 release. This project is a C++11 library for putting every las

Jonathan Müller 98 Jul 30, 2022