🍪🎄 Did you bake or buy the perfect Christmas cookies, only to find them mysteriously disappearing from the cookie jar? 🕵️♂️ Or maybe you want to limit the amount of sweets, but resisting the temptation is proving to be quite the challenge? The struggle is real, but don’t worry cookie detectives – we've got the perfect solution for you and your festive treats!
In our quest to protect the joy of holiday cookies, we crafted a clever solution: a Smart Guard for the cookie jar. This project, with a hidden built-in scale, not only weighs the jar but also monitors the rate at which the cookies are disappearing.
If, within a specified time, more grams of cookies than the set limit disappear, indicating a cookie robbery in progress, our trap system would kick into action. The trap, armed with a high-voltage generator, would deter the thief with an attention-grabbing zap!
Our demo shows a smart and funny way to deal with Christmas problems and is based on the implementation of the Anjay LwM2M Client for ESP devices connected to the Coiote IoT Device Management Platform.
The LwM2M (Lightweight Machine-to-Machine) protocol was designed to standardize messaging and device management for resource-constrained IoT devices. The LwM2M protocol optimizes bandwidth-efficient consumption by using space-efficient binary payloads and supports different wireless transport protocols such as NB-IoT, LTE-M, Wi-Fi, and SMS transport. It provides a uniform data format for easy interpretation of data, standardized device management processes, and support for FOTA (Firmware Over The Air).
Anjay is a library that implements the OMA Lightweight Machine-to-Machine protocol. Supporting multiple integration layers, it ensures the development of lightweight IoT devices.
Coiote IoT Device Management Platform allows you to manage your LwM2M devices throughout their entire lifecycle. Coiote IoT DM supports device onboarding, data management, data visualization, automated tests, firmware updates, monitoring & alerting, and cloud integrations.
Let’s buildThis tutorial shows the usage of the built-in scale consisting of the ESP32-DevKitC and tensometer connected directly to the top and bottom wood panels. Also, our project contains a DC high voltage arc generator to create an extra zapping effect.
Note
Safety is our top priority. We’ve added the 'high-voltage generator' to our project as a gadget for fun! We wanted to make you smile while keeping those sneaky cookie snatchers away. If you feel unsure about this, feel free to skip the gadget and enjoy the festive fun without any worries.
The Cookie Guard supports the following LwM2M Objects:
- Security (/0)
- Server (/1)
- Device (/3)
- Firmware Update (/5)
- WLAN Connectivity (/12)
- Load (/3322)
After wiring all sensors to the device, we will end up with something like this:
For readability, below is a wiring scheme:
Coiote IoT Device Management is a scalable LwM2M-based IoT platform for complete device lifecycle management.
To connect to the Coiote IoT DM platform, please register at https://eu.iot.avsystem.cloud.
To connect the board:
Log in to Coiote IoT DM and from the left side menu, select Device Inventory.
In Device Inventory, click Add device.
Select the Connect your LwM2M device directly via the Management server tile.
In the Device credentials step:
- In the Endpoint name enter your board endpoint name, e.g. test_device.
- In the Security mode section, select the PSK (Pre-Shared Key) mode.
- In the Key identity field, type the same name as in the Endpoint name field.
- In the Key field, type the password used in the device-server authentication.
Note
Remember your device credentials provided in Coiote IoT DM must be the same as are on the Client side.
Click the Add device button and Confirm in the confirmation pop-up.
Download the Anjay ESP32 client files- Create a project directory for the integration.
- Download esp32-devkitc.bin and nvs_partition_gen.py to your project directory from the code files at the end of this tutorial.
Create a nvs_config.csv file and save it in your project directory. In the file, provide your credentials in [wifi_ssid], [wifi_password], [endpoint_name], [identity], [psk], [lwm2m_server_uri] (without the [] brackets).
The last two parameters allow us to configure our trap. The threshold parameter determines the weight of candy that can be eaten within the time set by the tare_period_ms parameter. Enter your settings in [threshold weigh that activates the HV generator] and [scale taring period].
Use the following snippet as a template:
key,type,encoding,value
config,namespace,,
wifi_ssid,data,string,[wifi_ssid]
wifi_pswd,data,string,[wifi_password]
wifi_inter_en,data,u8,1
endpoint_name,data,string,[endpoint_name]
identity,data,string,[identity]
psk,data,string,[psk]
uri,data,string,[lwm2m_server_uri]
writable_wifi,namespace,,
wifi_ssid,data,string,[wifi_ssid]
wifi_pswd,data,string,[wifi_password]
wifi_inter_en,data,u8,0
cookie_guard,namespace,,
threshold,data,u32,[threshold weight that activates the HV generator]
tare_period_ms,data,u32,[scale taring period]
Note
The additional parameters under the writable_wifi namespace are used to provide a secondary Wi-Fi configuration (it is not obligatory). This allows for switching between Wi-Fi configurations while the device is running.
Open a command line interface, go to your project directory, and generate the NVS partition:
Linux
pip3 install future cryptography
python3 nvs_partition_gen.py generate nvs_config.csv nvs_config.bin 0x4000
Windows
pip3 install future cryptography
python nvs_partition_gen.py generate nvs_config.csv nvs_config.bin 0x4000
Flash the board and run deviceConnect your board to a USB port of your machine and open ESP-IDF command line application.
Use pre-built binaries to flash the board and provide credentials by flashing the NVS partition binary.
Install the esptool.py:
pip3 install esptool
Flash the board and NVS partition binary:
Tip
Before flashing the device you should erase the flash first to make sure you have the correct settings:
Linux
esptool.py erase_flash
esptool.py --chip esp32 write_flash 0x0000 esp32-devkitc.bin
esptool.py --chip esp32 write_flash 0x9000 nvs_config.bin
Windows
esptool erase_flash
esptool --chip esp32 write_flash 0x0000 esp32-devkitc.bin
esptool --chip esp32 write_flash 0x9000 nvs_config.bin
Once executed, the device will be reset and run with the configuration you provided.
Go to Coiote IoT DM to check if your device is connected. Click Next, then Go to Summary, then Finish. You will see your Device Center view:
After successfully creating your device in Coiote it is time to show some charts with parameters. But first, you need to set the observation.
Note
You need to set the observations on the load object which shows the information about weight of our sweets. For the tutorial we will set an observation on a single resource which, in our example, is the Sensor Value resource of the Load object. The Load object shows the applied weight or force from the load sensor
To set an observation on a resource (and, effectively send LwM2M Write-Attributes and Observe operations to the device):
- Click the widget and eye icon in the Operations column.
- In the side navigation menu, enable the desired attributes, fill in the values, and click Set observation.
Info
Not more often than once every - the minimum time in seconds between two notifications.
At least once every - the maximum time in seconds between two notifications. The notification is sent even if the value hasn't changed.
Read more about other attributes in our Brief description of OMA LwM2M.
After configuring the observations we can observe parameters that changed throughout the day.
To see our charts go to the Dashboard tab from the main server website view.
In our project, the threshold was set at 150 and once it was exceeded, no one took the risk to pick up more cookies.
Final resultsNow, our Cookie Guard can start collecting data and running flawlessly. With a smart scale, hidden sensors, and a high-voltage trap, we're now equipped to catch any cookie thief red-handed. Wishing everyone a Merry Christmas filled with joy, laughter, and of course delicious, thief-free cookies!
Comments
Please log in or sign up to comment.