ESP8266 Water Alert via IFTTT

December 10, 2015

ESP8266 High Water Alarm

I recently had to replace the float valve in the brine tank of our water softener. The first time I tried it, the valve did not close and the water overflowed through the overflow vent, filled the emergency bucket I had placed there, and continued to spread across the floor of our storage area.

I figured it was a bad valve, but after manipulating it a few times, it seemed to work fine. Perhaps it was just stiff because it was new and would now function properly. Nevertheless, I did not trust it and wanted a quick and dirty alarm to tell me if the water in the brine tank rose above its normal range.


Of course, I turned to my favourite little board for Internet of Things connectivity, the ESP8266. These handy little boards are down to $1.50 including shipping from China. The mind boggles at the value.



Pololu has recently added a really handy little board to their line of fine products. The Mini Pushbutton Power Switch with Reverse Voltage Protection, LV version, is a power switch capable of turning on or off any device using either the mini push button on the board or an external on, off, or control signal. It can handle 2.2 to 20 volts at up to 6 amps. It turns out to be very useful for many projects. In this case, I will use it to turn on the ESP8266.

The Sensor

Barely worthy of the name, sensor, in this case, bare wires are hanging in the tank just above the highest level the brine solution should reach. Note that the wires must not touch the edge of the tank as it is conductive due to the old
salt deposits on it.


This is a temporary installation for testing purposes. Once the tank is filled properly, the wires would have to be protected from the salt. It would be easy to put them in a PVC pipe, or even just surround each electrode with some tubing. I will probably do that in a few days, when I am satisfied that the valve and system are doing what they are supposed to do and I refill the tank with crystal salt.

Simple wires work for detecting an overflow situation, but can’t be used for level measurements underwater. Even a small amount of DC current causes electrolysis to occur which will corrode the metal very quickly
and do bad things to drinking water if it causes minerals to precipitate.

The Circuit

The project consists of a battery pack (2 AAA cells), the Pololu 2808 switch, and the ESP8266 board. Any battery pack could be used as long as it does not exceed 3.6 volts. Any of the various ESP8266 boards can be used. This project was built with the cheap and simple ESP-01.



When the brine rises high enough to touch the wires, it closes the sense connection between Vin and the CTRL connection, the switch turns on,
energizing the ESP8266. When the ESP8266 boots, it connects to the internet via WiFi and sends a message to my server. You could use the
IFTTT Maker channel.

The push button on the board can be used to turn on the ESP8266 for testing, and to turn it off once the water level is below the sensor wires.



The boards were connected with hookup wire and hang on the outside of the tank for now, secured by a bulldog clip. They will go into an enclosure later if I decide to keep this sensor in place.

I knew that a salt solution would be conductive enough to trigger the Pololu switch. I was surprised to find the control input worked with the small current that flowed through tap water. This means that the same circuit could be used to detect basement flooding due to a failed sump pump
or a higher than normal water level in a storage tank
. Since almost no current flows in the standby mode, the batteries should last for a very long time.

Software

I am a fan of the simple NodeMCU Lua system that has now been available for over a year. My first project using the ESP8266 and Lua was a pump monitor on our well, which simply reports when the pump is on. That board has been reliably connecting to the server since December 1, 2014 and it has generated a lot of useful information about our water usage.

There have been improvements to the Lua firmware and a great deal has been learned about implementing WiFi solutions on the ESP8266.


The Button
For reliability when quickly building a project like this, it is handy to be able to use well tested software. The same firmware which connects to the local access point,
then links to the server does everything required. The server code takes care of data storage and customized notifications. The Button and a number of other projects use this system. All that needs to be changed is the URL.

Source code is on GitHub

autoconnect.lua

httpget.lua

To download the code to the ESP8266 board, I used LuaLoader for Windows. There are numerous other programs now available to do the job.

If you are an Arduino fan, there is an Arduino firmware installation available for the ESP8266 which can also be used to implement the simple firmware required. The Arduino installation is supported by both sparkfun and Adafruit.

If This Then That – IFTTT

