owned this note
owned this note
Published
Linked with GitHub
# fl222mx - My IoT Tutorial
## Tutorial on how to build a Pool monitoring system powered by a PyCom LoPy4.
- [X] Your name and student credentials
Author: Fredric Luthman (fl222mx), Linneaus University
- [X] Short project overview
There are some aspects of an in ground swimming pool that has to be monitored to ensure the longevity of the pool as well as the safety of the users. Some of these are temperature, chlorine level, pH, water level, status of pump(s) and heater(s).
Some of these are harder to monitor than others. Probes and sensors for chlorine and pH are quite expensive and need periodic calibration in order for them to provide a real value. You also need to connect to the circulation system which requires plumbing work. For an IoT connected pool monitoring system, it might be better to start with the other aspects, which can ultimately give you exciting insights into the thermodynamics involved in the swimming pool.
- [X] How much time it might take to do (approximation)
Estimation of time to complete:
* Basic hardware and IDE setup, 1 hour
* IoT Connectivity (Platform, Dashboard), 2 hours
* Sensor setup, 1 hour
* Bench test, 1 hour
* 3D printing of the housing, TBD (still printing)
* On site installation, 3 hours
### Objective
- [X] Why you chose the project
After many years of hard work and thriftful living, my wife and I fulfilled a lifelong dream of owning a swimming pool in 2018. Since then we have had some incidents which gave me some ideas of what needs to be monitored and automated. Anything bearing prefix or suffix of "pool" is expensive. Historically I think this depends on the fact that owning a swimming a pool has been reserved for the rich and famous.
These days, this is no longer the case, since many people nowadays can afford to put in a pool. Therefore, I think there is a need for a less expensive pool monitoring system.
For the initial increment of this project I have decided to limit the scope to monitoring the following: temperature and water levels.
#### Why monitor water levels?
For an inground pool, two water levels are of particular interest:
* Pool water level
* Sump water level
##### Pool water level
The pool water level is essential. If it is too high it might risk the structural integrity of the pool and also might cause an overflow. It also reduces the effectiveness of the filtration system. If the water level is too low, however, it might lead to the pump running dry which can cause premature failure or even a fire in the worst case scenario. Since my pool is covered, the risk of a too high water level is minimal so I have chosen to only monitor a low water level. If the water level is too low, water has to be added to the pool. Some water loss is normal during the operation of the pool. Some water loss will occur due to evaporation (this is minimized through the use of a pool cover) and some water will also be lost when backwashing the filter (this can be reduced by observing good hygiene practices before swimming, i.e. take a shower and soap up!).
##### Sump water level
The sump is where the french drain is typically connected. For an in ground pool, a sump pump is used to pump out the water flowing in from the french drain around the bottom of the pool. You do this to avoid damage to the pool. If the sump pump stops working or cannot cope with the output from the french drain, the water level in the sump will quickly rise. This is a scenario I am monitoring for in this project.
#### Why monitor temperatures?
There are several reasons to monitor temperatures when you have a pool. In order to safely hibernate the pool during the off season (typically end of september to mid april), the water temperature needs to be below 10°C. Below 10°C, the circulation and filtration can be turned off and the pool can then be winterized. An inground pool takes quite some time to reach this level, so it is convenient to get a notification of this. Also, for a liner pool, the water temperature should not exceed 29°C for a long period of time, as that might harm the liner. The pool heater lacks intelligence and only works with a set temperature, if the temperature is below the set temperature, the heater is active.
During the summer of 2020, there was a heat wave lasting for almost two weeks where the temperature typically rose above the maximum desired temperatures most days due to the green house effect of the pool cover.
- [X] What insights you think it will give
With data for water temperature and ambient temperature, I can begin to model the passive cooling and heating of the pool.
- [X] What purpose does it serve
My long time goal with the project is to use machine learning to better optimize the heater and general operation of the pool. I am a long ways away from this, but the first step is to collect data. Water level data can be used to try to optimize the use of fresh water resources due to evaporation and maintenance. The data might also provide insights into the utilization of the pool.
### Material
The basis for the project is a LoPy 4 from PyCom. Added to this are the relevant sensors and accessories needed to connect them.
Explain all material that is needed. All sensors, where you bought them and their specifications. Please also provide pictures of what you have bought and what you are using.
- [X] List of material
- [X] Where you bought them and how much they cost
#### Material list
| Name | Quantity | Cost | Place of Purchase |
| --------------------- | -------- | --------- | ----------------- |
| LoPy4 | 1 | €34.95 | Pycom |
| Expansion Board 3.0 | 1 | €16 | Pycom |
| LoRa Antenna | 1 | €9.00 | Pycom |
| Micro USB Cable | 1 | Free | Desk drawer |
| DHT11 Sensor | 1 | 49 SEK | Electrokit |
| Liquid Level Switch | 2 | 59 SEK | Kjell |
| DS18B20 Sensor | 2 | 59-99 SEK | Electrokit |
| 5mm LED Red and Green | 1 of ea | Free | Desk drawer |
| 3.5mm phono jack | 2 | Free | Desk drawer |
| 3.5mm phono plug | 2 | Free | Desk drawer |
| Velleman G738 Box | 1 | Free | Desk drawer |
| Breadboard | 1 | 59 SEK | Electrokit |
| Jumper cables | Many | Free | Desk drawer |
| The Things Indoor Gateway| 1 | 79 EUR | Connected Things |
| Sensor Cable ELQXBE | 100m | 699 SEK | Kjell |
- [ ] What the different things (sensors, wires, controllers) do - short specifications
##### LoPy4
The LoPy4 is a multi mode transceiver with Wi-Fi, Bluetooth® , LoRa® and SigFox®. Based on the ESP32 and running MicroPython with many digital and analog inputs. This is the brains of the project and it handles all I/O, locally and to the cloud via LoRa.

