Robbery by underworld part-time job breaks into homes many times in Japan. The underworld part-time job is recruited in social media, so the robbers do not know each other. That makes it challenging to resolve the incident. We need to protect ourselves from the robber’s attack on our home.
My solution is to detect that someone opened the door of our house using radar. My solution also converts the detection information to a warning message and then sends it by email to a mobile phone or PC.
2. How I am Trying to Solve It?In the Home Security System, Arduino Nano inputs human position data using S2GO RADAR BGT60LTR11 installed on the other side of the door and connected by Arduino GPIO interface.
Arduino Nano checks that humans enter the home using inputted human position data from S2GO RADAR BGT60LTR11. When S2GO RADAR BGT60LTR11 detects human position, Arduino Nano sends the result data to PSoC™ 62S2 Wi-Fi BT Pioneer Kit using a GPIO interface. Then PSoC™ 62S2 Wi-Fi BT Pioneer Kit generates and sends warning mail to the SMTP server ”Smtp4dev” using Wi-Fi.
Home Security System also turns on or off the user LED of the PSoC™ 62S2 Wi-Fi BT Pioneer Kit according to the result of moving data detection.
The homeowner who is out of home access to the mail server using a mobile phone or PC can know the home situation by email.
3. Constructing HardwareThe hardware of the Home Security System is set up as follows.
Here is a Circuit Schematic made with KiCad. PSoC™ 62S2 Wi-Fi BT Pioneer Kit connects to Arduino Nano having S2GO RADAR BGT60LTR11 using the GPIO interface.
The Home Security System program code for PSoC™ 62S2 Wi-Fi BT Pioneer Kit 2 is developed by Infineon ModusToolbox. Those source codes are modified using the code example “TCP Client” of Infineon ModusToolbox. Those source codes are shown in the "https://github.com/tomosoft-jp/Connect-things/tree/main"
The function ”mail_send” sends the warning mail to the SMTP server ”Smtp4dev” using the SMTP protocol. This function is called from the incoming TCP server messages callback function “tcp_client_recv_handler.” The parameter “num” is the process stage ID of the SMTP protocol.
tcp_client.c
・・・
void mail_send(cy_socket_t mail_handle, int num) { // tomosoft
cy_rslt_t result;
char buf[MAX_TCP_DATA_PACKET_LENGTH];
//uint32_t bytes_received = 0;
uint32_t bytes_sent = 0;
switch (num) {
case 0:
memset(buf, 0, sizeof(buf));
/* HELOの送信 */
strcpy(buf, "HELO ");
strcat(buf, "smtp4dev");
strcat(buf, "\n");
printf("send: %s", buf);
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
break;
case 1:
memset(buf, 0, sizeof(buf));
/* MAIL FROMの送信 */
strcpy(buf, "MAIL FROM: ");
strcat(buf, "<from@example.com>");
strcat(buf, "\r\n");
printf("send: %s", buf);
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
cyhal_gpio_write(CYBSP_USER_LED, CYBSP_LED_STATE_ON);
printf("LED turned ON\n");
break;
case 2:
memset(buf, 0, sizeof(buf));
/* RCPT TOの送信 */
strcpy(buf, "RCPT TO: ");
strcat(buf, "<to@smtp4dev>");
strcat(buf, "\r\n");
printf("send: %s", buf);
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
break;
case 3:
memset(buf, 0, sizeof(buf));
strcpy(buf, "DATA\r\n");
printf("send: %s", buf);
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
break;
case 4:
memset(buf, 0, sizeof(buf));
strcpy(buf, "From:from@example.com");
strcat(buf, "\r\n");
strcat(buf, "To:to@smtp4dev");
strcat(buf, "\r\n");
strcat(buf, "Subject: Someone detected !");
strcat(buf, "\r\n");
strcat(buf, "\n");
strcat(buf, "");
strcat(buf, "\r\n");
printf("send: %s", buf);
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
memset(buf, 0, sizeof(buf));
strcpy(buf, ".\r\n");
result = cy_socket_send(mail_handle, buf, strlen(buf),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
printf("send: %s", buf);
break;
case 5:
result = cy_socket_send(mail_handle, "QUIT\r\n", strlen("QUIT\r\n"),
CY_SOCKET_FLAGS_NONE, &bytes_sent);
if (result == CY_RSLT_SUCCESS) {
//printf("Acknowledgment sent to TCP server\n");
}
printf("send: QUIT\r\n");
cyhal_gpio_write(CYBSP_USER_LED, CYBSP_LED_STATE_OFF);
printf("LED turned OFF\n");
break;
}
}
・・・
The task routine ”tcp_client_task” starts the task and checks the detection signal from Arduino Nano using the function ”get_radarInfo.“ When the semaphore "connect_to_server" count isn’t “0” and the flag “detectflg” is “1”, the code connects the SMTP server ”Smtp4dev” to send the warning mail. The function “cy_rtos_semaphore_get_count” gets the semaphore count.
tcp_client.c
・・・
void tcp_client_task(void *arg) {
・・・
/* Initialize secure socket library. */
result = cy_socket_init();
if (result != CY_RSLT_SUCCESS) {
printf("Secure Socket initialization failed!\n");
CY_ASSERT(0);
}
printf("Secure Socket initialized\n");
// Initialize pin P12_3 as an input
result = cyhal_gpio_init(P12_3, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE,
false);
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}
// Initialize pin P7_6 as an input
result = cyhal_gpio_init(P7_6, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE,
false);
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}
detectflg = 0;
for (;;) {
result = cy_rtos_delay_milliseconds(500);
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}
get_radarInfo();
result = cy_rtos_semaphore_get_count(&connect_to_server, &counter);
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}
printf("counter:%d\n", counter);
if (counter == 0)
continue;
if(detectflg == 0) continue;
detectflg = 0;
/* Wait till semaphore is acquired so as to connect to a TCP server. */
cy_rtos_semaphore_get(&connect_to_server, CY_RTOS_NEVER_TIMEOUT);
・・・
The function ”get_radarInfo” checks the GPIO port “P12_3” and “P7_6.” When the GPIO port “P12_3” is “1” and “P7_6 is “0”, this function sets the flag ”detectflg” as “1”. This function is called from the main loop constantly.
tcp_client.c
・・・
void get_radarInfo() {
// Read the logic level on the input pin
read_vald10 = cyhal_gpio_read(P12_3);
read_vald9 = cyhal_gpio_read(P7_6);
printf("d10: %d d9:%d\r\n", read_vald10, read_vald9);
if((read_vald10==1)&&(read_vald9==0)) detectflg = 1;
}
・・・
4.2 Arduino Nano program codeThe Home Security System program code for Arduino Nano is developed by Arduino IDE. Those source codes are modified using the sample sketch “direction detection” of Arduino IDE. Those source codes are shown in the "https://github.com/tomosoft-jp/Connect-things/tree/main"
The function ”setup” sets the GPIO mode into output.
directionDetection.ino
・・・
void setup()
{
/* Set the baud rate for sending messages to the serial monitor */
Serial.begin(9600);
・・・
pinMode(outTD, OUTPUT);
pinMode(outPD, OUTPUT);
}
・・・
The function ”loop” calls the function “radarShield.getDirection” to check the direction. When getting the direction successfully, the function ”loop” inputs the signal “TD” and “PD.” The function ”loop” outputs the obtained signal to GPIO ports “D11” and “D12.”
directionDEtection.ino
・・・
void loop()
{
/* Initialize the variable to NO_DIR to be able to record new events */
Bgt60::Direction_t direction = Bgt60::NO_DIR;
/* The getDirection() API does two things:
1. Returns the success or failure to detect direction of object as a message of type Error_t.
Any value other than OK indicates failure
2. Sets recent event in "direction" variable. Events can be: APPROACHING, DEPARTING or NO_DIR */
Error_t err = radarShield.getDirection(direction);
/* Check if API execution is successful */
if (err == OK)
{
read_vald11 = digitalRead(TD);
read_vald12 = digitalRead(PD);
digitalWrite(outTD, read_vald11);
digitalWrite(outPD, read_vald12);
・・・
5. Setting up SMTP server ”Smtp4dev”SMTP server ”Smtp4dev” is the fake SMTP email server for development and testing. The warning mail received in smtp4dev from PSoC™ 62S2 Wi-Fi BT Pioneer Kit using SMTP protocol can be viewed and inspected.
When the SMTP server ”Smtp4dev” starts up in the Windows command prompt, The command prompt displays the message as follows.
The SMTP server ”Smtp4dev” can display the warning mail using the URL "http://localhost:5000" set on the browser as follows.
Program code flashed by Infineon ModusToolbox and Arduino ID, and executes automatically.
Here is a video of the Home Security System. When I open the door, The S2GO RADAR BGT60LTR11 recognizes me and sends the detection signal to PSoC™ 62S2 Wi-Fi BT Pioneer Kit through Arduino Nano. PSoC™ 62S2 Wi-Fi BT Pioneer Kit processes that detection signal and sends the warning mail to the SMTP server ”Smtp4dev.” As a result, I can know the home situation by email.
The Windows command prompt displays the SMTP server ”Smtp4dev” message as follows.
smtp4dev version 3.2.0-ci20221023104
https://github.com/rnwood/smtp4dev
.NET Core runtime version: .NET 6.0.5
> For help use argument --help
Install location: C:\Users\ne\Desktop\Rnwood.Smtp4dev-win-x64-3.2.0-ci20221023104
DataDir: C:\Users\ne\AppData\Roaming\smtp4dev
Using Sqlite database at C:\Users\ne\AppData\Roaming\smtp4dev\database.db
TLS mode: None
SMTP Server is listening on port 25.
Keeping last 100 messages and 100 sessions.
IMAP Server is listening on port 143
Now listening on: http://localhost:5000
Session started. Client address 192.168.10.108.
Message received. Client address 192.168.10.108, From from@example.com, To to@smtp4dev, SecureConnection: False.
Processing received message
Processing received message DONE
Session completed. Client address 192.168.10.108. Number of messages 1.
・・・
The serial monitor in Infineon ModusToolbox outputs the message as follows.
============================================================
CE229112 - Connectivity Example: TCP Client
============================================================
WLAN MAC Address : 18:48:CA:88:48:CA
WLAN Firmware : wl0: Dec 12 2022 18:42:34 version 13.10.271.293 (9974213 CY) FWID 01-e2162f9b
WLAN CLM : API: 18.2 Data: 9.10.0 Compiler: 1.36.1 ClmImport: 1.34.1 Creation: 2022-08-16 03:35:21
WHD VERSION : 2.6.1.20115 : v2.6.1 : GCC 11.3 : 2023-06-28 02:01:23 +0000
Wi-Fi Co
necd10: 0 d9:0
counter:1
d10: 0 d9:0
counter:1
d10: 0 d9:0
・・・
============================================================
Enter the IPv4 address of the TCP Server:
Connecting to TCP Server (IP Address: 192.168.10.105, Port: 25)
Connected to TCP server
d10: 0 d9:0
counter:0
d10: 0 d9:0
counter:0
d10: 0 d9:0
counter:0
d10: 0 d9:0
counter:0
d10: 0 d9:0
・・・
10: 0 d9:0
counter:0
d10: 0 d9:0
counter:0
d10: 0 d9:0
counter:0
rcv 220 DESKTOP-7KFPQ23 smtp4dev ready
send: HELO smtp4dev
d10: 0 d9:0
counter:0
d10: 0 d9:0
・・・
Comments