If you do not have your own server, or just want to save a lot of time, the
IFTTT Maker Channel was designed to connect IoT devices, like this monitoring system, to the notification you need.

To use IFTTT, you have to create your own account, then proceed to the Maker Channel to create a Trigger event. IFTTT will give you the URL to enter into the ESP8266 code. The URL will look something like this:

http://maker.ifttt.com/trigger/OVERFLOW/with/key/yourownkey

OVERFLOW is the event trigger name, I have chosen for this event. Yourownkey will be assigned to you the first time you create a new Maker recipe. When the trigger URL is called by the ESP8266, all recipes based on that trigger URL will be executed.

There are hundreds of actions available, including sending emails, SMS messages, adding items to DropBox, adding data to Google Drive spreadsheets, and even sending a message to another ESP8266 equipped with an LED or alarm sound.


If you are new to the ESP8266 or LuaLoader, you may want to look at my

Quick Start Guide to the ESP8266 and LuaLoader

ESP8266 for Dummies


          More Links:

Ask Google for the time with an ESP8266

January 21, 2015

This is an example of how to connect to Google and retrieve just the HEAD information, which happens to include the current time.

It would be possible to do this with NTP, but that would require more coding. The results wouldn’t be any more accurate. I am pretty sure Google keeps the time on their servers well synchronized with the actual time.

— retrieve the current time from Google
— tested on NodeMCU 0.9.5 build 20150108

conn=net.createConnection(net.TCP, 0)