Fig. 1. LoPy4 with headers. Pycom.io
##### Expansion Board
The expansion board is used as a shield for the LoPy4 and it is here all external sensors, LED:s and switches are connected to.

Fig. 2. PyCom Expansion Board. Pycom.io
##### DHT11 Digital Temperature and Humidity Sensor
The DHT11 is a digital temperature and humidity sensor. It has one data pin, ground and V~cc~. The sensor can operate on 3.0 to 5V and has a range of 0-50°C. Make sure to connect the data pin correctly. In my experience, the DHT11 should be fairly close to the device.
##### Onewire Temperature Sensor
The DS18B20 is a digital temperature sensor using the Onewire bus. It has one data pin, ground and V~cc~. The sensor can operate on 3.0 to 5V and has a range of -55°C to +125°C. Make sure to connect the data pin correctly and if you use more than one sensor you have to carefully construct your onewire network. One benefit is that you can have quite long cable runs with onewire.
##### Liquid Level Float Switch Sensor
This must be mounted vertically, preferably in a perforated pipe, which allows the water level to equalize with the surroundings (check out communicating vessels for the scientific theory).

I intend to 3D print a mount for this fitting inside a 32MM PVC pipe. The sensor has a bolt and nut which mounts through a 8mm hole.
###### 3D Model of Float Switch Sensor Holder

Fig. 4. Fusion 360 model.
###### 3D Model of Float Switch Sensor Holder

