My name is Greger Gustafsson and I have chosen to call my project Honey maximizer.

Overview
What are IoT: In short, the Internet of Things refers to the rapidly growing network of connected objects that are able to collect and exchange data in real time using embedded sensors.

In order to collect as much honey as possible, it is important that the bees live in their hive in the best environment possible. Therefore, I will monitor the environment in the hive and send the data on to the internet and present it there in the form of a graph.


Fig. 1 The sensor are connected to an esp32 board, which is connected to the internet.

Time To Complete
This project should take approximately 20 hours over a period of 4 weeks to implement.

Hardware
Software
Connectivity
Server
Presentation
Start project
Project plan Honey maximizer


Fig. 2 Project plan Källa: https://www.wenell.se/projektmodell-start/projektmodell/dokumentmallar/

Objective
I have had bees for a couple of years now and have always wanted to be able to monitor the environment for them and that is why I have chosen to do so in this project. The bees cover a radius of about 4 km from the hive and visit about four million flowers to make 1 kg of honey.
The purpose of this project is to get more honey for me and the bees. I want to optimize the environment in the hive so the bees can be as productive as possible.The bees should love their hive.
:bulb: The insight I will gain I think is that this can be used for more than just maximizing honey production. Maybe I can prevent bee swarms, prevent bee deaths in winter etc.
Material

In this project I have chosen to work with the ESP32 device.

The device has many digital and analog input and outputs and is well suited for an IoT project.


Fig. 3 Material

List of material
Källa: https://sizable.se/C.GWNYC/

Supplier Product Cost Specification
Sizable ESP-Wroom-32 94 sek CPU-board
Sizable DHT11 28 sek Temperature & Humidity Sensor
Sizable Breadboard 34 sek 400 dots
Sizable USB kabel 50 cm 18 sek Micro USB
Batterilagret SAFT Batteri 3,6V med lödbleck 95 sek 2600 mAh Källa: https://www.batterilagret.se/
Kjell built-in box 45 sek Plastic
Total: 314 sek
Computer setup
Macbook and macOS Mojave 10.14.6.

Installing IDE

I tried installing Thonny IDE and it turned out to work well on my Mac.

Go to https://thonny.org and download the installationfile.
Run the file.
Follow the installation wizard to complete the installation process.
You just need to click “Next” and so on.
After completing the installation, open Thonny IDE.
I also installed Vscode and Atom but I used Thonny for this project.

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free.

Atom is a code editor, notepad, and IDE. It’s easy to use, easy to configure, easy to extend, and it offers a great user experience. Atom is is available for free and is open source.

Next step is to download the firmware to you harddisk.

Go to https://micropython.org and click download in the menu.
Click on ESP32 Espressif
Download v1.14 firmware MicroPython
The easiest way code is uploaded to the device is through Thonny.

*Next step is to uppload the firmware to esp32

Open Thonny IDE
Open Interpreter
Open Install or update firmware
Select port in my case com4
Browse to the firmware v1.14 MicroPython
Click Install
Press and hold down the BOOT button for one second.
Release the BOOT button
The update firmware prosess is started
:thumbsup: Success
Now i have installed firmware v1.14 MicroPython in the esp32.

Putting everything together
Connected electronics
Here I describe in detail how I connected everything to esp32 circuit board.


Fig. 4 Circuit diagram

Since I will have the sensor and esp32 in the hive, I have to use a battery. The sensor is connected to GPiO4 on esp32. It has wireless communication via WiFi to the Internet.

The battery has a voltage of 3.6 and is directly connected to esp32. The unit cannot be turned off when the battery is connected. Therefore, it is important that the program is written so that minimal energy consumption is achieved.

Electrical calculations
Often IoT sensors will be designed to operate for their entire life on the original battery, as the cost of replacement is so large.

In this table (Fig. 5), you can see power consumptions from the datasheet of esp32 with information on sleep mode etc.


Fig. 5 datasheet esp32

The energy consumption can be estimated.

