Intro
My boat is moored in Portugal. Since I'm not there all the time, I wanted something that would keep an eye on it for me, and warn me if there was anything afoot.I have been playing with Raspberry and Arduino before, so that is immediately what sprung to mind. However, after toying with the idea for a while, I found another board even more suited for what I had in mind: the ESP8266.
The ESP8266 (and the ESP32, its successor) is like an arduino, except that it comes out of the box with WIFI. So it is a very good choice for any project where sending data is involved.
It has an additionnal feature, which makes almost the only possible candidate in my case: the WIFI only draws 200mAh at full sending power, down to 20µAh (!) in deep sleep. Deep sleeps makes your power drawing up to 10000 times less (!)- on average, it multiplies the autonomy of your battery by at least 50. Icing on the cake, the ESP is very cheap, less than €10 /piece, and after the initial setup, you can upgrade its firmware over the air.
(very summary) Comparison with other boards: | |
---|---|
Raspberry zero | Considering its low consumption (depending on the source, from 150mAh to 300mAh), the Zero is a good candidate. Drawbacks: can't be put into deep sleep to save energy, no update over the air, marginally more expensive.(Also I haven't found a place where you can buy more than 1 at a time) |
Arduino | Drawbacks: lack of wifi integration off the shelf, marginally more expensive, no deep sleep, no OtA update. |
Arduino Uno wifi | more elaborate, but twice the price and don't need extra features, no deep sleep, no OtA update. |
Feather huzzah | basically same as ESP32, based on esp8266; draws 500mAh, marginally more expensive, no deep sleep, no OtA update. |
Project
So the idea was very simple:- have a sensor get the temperature
- have a sensor get the humidity
- possibly have a gps to tell me if the boat had moved
- send the data to me if the value are outside given parameters
I finally added to the project a 4a) "send data to a database", because I thought it might be interesting to keep a trace of what was going on.
I found a sensor that does both humidity and temperature (DHT11/22), simplifying my life a lot, and also diminishing power consumption.
So there it is, very simple: humidity and temperature are polled at regular intervals, posted on Telegram, and sent to the web site. In between polling the board goes into deep sleep to save energy, as it works on batteries. The system is powered by a 18650 2500mA rechargeable battery. Battery level is monitored with longer and longer deep sleep intervals as level goes down. If the values are outside boundaries, it sends a notification email too and makes a special post on Telegram. Values can be displayed at any time from the website.
Planned for V.2.0: OtA update; GPS module.
Hardware
Links are not an endorsement of the product and just provided for convenience sake. I get not cut.
That said, I do have a good experience with AZ-Delivery in Germany. They are reasonably cheap and very fast. They also have a quite complete free library (registration required) in several languages. The pdfs in the library contain all the information you need to get started, say with the ESP32.
Total cost (Aug. 2020):
- ESP8266: 8€
- DHT22 4€
- battery casing 4€
- batteries 3€
- total=19€
GPS is 10€.
Some comments:
I have worked both with the ESP32 and the ESP8266. They are (very) broadly the same, but don't use the same libraries, so you can't take one for the other in the Arduino IDE. For this project (boat monitoring) I used the 8266. For another monitoring project I started with an ESP32, thinking of adding a camera (OV7670, 6€), but I soon realized it would be simpler and cheaper to swap the esp32 for an esp32-cam. For that project I couldn't use a 8266 because it doesn't have enough space to store the picture before sending it. The ESP32 has several major improvements over the 8266, but they were not relevant for my project. (* The ESP32-CAM is an ESP32 coupled with an OV2640 and a card reader. However, it does NOT have a usb port, so you need an FDTI programmer, which costs around €10).After installing the IDE, the first thing to do is to download the respective libraries for each and install them. For the ESP32, I unzipped a package at the right place, and everything appeared (and removed a library that was giving errors). For the ESP8266 there is an extra step: you need to add the proper url in the preferences, then go to "add board" and download the package, then your board will appear. I used "ESP32 dev board" and "NodeMCU 1.0 (E12)" respectively.
For the rest, it is quite simple, really. I looked at examples found on the net and wrote my own stuff or cut and pasted. For the DHT reading for example, all you need is in the sample code provided with the library. Once I had that working, I added the wifi code, then the email/telegram and finally data sending to the web site. I kept that one for the end since I also needed to write a php program on the server to receive, store and display data.
In fact, the only advice I can give you is to first think about the software, and buy the hardware accordingly. Ok, the sensor XXZZYY is €0.02 cheaper, but by paying this extra €0.02 for the DHT, you'll save yourself hours of research and coding. So cheap hardware, yes, obscure - no. (Another good example of this is what happened in this project. If I had known, I would have bought a SSD1306 screen!)
Also for the ESP chip itself: They are several producers of all kind (the NodeMCU design is open source), so you will find them in all sizes and shapes, at various prices. The main difference is usually the number of pins, but also consumption, and whether you need a programmer. Install the IDE, have a look at the existing libraries, and then go drool into your favorite shop. At least the names will (hopefully) ring a bell and you'll buy accordingly.
The main tricky part in the project (and incidently a big thanks to Claude for drawing my attention to it and his explanations), and the reason a board like the ESP[8266|32] is needed, is power consumption, something usually taken for granted. Here the sensor will be on its own for weeks on end, so it is paramount that it has enough energy. But if you do the math, you'll see that a simple board usually draws 200 mAh per hour. This means that your regular 2000 mAh battery will last 10h. Even if you find a super heavy duty 8500 mAh battery, that will give you 43h at best, so not even two days. By bringing average consumption down to 2 mAh, my 2000 mAh battery suddenly gives me an autonomy of 41.6 days, ie almost 6 weeks. Using deep sleep requires additionnal wiring to work. If you can't do that, you can still use light sleep which is software-only and will reduce consumption to less than half a mAh. As those functions work by switching the modem off, they live in the WIFI library. Finally, the first version of the library allowed DeepSleep for 71 minutes, but since SDK version 2.1 you can actually deepsleep 3h45 minutes. Better take a margin, because as seen on the picture above, the MaxLength reported by the chip itself is obviously influenced by temperature, etc.
Of course there is also the fact that those chips have very limited resources, like saving space or memory, but that is par for the course. Having started programming a long time ago when computers didn't have gigabytes of memory (or megabytes for that matter), it was more a matter of remembering how to squeeze the last k by shifting variables from the stack to the heap or finding memory saving tricks!
For windows, don't forget you need the CP2102 driver or the CH340 depending on your chip.
You can find this type of services on the internet, usually with a fancier package, for about €700 (cheapest: sailsense, boatsecure) to several thousand...