our postman does not ring anymore and
for sure not twice
he just places the letters and
particularly important my packets in our
mailbox and off he is unfortunately he
does not always appear at the same time
because i'm a nerd i hate leaving my lap
and walking several times to the mailbox
without a reward
and the worst my wife loves her sunday
morning newspaper and often had to go to
the mailbox without success in winter
even in the cold and dark can you
imagine
the ultimate reason to solve this
problem
pretty youtubers here is the guy with
the swiss accent with a new episode and
fresh ideas around sensors and
microcontrollers remember if you
subscribe you will always sit in the
first row this is our mailbox it is
placed with other mailboxes around 50
meters away from my lab and our house
as you see it is made of metal
it has a flap for the small things and a
door for the bigger ones
because we get small items like letters
with each delivery i only have to
supervise the flap to detect the postman
or should i say post person
the mailbox is not my property so i do
not want to drill holes into it
to mount an outside antenna
the only possibility is to place the
transmitter inside this faraday cage
i once made tests with a simple 433
megahertz transmitter
unfortunately these tests failed because
the signal did not reach my home
so this time i tried with our most
potent weapon laura
frequent viewers know that it has a link
budget of up to 160 db
i was still skeptical but the first
trials showed that my gateway on the
roof on the opposite side of the house
could receive packets from my test note
so the project was feasible and i
defined the following goals
produce a distinct alarm in my lab when
something is inserted in the mailbox
add a telegram alarm on my smartphone
why
because i can
light up an led to show my wife that she
can go and get her sunday newspaper and
also as a reminder if i did not hear the
alarm
the sensor should run for a long time
with the same battery
and it should be used as a test case for
the lorawan v3 migration
frequent viewers of this channel know
that we have a few options for such a
notifier
different sensor technologies different
battery technologies different switching
concepts for the electronics
let's start with the sensors because it
is dark in the mailbox and if the flap
is open for a short time it could be
detected by a light sensor
or we could use an ultrasonic sensor to
detect the movement of the flap
or we could attach a tilt sensor to the
flap which triggers when it is moved
because the most important goal was to
reduce power consumption active sensors
like ultrasonics were out
the light sensor probably would have
worked but i had a bad experience with
such a sensor which switches our tv off
when we closed this door
during a particular time of the year the
sun was in a position where it was able
to inject light and trigger the sensor
you can watch video number 171 if you
are interested in how i solve the
problem
we all know also brilliant people make
mistakes but in contrary to the stupid
ones they make the same mistake only
once
so let's try to behave like brilliant
people it feels so good
no light sensor then
a tilt sensor would probably be a good
solution and i might try it once it is a
mechanical switch and it does not
consume any current when off
the sensor i used is a simple read
switch with a magnet
when the magnet is closed it is off and
it switches on as soon as the magnet is
removed
and this is how i placed it
please pay attention if you buy one you
get them also in a version that is on if
the magnet is closed
so we decided on the sensor how shall we
go on with the electronics
i could deep sleep the mcu and wait till
the sensor creates a trigger to switch
it on
which would be a good idea for many
situations
but not for this one why
i did not want to create a custom pcb
with a low power mcu and a lora module i
just wanted to use one of my ready-made
boards from healthtech or ttgo
we all know that these sports are
relatively power hungry even if we deep
sleep the esp32s
i could have used this sport with an
atmel 328 chip but unfortunately the
newest version of the elmic library
called mcci is too big for that chip
and because i wanted to use a supported
library for my lorawan v3 testbed
i went with this heltech board
i also did a second prototype with a
ttgo board and a different battery
technology
also this one worked
as said before these boards consume too
much current during deep sleep
so you have to switch them completely
off when not used
that is perfectly possible as we saw in
video number 388 where i created this
prototype board with two transistors
now the board is powered as soon as the
magnet is removed then the esp32
switches gpio4 on and keeps the power on
as long as needed to transfer the
message
as soon as this is done it switches
power off
as you can see the typical on time is
only a few seconds
also because i only transfer one value
the battery voltage we do not need to
transfer more information because it is
clear that the flap was opened when we
get a message and we can record the time
of movement on the receiver side in node
rate
the next question is
which power source
the most obvious would be to attach a
lyon battery because these boards have
everything needed
this is what i did first and it works
fine
but because i prepare a video about live
fap4 batteries i wanted to give this
technology a chance
and because space was not a big issue i
used this heavy bomber i only added low
voltage protection and no charging board
we will solve the charging problem in a
few years when the battery is depleted
and of course the same switching circuit
as before
it also works with live apo 4 and with
disposable batteries
i also added a voltage divider to
measure voltage with an adc pin of the
esp32
i choose very high resistor values to
reduce power consumption and because
accuracy is not too important for this
application
in my future life apo4 video we will
measure the current lost by the under
voltage protection and this voltage
divider
what do we need next
software of course
in the early days of lora van we would
have used abp for such a scenario but
these days everybody recommends to use
otaa
if you still want to use abp i strongly
suggest planning enough time for it the
counters do no more work the same way as
in v2
and otaa seems to work ok
after disappointing experiments with abp
i focused on otaa and run into the next
problem
with otaa your node should join the
network once and then transmit its
messages right away like with avp
unfortunately all example sketches i
found joined after every deep sleep or
reboot of the mcu
not as intended by the inventors
you could say who cares
there are only a few messages a day
remember that a join process takes much
longer than a simple message transfer
unnecessarily depletes your battery and
increases air time
but there is more ttn only supports a
limited number of joints from a
particular node because it runs out of
numbers
so our node will stop working after a
while
as far as i know it is after about 30
000 joins
i was astonished that i did not find a
standard library that supports the most
common scenario for a laura note deep
sleep
it took me a lot of time and discussions
with various people and my frustration
somehow was shared
so far i did not find an official
arduino compatible library supported by
ttn or simtek
anyway finally i found the working
example of jack gruber who uses the mcci
library and stores the whole elmig
structure into rtc memory
we remember rtc memory survives deep
sleep
fortunately the esp32 has a lot of
memory and he was able to store the
roughly 900 bytes of the structure
without problems
if we reload the stored information at
reboot
our node is still joined
perfect
only if our node loses power it has to
rejoin
problem solved
at least for the guys with deep sleep
unfortunately i decided against it
so i was alone again
the only way left was to transfer jack's
concept to eeprom and this is what i did
if you use my sketch you can choose
between storage in rtc or eeprom memory
we all know that the esp32 emulates
eeprom in flash
and it will wear out
maybe somebody writes an addition that
selects a different area of the flash
every time it stores new values the
sketch is quite simple in the setup we
initialize everything read the ee prom
or rtc
read the voltage and queue the message
for transmission
if the sequence number is zero we know
that there is no relevant info in the
eeprom and we must join
the loop does not do a lot this line
makes sure all callbacks work
for my deep sleep or switch off
scenarios i added a few other things
as soon as the message is completely
transferred the enable sleep variable is
set to true
these lines then store the actual elmic
values for the next session and the mcu
switches itself off or goes to deep
sleep here i added a trick
imagine that our post person does not
work correctly and leave parts of the
letters like this
then the esp will not switch off because
it gets power through the read switch
even after transmitting the message
in this case i send the esp into deep
sleep to save energy
as soon as i remove the letters
the lid closes and all is good
and if the transfer does not work as
expected and takes too long the elmig
sequence number is set to 0 which means
the device tries to rejoin during the
next boot
finally the esp is switched off without
transferring a message
both measures prevent that the battery
is depleted in an infinite loop
one word of warning this sketch does not
work with deep sleep because the switch
is not connected to a wake up pin you
should find examples of how to do this
and maybe somebody creates a pull
request
with such a changed version of the
sketch
of course you can remove all print
statements if you want to save
additional energy
now you have at least a working example
of a long lasting note i'm sure you can
base your project on it
now we only need a decent box for the
sensor i used video number 258 to print
these boxes and with the help of
double-sided tape the mounting of the
reed switch was simple
we already had to add our sensors to ttn
to get these ids if you want you can
store them in a credentials.h file or
you can delete this line and fill in
these numbers
my future lorawan video will show how to
register our gateway or notes
we still have a few things on our to-do
list the first is a decent alarm as said
in my last video i wanted a distinctive
sound this is why i bought this
electromechanical bill added this
circuit to drive it from my raspberry
and printed this case
i wanted to connect it to my pi because
i did not want another esp using energy
just for this spell i added mqtt
integration to my device in the ttn
console and added this flow to node-red
on my raspberry pi server
adding mqtt integration is not
complicated
you just have to create a key and store
it somewhere because you will never see
it again on ttn
and at the username and this key as the
password in the node red flow as usual i
share this flow in the description
for the rest i use iot stack as shown in
videos number 295 and 362.
because i already use telegram influx db
and google calendar for other things it
is easy to add them to this project if
you are interested in these spells and
whistles you find other videos on this
channel on how to do it
you might ask
why did i add influx db and google
calendar
as said our newspaper service was not
reliable in the past
yes this also happens in switzerland
this is why i wanted facts for the
complaints
and google calendar
as shown in video number 185 we still
have our happy wife device in our
kitchen
it is triggered by google calendar
so i only had to add a new event called
mail as soon as the lid of the mailbox
is opened the bell rings telegram sends
a message the time and battery voltage
is stored in influx db and the led
lights up in the kitchen
as soon as somebody empties the mailbox
they can press the button to reset the
alarm
what do you want more
so let's see if we forgot something
using our list from the beginning
produce a distinct alarm when something
is inserted in the mailbox
yes a mechanical bell added to the
raspberry pi creates a decent sound
by the way here you find a write-up on
how to add gpios to the iot stack
project at telegram if i'm on the road
node red does the tree light up an led
to show my wife in the kitchen that she
has to send me to get her sunday
newspaper
yes the happy wife device made the wife
even happier and i'm sure if i have to
ask for permission to buy the next
expensive instrument it will turn the
odds into my favor
because of the influx db integration we
even can't support our complaints when
the newspaper did not arrive in time
it should run for a long time with the
same battery
we can't also take this one because the
electronics are switched off most of the
time
and it should be used as a test case for
the lorawan v3 migration
this one took most of the time and i
hope that you can profit from my work
and maybe we can convince the makers of
the mcci library to add deep sleep
capabilities that was all for today as
always you find all the relevant links
in the description
i hope this video was useful or at least
interesting for you if true please
consider supporting the channel to
secure its future existence thank you
bye