Product Active Sleep
Esp32-bord 40 mA 150 uA
DHT11-sensor 0.3mA 60 uA
Total 40.3 mA 210 uA
With readings every hour, the device is powered on for 30 seconds and then go to sleep.

Electrical battery calculations
I have chosen a lithium battery from the company Saft with a capacity of 2600 mAh.


In the graph we can see that the voltage (3.6) is almost constant throughout the life of the battery.

Duration of code execution: 30
Sleep time: 3570
Consumption during code execution: 40.3 mA
Consumption in sleep mode: 210 uA
Power of battery: 2600mAh
Manual calculations
30s⋅
40.3mA+3570s⋅0.21mA/3600s≈0.544mAh
2600mAh/0.544mAh≈4779
h≈199days

Online calculator
Källa: https://www.of-things.de/battery-life-calculator.php

:thumbsup:
The device will probably run for around 199 days and 2 hours.
Its estimated, average power consumption per hour 0.54 mAh

Platform
Describeing the platform in terms of functionality
Datacakes offer: There is no limit to the number of users on the Datacake Cloud. Create workspaces for your customers or projects and invite people. With each device, the templates for common LoRaWAN devices can be used. You can have an individual logo for each tenant, wether company, or project.

Pricing Datacake cloud Källa: https://datacake.co/pricing

1 Free 2 Light 3 Standard 4 Plus
Free for your first 2 devices, 1 Weeks Data Retention 1€ per month & device, 4 Weeks Data Retention, Monthly cancellable 3€ per month & device, 3 Month Data Retention, Monthly cancellable 5€ per month & device, 12 Month Data Retention, Monthly cancellable
Initially, I will choose the free service, but in the long run, a paid service will be needed.

Chosen Datacake to my platform
I have chosen Datacake to my platform for data visualisation because it is easy to use and has a lot of possibilities. Datacake is a cloud solution. This includes the underlying infrastructure, servers and storage, needed for real-time operations and processing for IOT.

There are many IoT platforms to choose from. In order to move forward, a thorough study of the market must be done in order to be able to choose the best one for the purpose.

To scale up this solution, I imagine a solution with LORaWan to move forward because some hives are not close to a WiFI network. It can stand far out in the woods etc.

The code
import machine # Greger Gustafsson 2022-06-26, gg222bk
import dht # Library for the DHT11 Sensor
from machine import Pin # Pin object to configure pins
import urequests as requests #from time import sleep
from time import sleep #from time import sleep

def connect(): import network sta_if = network.WLAN if not sta_if.isconnected(): # Check if already connected print(‘connecting to network…’) sta_if.active(True) # Activate network interface sta_if.connect(‘YOURSSID’, ‘YOURPASSWORD’) # Your WiFi Credential # Check if it is connected otherwise wait while not sta_if.isconnected(): pass print(‘network config:’, sta_if.ifconfig()) # Print the IP assigned by router