Fig. 6. Finished 3D print.
- [X] Steps that you needed to do for your computer. Installation of Node.js, extra drivers, etc.
### Computer setup
For this project I used a HP Z210 workstation running 64-bit Microsoft Windows 10 (version 18363.900). For communicating with the LoPy device, I used Atom along with the PyMakr extension for IDE. I followed these steps to get up and running:
#### Expansion board firmware update
I followed the instructions on https://docs.pycom.io/pytrackpysense/installation/firmware/, I used the following tools:
* Zadiq, http://zadig.akeo.ie/ used for installing drivers needed for DFU (Device Firmware Upgrade).
* DFU-util, http://dfu-util.sourceforge.net/releases/dfu-util-0.9-win64.zip used for installing the actual Expansion Board Firmware.
One thing to note is that it is quite tricky to get the correct drivers installed. You only have seven seconds and you should really have three arms to do this procedure. If possible, ask a friend to assist you. One person can handle the device itself (Note: do not have the LoPy4 installed when upgrading the Expansion Board Firmware), i.e. plugging in / out the USB cable and pressing the button. The other person controls the mouse / trackpad and pushes install driver when prompted. I had to do several attempts before I got this to work.
#### PyCom Firmware Updater
In order to get the best experience, it is almost always a good idea to upgrade the firmware to the latest stable version. For the LoPy, this is done with the PyCom Firmware updater, using the LoPy installed in the upgraded expansion board. It is important to orient the LoPy so that the PyCom text on both the LoPy and the Expansion Board is facing the same way. As opposed to the DFU, the LoPy firmware was easy to upgrade and I used:
* Firmware: 1.20.2.rc9
* Pybytes: 1.5.0
After this I set up my device at PyBytes using the firmware update tool. I had some issues with getting my board connected to Wi-Fi and it turned out that the devices (currently) cannot handle white-spaces in the SSID, so I had to change my SSID on my Wi-Fi.
- [X] Chosen IDE
#### Atom and PyMakr
This was the first time I used the IDE Atom (https://atom.io/download/windows_x64). I briefly tried Visual Studio Code, but for my PyCom I thought Atom was the better fit for me. It was an excellent experience and I was up and running in a very short time. PyMakr is installed from within Atom and required very little effort. I began with a simple Hello World in the Atom REPL interface, you can run code directly from the terminal to try out simple things. You can also run a single Python file directly from the Atom IDE by pressing the Play button. For more complex projects using a library (most sensors use some kind of library), you have to press the Upload button to make sure that the code gets uploaded correctly. The start file should be called main.py and any libraries should be in the subfolder lib. This is very important!

Fig. 7. A look at how the REPL interface in Atom looks.
- [X] How the code is uploaded
##### Options for uploading the code
It is possibe to run code in many ways, as I have mentioned. The easiest is to connect to the PyCom device through USB connected to the expansion board. I have also used FTP. Here it is important to note that you must use Passive Mode, no encryption. I used the FileZilla Client (https://filezilla-project.org/download.php?type=client). In order to get the IP address of the Wi-Fi, you can use these commands in the REPL interface:
```python=
from network import WLAN
wl = WLAN()
wl.ifconfig()
```
If you haven't got a working USB connection, it is usually also possible to find out the IP address in the router's DHCP client list. If you are having problems, check out: https://forum.pycom.io/
### Putting everything together
#### Prototyping
For prototype work, I used a breadboard. I used the GPIO:s on the expansion board. In the circuit diagram (breadboard drawn in TinkerCAD) below. I Tried doing a better job in AutoDesk Fusion 360, but I was missing too many parts and didn't have time to make custom ones.
- [X] Circuit diagram (can be hand drawn)

Fig. 8. Crude wiring diagram.
The DHT11 and DS18B20 is S1 and S2 in the diagram. SW1 represents the Float Switch.

Fig. 9. Picture showing the breadboard setup.
#### Moving to the real world.
My projects' practical implementation requires some fairly long cable runs. The LoPy4 has a V~cc~ of 3.3V, this in combination with long cables can be problematic. The longest run is to the Liquid Level Switch Sensor placed in the sump. This sensor is of NO (Normally Opened) type and connected to GND and P TBD. When the water level in the sump reaches the maximum threshold, the float reed switch closes the circuit, connecting GND and P TBD.
I used a Velleman box I had lying around and the router tool on my Dremel to cut a hole for the USB cable. I drilled holes for the antenna using a 6mm drill bit and holes for the LED:s using a 5mm drill bit. The 3.5mm phono jacks took a 6mm drill bit.

Fig. 10. Some Dremel action done on the extractor fan, using safety glasses and a face mask.
The red and green LED:s indicate the following:
* Red and Green, initializing
* Red, Sump overflowing
* Green, Sump nominal
- [X] *Electrical calculations
#### Electrical calculations
Since I am using long runs of cable, it is important to consider voltage drop. Using Ohm's Law, $I=\frac{V}{R}$, it is possible to calculate the voltage drop for the given length of cable.

Fig. 11. Schematic description of Ohm's law.
The voltage drop in the cable is equivalent to the voltage drop over the resistor R. Solving for V, this gives that $V={I}*{R}$, where R is the resistance of the cable. The specifications of the cable is 95,9 Ω/km (http://draka.se/cables/elqxbe-pure-100-v/). With the following equation, it is possible to calculate the Voltage drop.
$$
V~drop~ = I~wire~(A)*\frac{2*L(m)*R~wire~(Ω/km)}{1000(m/km)}
$$
##### Voltage Drop Sump Water Level Sensor
Given the above equation and with my parameters I got a voltage drop of 0.5V, measuring the drop with my simple multimeter Xiole XL830L I measured of drop of 0.6V. Still this should not be an issue with the water level sensors. I couldn't find any specifications of the ranges the PyCom GPIO pins would detect a digital zero or a digital one.
##### Resistors for the driving Sump Status LED:s
For my 5 mm red and green LED:s, I needed to find suitable resistors for use with the PyCom Expansion boards 3,3V~cc~ output. Using Ohm's law, $R=\frac{3.3}{0.015} => R=220Ω$. I only had 210Ω at hand so I used those, which resulted in a forward current I~F~ of 15.7mA which is tolerable for my LED:s.
##### Power Budget
According to the Pin Out diagram for the PyCom LoPy4, the maximum available power on the 3V3 is 1.2A. From my own findings during this project, it seems like an exaggerated figure. From the LoPy4:s datasheet 400 mA is mentioned. I had originally intended to use five status LED:s. I ended up using only two, since the two LED:s were pushing the limit for the board resulting in some unreliable performance. The main problem was with the Onewire sensor that would sometimes stop working.
* LED:s, 2*16 mA
* Temperature Sensor, DS18B20, 2*20 mA.
* Temperature / Hygrometer, DHT11, 2.5 mA.
* Water Level Sensor in the sump, 22 mA.
I~MAX~ = 98,5 mA (from 3V3).
### Platform
I use a free instance of Ubidots which is cloudbased. It has an integration with The Things Network to which my data is transmitted over LoraWAN. I have also experimented with PyBytes, but I found that dashboard to be too limited for my application.
- [X] Describe platform in terms of functionality
- [X] *Explain and elaborate what made you choose this platform
I originally intended to use a local solution based on the Telegraf, InfluxDB, Grafana. I have a linux server running Unraid on which I installed the TIG Stack. The hardware is quite old and didn't quite have the performance to run this and I ended up using Ubidots instead since there was a ready made integration from The Things Network.
### The code
Import your code here, and don't forget to explain what you have done!
```python=
import pycom
import time
from network import LoRa
import socket
import time
import ubinascii
from machine import Pin
from machine import Timer
from dth import DTH #DTH from dth library
from onewire import DS18X20 #Library for dealing with DS18X20 sensors
from onewire import OneWire #Library for Onewire
import cayenneLPP #Library for sending sensor data over LoRa
timebetweentransmissions = 1800 # Wait 30 minutes between timed transmissions
th = DTH(Pin('P23', mode=Pin.OPEN_DRAIN),0) #Create an object called th which is an instance of DTH using P23
result = th.read() #Read temperature and humidity from DHT11 sensor
ow = OneWire(Pin('P10')) #Create an object for interfacing through onewire on P10
temp = DS18X20(ow) #Create on object for temperature from DS18B20 with onewire
owtemp = temp.read_temp_async() #Read the temperature value from DS18B20
temp.start_conversion() #This is called for reading the temperature
print("DHT11 - Temperature at boot-up: %d C" % result.temperature) #Output the DHT11 temperature at boot-up
print("DHT11 - Humidity at boot-up: %d %%" % result.humidity) #Output the DHT11 humidity at boot-up
print("DS18B20 - Temperature at boot-up: %d C" % owtemp) #Output the DS18B20 temperature at boot-up
sumpoverflow = Pin("P14", mode=Pin.IN, pull=Pin.PULL_UP) #Create object with internal pull up connected to P14 for the float switch sensor
sumpledred = Pin('P9', mode=Pin.OUT) #Create a object for the sump pver flow warning led
sumpledgreen = Pin('P8', mode=Pin.OUT) #Create a object for the sump pver flow warning led
#Set both leds on to indicate initialise
sumpledgreen.value(1)
sumpledred.value(1)
# Initialise LoRa in LORAWAN mode.
# Please pick the region that matches where you are using the device:
# Asia = LoRa.AS923
# Australia = LoRa.AU915
# Europe = LoRa.EU868
# United States = LoRa.US915
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
# create an OTAA authentication parameters
app_eui = ubinascii.unhexlify('70B3D57ED003087C')
app_key = ubinascii.unhexlify('CFD57D47943DC4972ED28CDBBB6BD870')
# join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
# wait until the module has joined the network
while not lora.has_joined():
time.sleep(2.5)
print('Not yet joined...')
# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
# make the socket non-blocking
s.setblocking(False)
lpp = cayenneLPP.CayenneLPP(size = 100, sock = s) #lpp is a object for CayenneLPP payloads
chrono = Timer.Chrono() #Create a Chrono object from Timer to measure time
chrono.start() #Start measuring time
temp.start_conversion()
time.sleep(1) #Wait for onewire net to catch up, minimum 750 ms as per spec
t_ = temp.read_temp_async() #Read and store temperature in local variable
time.sleep(1)
lpp.add_temperature(t_) #Add temperature to Cayenne payload
print("DS18B20 temperature: " + str(t_))
#Check status of sump, toggle LED:s and add it to the payload
sumpoverflow_value = sumpoverflow() #Get the current state of the button, 1 is not pressed, 0 is pressed
if sumpoverflow_value == 1:
sumpledgreen.value(1)
sumpledred.value(0)
s_ = sumpoverflow_value
elif sumpoverflow_value == 0: #Button has been pressed, send measurements to PyBytes and output to terminal
sumpledgreen.value(0)
sumpledred.value(1)
s_ = sumpoverflow_value
lpp.add_digital_input(s_) #Add the float sensor value to the payload
#Send payload to TTN
lpp.send(reset_payload = True)
time.sleep(5)
warningsent = False
#Main loop for sending measurements, time based or triggered by the float switch sensor
while True:
#Read float switch value
sumpoverflow_value = sumpoverflow() #Get the current state of the float switch, 1 is not overflow, 0 is overflow
elapsed_seconds = chrono.read() #Get the elapsed time since start of chrono (or reset)
if sumpoverflow_value == 1 and elapsed_seconds < timebetweentransmissions: #Check if button is not pressed AND that the elapsed time is below threshold
sumpledgreen.value(1)
sumpledred.value(0)
time.sleep(1) #Sleep before next loop
elif sumpoverflow_value == 0 and warningsent == False: #Sensor has been tripped, send measurements to PyBytes and output to terminal
sumpledgreen.value(0)
sumpledred.value(1)
print("Sump Pump Water Level has exceeded the maximum threshold at %f seconds, sending signal to PyBytes" % elapsed_seconds)
result = th.read()
temp.start_conversion()
time.sleep(1)
t_ = temp.read_temp_async() #
t2_ = result.temperature #Machine room temp
s_ = sumpoverflow_value
time.sleep(1)
lpp.add_temperature(t_)
lpp.add_temperature(t2_)
s_ = sumpoverflow_value
lpp.add_digital_input(s_)
print("DS18b20 temperature: " + str(t_))
print("Sump:" + str(s_))
#Transmit Cayenne payload over LoRaWAN
lpp.send(reset_payload = True)
time.sleep(5)
chrono.reset() #Reset chrono for next measurement
warningsent = True #Set flag variable to indicate a sent message
elif elapsed_seconds > timebetweentransmissions: #Timer threshold has been reached, send measurements to PyBytes and output to terminal
print("Idle time out limit reached after %f seconds, sending values to PyBytes" % elapsed_seconds)
result = th.read()
temp.start_conversion()
time.sleep(1)
t_ = temp.read_temp_async() #
t2_ = result.temperature #Machine room temp
s_ = sumpoverflow_value
time.sleep(1)
lpp.add_temperature(t_)
lpp.add_temperature(t2_)
s_ = sumpoverflow_value
lpp.add_digital_input(s_)
print("DS18b20 temperature: " + str(t_))
print("Sump:" + str(s_))
#Transmit Cayenne payload over LoRaWAN
lpp.send(reset_payload = True)
time.sleep(5)
chrono.reset() #Reset chrono for next measurement
warningsent = False
# Explain your code!
```
#### Libraries used:
I used:
CayennneLPP (Creating payloads for TTN), https://github.com/iot-lnu/applied-iot-20/blob/master/network-examples/onewire-cayenneLPP-TTN/lib/CayenneLPP.py
onewire.py (Communicating with the Onewire sensor) https://github.com/iot-lnu/applied-iot-20/blob/master/network-examples/onewire-cayenneLPP-TTN/lib/onewire.py
dht (Communicating with the DHT11 sensor), https://github.com/iot-lnu/applied-iot-20/blob/master/sensor-examples/DHT11-22/lib/dht.py
### Transmitting the data / connectivity
I had never worked with LoRa before this project. Therefore, it was interesting but a bit challening since I am spoiled with bandwidth. Working with LoRaWAN required some reworking on my project in order to minimize the size of the payload and also the frequency of the updates. There is a trade off there, since during development you want more frequent updates in order to spot irratic behaviour and mistakes in your code.
- [X] How often is the data sent?
* On Startup
* Everytime the float switch sensor is triggered, I have a rearm protection, in order to send another alert, 30 minutes must pass.
* Every 30 minutes the sensor values are transmitted.
- [X] Which wireless protocols did you use (WiFi, LoRa, etc ...)?
I used USB, WiFi and LoRa to transmit data and interface with the device. I have no connection to the TTN where I live so I bought my own gateway. I tried getting the local utility company to support TTN in their LoRa network but they use their own solutions.
- [X] Which transport protocols were used (MQTT, webhook, etc ...)
The chain of transmission is like this:
LoRa (LoRaWAN) -> TTN (http) -> Ubidots -> Cellphone (SMS)
- [X] *Elaborate on the design choices regarding data transmission and wireless protocols. That is how your choices affect the device range and battery consumption.
I used CayenneLPP in order to reduce the size of the payloads. It was an easy choice since there was a ready made library for MicroPython and TTN also had a decoder for CayenneLPP. This reduced the time to get my cloud based dashboard up and running and start collecting data.
#### CayeneeLPP transmission
From the [documentation](https://developers.mydevices.com/cayenne/docs/lora/#lora-cayenne-low-power-payload-overview) for CayenneLPP you can see that in order to send data for my current implementation with one float switch and one temperature sensor, the payload structure will look like this
##### Payload structure
According to the the [IPSO Alliance Smart Objects Guidelines](http://www.ipso-alliance.org/), each data type should have it's object ID.
###### Data Type for Temperature Sensor
For a temperature sensor, the IPSO datatype is 3303, the CayenneLPP handles this in a clever way, requiring only one bytes:
*LPP_DATA_TYPE = IPSO_OBJECT_ID - 3200 => 103*
The data uses 2 bytes.
###### Data Type for Digital Input
For a digital input, the IPSO datatype is 3200.
*LPP_DATA_TYPE = IPSO_OBJECT_ID - 3200 => 0*
The data uses 1 bytes.
The payload structure and size for my two sensors are therefore as follows:
| Data1 Ch. | Data1 Type | Data1 | Data2 Ch. | Data2 Type | Data2 |
| --------- | ------| ------ | --------- | ---------- | ----- |
| 1 byte | 1 byte| 2 bytes| 1 byte | 1 byte | 1 byte|
The total size is 7 bytes. This can be compared to the 8 bytes the standard signal for a temperature sensor required when transmitting to PyBytes. For a low bandwidth network, such as LoRa, where there are payload size restriction, this is a considerable improvement.
#### Power consumption considerations
Since I use mains power, I didn't have to optimize power consumtion, however, I think I will look into this for my next project which will be battery and solar operated. This project will be an off grid presence detection for a sport facility. There is no utility power and cellphone reception is spotty. I hope to put up a gateway 2 km away, where there is both power and Internet.
### Presenting the data
I built the dashboard using Ubidot widgets. At the moment I have a graph showing the pool temperature over time and a representation of the status of the sump. The sump is green when everything is alright and turns red when the sump is overflowing. My free STEM account at Ubidots saves the data for one month, but there is also an option to download your data. In order to work on future improvements I will continue investigating using my own local solution.
- [X] Provide visual examples on how the dashboard looks. Pictures needed.

Fig. 12. Picture of Ubidots Dashboard.
- [X] How often is data saved in the database
- [X] *Explain your choice of database
The data is transmitted every 30 minutes or when the float switch sensors are triggered. The database was provided by Ubidots so I had no options here, but for future projects I want to have the option of using a local database to preserve my data. In order to do this, I have started experimenting with a [InfluxDB](https://www.influxdata.com/). For previous projects I have used a local [SQLite](https://www.sqlite.org/index.html) database. I think Influx is more adapted to IoT use with sensors and fits nicely into the Telegraf, InfluxDB, Grafana stack (TIG-stack).
- [X] *Automation/triggers of the data
#### Cloud triggers
If the float sensor in the sump detects a water level above the set value for more than 15 seconds a notification is sent to my cellphone.
#### Local triggers
I have a [Nexa WBT-912](https://nexa.se/smarta-hem/systemnexa/inbyggnadssandare/wbt912) which will propagate actions to my Home Automation system. This is connected to a two digital output on the LoPy. The first channel is for triggering the future redundant sump pump. I need a check valve to prevent backwash between the pumps, so this will have to be a future improvement. This pump will be placed above the first one and triggered by the sensor.The second channel is used for shutting down the pool's circulation pump in the event of too low water level, detected by the float switch.
### Finalizing the design
Since Corona messed up the delivery of my 3D printer which I got on the very last day, I only managed to finish the sensor holder for the perforated PVC pipe for the sump. The more complicated bracket which will attach to the skimmer will take some more time to finish since this is a mated screw / sink solution.
I think that for my intended application, it would be better to have a 5V solution for the sensors, but since the LoPy cannot handle 5V signals this would have required additional hardware which I presently don't have. I will look into this in the future. I see my finished result as a decent proof of concept and a great learning experience. It was interesting using LoRa even though I would have gotten away with Wi-Fi.
- [X] Show final results of the project
A short video of the finished table top result showing the boot up sequence and the first transmissions to the TTN: {%youtube -cg2tqnD6Lg %}
- [X] Pictures
Below is an image and a video showing me triggering the float switch sensor on the device and what happens on the dashboard at Ubidots.

{%youtube wLnx_2_s3zU %}