conn:on(“connection”,function(conn, payload)
conn:send(“HEAD / HTTP/1.1\r\n”..
“Host: google.com\r\n”..
“Accept: */*\r\n”..
“User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)”..
“\r\n\r\n”)
end)

conn:on(“receive”, function(conn, payload)
print(‘\nRetrieved in ‘..((tmr.now()-t)/1000)..’ milliseconds’)
print(‘Google says it is ‘..string.sub(payload,string.find(payload,”Date: “)
+6,string.find(payload,”Date: “)+35))
conn:close()
end)
t = tmr.now()
conn:connect(80,’google.com’)

The program can be saved to a file, google.lua. Then, dofile(‘google.lua’) will retrieve and print the time. From this location, the normal elapsed time from requesting to printing was under one tenth of a second. Pretty good.

google

Simple scripts like this are easy to enter and test with LuaLoader.

Using the ESP8266 as a power monitor

November 23, 2014

I needed a simple way to monitor the pump on our well.

Once in a while, something goes wrong and it fails to run. We don’t notice until the holding tank empties and there is no water. Then we have to go figure out what happened – breaker problem, switch problem, power bill not paid, etc…

Other times, like last month, the pump remains on 24/7 and the water overflows the tank until someone notices. It took 35 days at 2KW before anyone noticed. $400 electric bill!!!!! The well and tank are not visible or even easily accessible from the house.

Seems like a good application for the esp8266.

A 3.3 volt wallwart is connected in parallel with the pump relay to power the esp8266 in a waterproof box. It couldn’t be any simpler.

Wallwart and ESP8266. That's all it takes!

When power is on, it pings a php script on my webserver. A simple program that logs the times and reports by email if the pump hasn’t run for more than 24 hours, or if it has run for more than 2 hours straight. Normal operation is an hour a day.

Inspired by Mark and Xavi’s How to use ESP8266 ESP-01 as a SENSOR web client post, I decided to use Lua for this quick job.

On the esp8266 set up the AP SSID and password as usual and run benlo.lua every 30 seconds when the power is on.


wifi.setmode(wifi.STATION)
wifi.sta.config('SSID','password')

Check with print(wifi.sta.getip()).

This is conveniently stored permanently in flash memory!

Setup for feeding over a serial terminal to the Lua prompt (is there a better way?)


file.remove('benlo.lua')
file.open('benlo.lua','w')
file.writeline([[conn=net.createConnection(net.TCP, 0) ]])
file.writeline([[conn:on("receive", function(conn, payload) print(payload) end) ]])
file.writeline([[conn:connect(80,'se.rv.er.ip') ]])
file.writeline([[conn:send("GET /yourscript.php HTTP/1.1\r\n") ]])
file.writeline([[conn:send("Host: yourserver.com\r\n") ]])
file.writeline([[conn:send("Accept: */*\r\n") ]])
file.writeline([[conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") ]])
file.writeline([[conn:send("\r\n") ]])
file.writeline([[tmr.alarm(30000, 0, function() dofile('benlo.lua') end )]])
file.close()

As you can see, this script just connects to the web server once every 30 seconds when the power is present.

The output from the webserver script gets sent to the UART if the computer is connected. Otherwise, it just blinks the blue LED on the board, giving visual feedback of successful operation.

To start on power up, init.lua waits 10 seconds for the connection to the WiFi AP and starts benlo.lua


file.remove('init.lua')
file.open('init.lua','w')
file.writeline([[print('Peter LUA module 0.1')]])
file.writeline([[tmr.alarm(10000, 0, function() dofile('benlo.lua') end )]])
file.close()

I suppose, benlo.lua could just be incorporated into init.lua, but I like the idea of keeping it separate.

Just what I needed.

Thanks and kudos to the developers who put up the Lua code, it was pretty easy to craft this in an afternoon without knowing anything about Lua or the esp8266.

Feedback on dumb things I am doing would be useful. Just starting out…

Links:
My ESP8266 Posts at benlo.com
Mark and Xavi’s Post on using Lua
NodeMCU Lua Developmen
ESP8266 Forum with Lua Threads

Peter’s Nomadness in the Andes

May 11, 2013

Time for a little rambling in South America.  I have been wandering about in Colombia and Ecuador for the past couple of months.

 

Here are some slides from Colombia:

Look for more photos and ramblings on my Nomadness Web Site.

 

 

GoPro Camera Video Monitor Adapter

January 28, 2013

GoPro Video Monitor Adapter

Cam-Do.com has introduced the GoPro Video Monitor Adapter.

The adapter plugs into the Hero Bus connector on the back of all HD Hero, Hero 2, and Hero 3 White, Silver and Black cameras.

Output is 480i SD video compatible with LCD and CRT monitors as well as all video transmitters and receivers.

The video displayed is a real time image of what the camera sees, giving the photographer better control of framing and setup. Transmitted video can be used for FPV transmissions from R/C planes and quadcopters while the camera is capturing HD video.

WiGo – GoPro WiFi App for Windows

October 28, 2012

ImageW

 

WiGo is a Windows application that connects to GoPro cameras with a WiFi BacPac.

The app can be used to control the camera settings, preview images, and download photos and videos from the SD card directly to the PC.

WiGo is available for download from Cam-Do.com.

Enjoy.

GoPro Programmable Scheduler

September 5, 2012

 Image

I finally finished the code for the GoPro Programmable Scheduler. It’s up on the cam-do.com website for early ordering now.

This should be a good product with lots of applications for time lapse photography and event video where the camera can be set up ahead of time with a schedule for shooting later in the day or week.

Check it out at www.cam-do.com/GoProScheduler.html

GoPro Camera Controller adds flexibility

July 10, 2012

GoPro Camera Controller adds flexibility

I’ve been working on the GoPro camera controller board using an MSP430 to control the camera for time lapse or triggering with diverse sources.

 

 

http://cam-do.com/GoProTimeController.html

Perhaps the most fun was interfacing the controller to my mobile phone using the audio from the headphone jack.

http://cam-do.com/webcam/AudioTrigger.html

Night Sky is an instant hit

November 25, 2009
Night Sky

Night sky chart on iPhone

Since Apple announced the availability of Night Sky for the iPhone and iPod Touch, the traffic on the site has been phenomenal.

Check it out yourself at mwebapp.com/nightsky.

Pocket Guide to World History on the iPhone

September 24, 2009

We are very excited that Apple has featured our Pocket Guide to World History on their web applications site.

Since then we have had thousands of readers from around the world. It is so exciting to see readers enjoying our work and asking for the iPhone App and ebooks which will be available soon.