connect() # connect to internet
sensor = dht.DHT11)
temp=100 # Dummy tempdata
while True: try: sleep(2) sensor.measure() temp = sensor.temperature() humi = sensor.humidity() print(‘Temperature: %3.1f C’ %temp) print(‘Humidity: %3.1f %%’ %humi) if temp != 100: # if change break (new temp value) break except OSError as e: print(‘Failed to read sensor.’)
print( “Reading from sensor: Temp”, temp, “Humi” , humi )
sleep(5)
print(“Sending to Datacake platform:” )
print(“—————————————————————” )
sensor_data = {
‘serial’: ‘kalle’,
‘temp’: temp,
‘humi’: humi
}
print(sensor_data) # HTTP Endpoint URL DataCake
r = requests.post(url=‘https://api.datacake.co/integrations/api/YOURTOKEN/’, json=sensor_data)
print®
sleep(5)
print(“Go to deepsleep 1 h” )
machine.deepsleep(3600000) # 1h sleep until next read

HTTP Payload Decoder on datacake

function Decoder(request) { var payload = JSON.parse(request.body); var serial = payload.serial; return [ { device: serial, field: “TEMP”, value: payload.temp }, { device: serial, field: “HUMI”, value: payload.humi } ];
}
Output from code
rst:0×1 (POWERON_RESET),boot:0×13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0×00,q_drv:0×00,d_drv:0×00,cs0_drv:0×00,hd_drv:0×00,wp_drv:0×00
mode:DIO, clock div:2
load:0×3fff0018,len:4
load:0×3fff001c,len:5008
ho 0 tail 12 room 4
load:0×40078000,len:10600
ho 0 tail 12 room 4
load:0×40080400,len:5684
entry 0×400806bc

connecting to network…
network config: (‘192.168.32.4’, ‘255.255.255.0’, ‘192.168.32.1’, ‘192.168.32.1’)

Failed to read sensor.

Temperature: 23.0 C
Humidity: 47.0 %

Sending to datacake platform
/————————————————————
{‘temp’: 23, ‘humi’: 47, ‘serial’: ‘kalle’}

Go to deepsleep 1 h

Explain the code
After a call to do_connect(), the device will connect to internet. Then it reads the sensor for temperature and humidity in the beehive. Once the values have been retrieved, they are sent further on the internet, to the cloud provider Datacake for presentation on a dashboad.

Solved problem
I had a problem with the sensor not reading the data from sensor at start so I had to do several readings and jump out of the loop with a real value. The code is this:

temp=100 # dummy data Try: … temp = sensor.temperature() … if temp != 100: # if change break (new temp value) break
Transmitting the data / connectivity
APIs need to pull data from a server periodically to stay up to date, but with webhooks, the server can push this data over to you the instant when something happens.

Webhooks are one of a few ways web applications can communicate with each other. It allows you to send real-time data from one application to another whenever a given event occurs.

event
System_ESP32
HTTPS_POST
SystemDatacake
The data (temperature and humidity) is sent every hour (event) from the sensor to the Datacake platform 24/7 via HTTPS POST request.

The wireless protocols I used is WiFi 802.11g.
WiFi IEEE 802.11g-2003 standard is used it operates in the 2.4 GHz microwave band. The theoretical range is 38 meter.

LoRa and the other side have a range of over 10 km. With a power consumption that is low enough to enable over 10 years of battery life. This would have been my first choice if the hardware had been available.

The transport protocols were used is HTTPS with a webhook to Datacake. The HTTPS (Hypertext Transfer Protocol Secure) is an internet communication protocol that protects the integrity and confidentiality of data between the user’s computer and the site.

The design with Wifi and webhook is good for my solution because the hive is close to my WiFi and Datacake platform offered the solution webhook. The battery consumption is low because the device goes in deepsleep after sending data to the next reading.

Presenting the data
Visual examples on how the dashboard looks.


Fig. 6 Dashboard

How often is data saved in the database
The data (temperature and humidity) is saved every hour from the sensor to the database.

Explaining the choice of database
Datacake has its own database (NoSQL database) and you can not choose any else for their solution.

Examples of NoSQL databases: Elastic, InfluxDB, MongoDB, Cassandra, Couchbase, Graphite, Prometheus, ClickHouse, OpenTSDB, DalmatinerDB, KairosDB, RiakTS.

Examples of Relational databases: MySQL, MariaDB Server, PostgreSQL.

Automation/triggers of the data
The data is triggerd with a timer every hour and then send temperature and humidity from the sensor to the Datacake platform 24/7 via HTTPS POST request.

Finalizing the design
Assembly of components


Fig. 7 The components

To assemble the parts, it needs to be soldered.

Final results

Fig. 8 The box with sensor
Installed in the hive


Fig. 9 Final results: the beehive with Honey maximizer!

The sensor is in the top box in the middle.

Final thoughts
This has been a successful project, everything has worked as it should but everything can be done a little better. I think there will be a version 2 of this project with LoRAWAN and Grafana in the near future.

Skribent