This shows you the differences between two versions of the page.
iothings:proiecte:2025sric:homemonitoringsystemwithalerts [2025/05/24 14:04] andrei.buhnici [Firebase] |
iothings:proiecte:2025sric:homemonitoringsystemwithalerts [2025/05/24 14:37] (current) andrei.buhnici [References] |
||
---|---|---|---|
Line 50: | Line 50: | ||
====== Software ====== | ====== Software ====== | ||
- | === Code Snippets === | + | === Arduino Code === |
I have 2 ino files, 1 for the base ESP32 which controls the sensors and sends the data, and the other is for the esp32 cam module to take the picture and save it to my google drive. The base ESP32 code is the Thingsboard example modified to fit my needs and the esp32 cam module contains different examples combined (http server example, take photo example and google drive data upload example). | I have 2 ino files, 1 for the base ESP32 which controls the sensors and sends the data, and the other is for the esp32 cam module to take the picture and save it to my google drive. The base ESP32 code is the Thingsboard example modified to fit my needs and the esp32 cam module contains different examples combined (http server example, take photo example and google drive data upload example). | ||
Line 1014: | Line 1014: | ||
Besides these 2 ino files i have 3 javascript rule nodes in Thingsboard's rule chain which just filter for the correct telemetry (motion, sound, gas) and convert the message from "gasAlarm = 1" to a string like "[Telemetry_Name] detected! [photo_url]". Then this message is sent to Twilio and is routed to the configured mobile phone number. | Besides these 2 ino files i have 3 javascript rule nodes in Thingsboard's rule chain which just filter for the correct telemetry (motion, sound, gas) and convert the message from "gasAlarm = 1" to a string like "[Telemetry_Name] detected! [photo_url]". Then this message is sent to Twilio and is routed to the configured mobile phone number. | ||
==== Google Drive ==== | ==== Google Drive ==== | ||
- | As i said previously i am also using a google script to actually store the photo take by the esp32 cam module to my google drive. The script is needed to handle the image upload and return the actual url to the image. The script is at https://script.google.com. | + | As i said previously i am also using a google script to actually store the photo taken by the esp32 cam module to my google drive. The script is needed to handle the image upload and return the actual url to the image. The script is at https://script.google.com. |
<code> | <code> | ||
Line 1050: | Line 1050: | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | ==== Thingsboard ==== | ||
+ | In Thingsboard there is not much coding going on, i just configured some buttons which connect to the RPC methods from the ESP32 code. I also wrote some filter and transform functions in JS for the Thingsboard rule chain. It was needed in order to choose a path based on the alarm triggered and configure a message. Example: | ||
+ | <code> | ||
+ | Filter: | ||
+ | return msg.soundAlarm == 1; | ||
+ | |||
+ | Transform: | ||
+ | msg.body = "Sound was detected"; | ||
+ | delete msg.soundAlarm; | ||
+ | return {msg: msg, ...}; | ||
+ | </code> | ||
+ | |||
+ | And also there is the telemetry data and the dashboard shown in the context section. | ||
+ | |||
+ | {{:iothings:proiecte:2025sric:tb_ss.png?600|}} | ||
+ | |||
+ | {{:iothings:proiecte:2025sric:tb_dashboard.png?600|}} | ||
+ | |||
+ | |||
====== Challenges ====== | ====== Challenges ====== | ||
+ | The most challenging thing was to actually take the photo, because it needed a bit more setup with the google cloud and the actual taking of the photo. And also i really struggled with the google script because it was returning a redirect response and i had to figure out how to follow the redirect link in order to get the image URL. It took me a lot of time to realise i can just extract the url from the body of the redirect message and just make another request. Also i first wanted to send the image url through BLE to the main ESP32 and it took me a while to realise that BLE and Wi-Fi don't really work simultaneously, because there is interference and communication ordering and stuff. So i had to give that up and find another way, because i really didn't want to connect wires since i was skeptical about how to connect them. So i eventually came up with a web server and then it went smoothly. | ||
+ | |||
+ | Another big challenge was how to send SMS only once and not every time an "alarm" is triggered. And to achieve what i have now i reached the limit of free sms messages sent in 3 different days. I first tried to keep count of alarms in Thingsboard but it didn't went well and i just figured that i can manage the alarm stuff locally and just set them off from the cloud and that's exactly what i did. Now an alarm triggers once until it's turned off. | ||
+ | |||
+ | And the last challenge i encountered was setting the right values for potentiometers and the thresholds set by me. | ||
+ | |||
+ | There was a lot of trial and error during this project but thankfully nothing was fried :D. | ||
====== References ====== | ====== References ====== | ||
+ | - https://thingsboard.io/docs/devices-library/esp32-dev-kit-v1/ | ||
+ | |||
+ | - https://docs.sunfounder.com/projects/umsk/en/latest/03_esp32/esp32_lesson04_mq2.html | ||
+ | |||
+ | - https://www.electronicwings.com/esp32/pir-sensor-interfacing-with-esp32 | ||
+ | |||
+ | - https://circuitdigest.com/microcontroller-projects/interface-ky038-sound-sensor-with-esp32 | ||
+ | |||
+ | - https://randomnerdtutorials.com/esp32-cam-take-photo-save-microsd-card/ | ||
+ | |||
+ | - https://www.niraltek.com/blog/how-to-take-photos-and-upload-it-to-google-drive-using-esp32-cam/ | ||
+ | |||
+ | - https://ocw.cs.pub.ro/courses/iothings/laboratoare/2022/lab3 | ||
+ | |||
+ | - https://thingsboard.io/docs/user-guide/ui/rule-chains/ | ||