If you have a dog, cat or any pet that needs to go into a kennel when travelling, and be left in the hands of airlines or moving services, you know how stressful and problematic it is for your precious friends.
The main problem thus is: The horrid care pets get when they are transported.
Regarding the pet's safety and comfort:
Sometimes we need to send pets with an airline service for travel to another country or just around the corner. How can we be sure they're fine at all times? Take into consideration how baggage is treated.
And secondly, have we ever feared that our dog goes astray and you can never find it again, the following project might have a solution for that.
Always use technology to improve the world, if you are a black hat or gray hat hacker please abstain at this point......... or at least leave your star to make me feel less guilty XP.
Solution:I will make an integral IoT solution to monitor the pet’s environment based on RSL10-SENSE-DB-GEVK, in order to ensure their well-being throughout their journey. All this also integrated with a AWS as backend and NodeRed based platform which, in addition to showing the status of the package in real time, also sends notifications at the frequency that is convenient.
The current monitoring solutions are restricted to only lifeless packages, this making the continuous monitoring of pets a novelty. It is useful because thanks to this system pet owners can be 100% sure that their pets will be well and can monitor and follow them throughout their flight or any travel.
For those lost and gone astray pets:
NFC technology has been used for many years in products, animals and even humans, however we do not have a solution that indicates if the dog has already been found once the tag has been scanned.
We will create a configuration for the NFC tag so that once the tag data is reviewed, it notifies us where it is and also shows the person who scanned the tag, the contact information to recover our best friend.
Connection Diagram:- Kit Assembly:
- Connect the Antenna.
- Put the battery in the socket.
- Perfect, your kit is assembled and ready to program!
For the correct configuration of the kit, it will be necessary to download the official ON Semiconductor IDE.
IDE Link: https://www.onsemi.com/PowerSolutions/gatedDocument.do?method=getGatedDocument&docId=1172113
The manual to correctly configure the IDE is the following:
Link: https://www.onsemi.com/pub/Collateral/EVBUM2614-D.PDF
All the dependencies of the program are in the "Dependencies Pack" folder, you can download them directly from the ON Semiconductor page, but I recommend using the ones in the folder.
Note: All the configurations for the kit are perfectly documented in the document, so this tutorial will start from the configuration of the mobile application for this project.
App Setup - Part 1:- Install your gateway from this link:
iOS:https://apps.apple.com/us/app/rsl10-sense-and-control/id1451974010
Android:https://play.google.com/store/apps/details?id=com.onsemi.rsl10senseandcontrol&hl=es_VE
- Select the device you are going to configure.
- Select your sensors.
- If everything works well, we can see the sensors obtaining information.
- One of the main difficulties to carry out the transmission by MQTT correctly, is to know the Topic in which all our information is being sent. This Topic will be the same for all the brokers that we configure, however to obtain it, we must carry out a small test with a Broker MQTT that allows us to review all Topics. In the case of AWS, it is not possible to do this, so we will obtain the topic through a local Mosquitto broker.
Link: https://mosquitto.org/download/
- To access the mosquitto broker we will have to configure the broker in our app.
- Tap the gear symbol in the upper right corner.
- Press the "Enable Broadcast" switch and then enter the Manage Brokers option.
- We press the + symbol in the upper right corner to add the broker.
- Client Name: "Any Name"
- Protocol: tcp
- URL: IP From the server in your local network.
- Port Number: 1883
- Username: null
- Password: null
- Set up the credentials as follows.
- Start the data broadcast on your computer and execute the following command in your CMD or Terminal, to listen to all the topics of your broker and therefore that of your device.
Note: sometimes the mosquitto broker is not activated automatically in windows, I added two.bat files in the "Scripts" folder that allows you to turn the broker on and off by clicking them. Run them as administrator.
Note 2: In most brokers, the # symbol is used as a wildcard for topics.
mosquitto_sub -v -t #
- You will see the Topic as follows
Save that topic since it will be the publication topic in all brokers.
AWS Setup:AWS works through roles, these roles are credentials that we create so that the services can communicate with each other, in order to carry out all our integration we need to create a role that allows the effective transmission of all services, therefore that will be the first thing To make.
Note: always start here when doing a project with AWS.
IAM:- Enter the IAM console.
- Enter through the role tab and click "Create role".
- Create a role focused on the IoT platform.
- Press next till review.
- Now we have to add the additional permissions to the Role, in the roles tab enter the role we just created and press the Attach policies button.
- AmazonDynamoDBFullAccess
- Inside policies add the following:
- Once that is finished, now we can start configuring the Rule within AWS IoT Core.
In this case the AWS IoT configuration is already provided by the official documentation by ON semiconductor, however I will show you how to configure the Rules to connect the rest of AWS services.
Link: https://www.onsemi.com/pub/Collateral/AND9831-D.PDF
- Once we receive the data to our AWS IoT Core, we will configure the Rules to connect the following services.
- Set any name for the Rule.
- In the SQL Query we will place our topic.
- The first rule we are going to create will be to save all the data in a DynamoDB.
- Press "Create a new resource" to create the table where we will save the data.
- For our table we will use the following parameters, I suggest that you use these specifically, since at production level all the device numbers will be different and in the "Time" column we are going to implement a special TIMESTAMP function.
- Once the resource is created we return to:
The Sort Key value special function is:
${parse_time("yyyy.MM.dd G 'at' HH:mm:ss z", timestamp() )}
- Once this is finished, we will have finished the first rule. In this case, because the rule for the lambda uses a different SQL query, we will no longer add any more actions to this rule.
- To create a new rule but using the following SQL Query.
- We will add to this rule the following action:
- Press the "Create a new Lambda Function" button:
- We configure the lambda in the following way and create it:
- Once the lambda has been created we go down to the Execution role section and press the View the YOURROLE button on the IAM console to be able to add the SNS police to the SMS:
We add the SNS service
- AmazonSNSFullAccess
- Once that is finished, we select the lambda in our rule to finish configuring the lambda trigger.
- Before programming the Lambda we will have to configure the SMS service through SNS.
- Press the "Create Topic" button to create our message service.
- Give the Topic a title and create it.
- Save the ARN number, since we are going to need it to configure the lambda.
- Click "Create subscription".
- Select as "Protocol" SMS and in Endpoint put your cell number (International dialing).
- Done, we have finished creating the necessary services to use the lambda correctly, now we return to the lambda and copy the code in the Lambda Code folder and paste it into your Lambda.
- The most important part of the code is the Thresholds, each of them was obtained from the following references.
- Air Quality: RSL10 Reference.
- Max Accel Limit: https://web.archive.org/web/20170104164718/http://www.au.af.mil/au/aupress/digital/pdf/book/b_0113_brulle_engineering_space_age.pdf
- Max Pressure on Flight: https://www.who.int/ith/mode_of_travel/cab/en/
- Max Degrees: 45 degrees maximum static friction before the dog slips
- Max Magnetic Field: https://www.who.int/peh-emf/publications/facts/fs322/en/
- Min and Max, Temperature and Humidity: http://www.dartmouth.edu/~cushman/courses/engs44/comfort.pdf
- Max Lux Level: https://www.engineeringtoolbox.com/light-level-rooms-d_708.html
Since we have all our platform ready, we have to create the accesses to communicate with it. So we will have to create two Things in this case, the first is for our RSL10 module and the other will be for the NodeRed UI.
Note: To configure the app, you can use the following official ON Semiconductor manual as well.
Link: https://www.onsemi.com/pub/Collateral/AND9831-D.PDF
- First we have to access our AWS console y look for the IoT core service:
- Obtain your AWS endpoint, save it because we will use it to setup the RSL10 App and the webpage.
- In the lateral panel select the "Onboard" option and then "Get started".
- Select "Get started".
- At "Choose a platform" select "Linux/OSX", in AWS IoT DEvice SDK select "Python" and then click "Next".
- At Name, write any name, remember that you will have to do this process twice, so name things ion order that you can differentiate the credentials that you will put in NodeRed and in the RSL10 app. Then click on "Next step".
- At "Download connection kit for" press the button "Linux/OSX" to download the credential package (which we will use later) and click on "Next Step".
- Click "Done".
- Click "Done".
- On the lateral bar, inside the Manage/Things section we can see our thing already created. Now we have to set up the policy of that thing for it to work without restrictions in AWS.
- At the lateral bar, in the Secure/Policies section we can see our thing-policy, click on it to modify it:
- Click on "Edit policy document".
Copy-paste the following text in the document and save it.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "*"
}
]
}
- Once this is done, we will go to our pc and to the folder with the credentials previously downloaded, extract them.
Android: if you are configuring AWS on an Android, send the certificates through USB so you can easily configure them.
iPhone: If you are configuring AWS on an iPhone, the easiest way is to put the certificates from https://www.icloud.com/# in the "iCloud Drive" application.
Since we have the certificates for the device, we will configure it as follows.
- Enter the gear symbol in the upper right corner.
- Press the "Enable Broadcast" switch and then enter the Manage Brokers option.
- Press the + symbol in the upper right corner to add the broker.
- Client Name: ANYNAME
- Device ID: ANYNAME
- Protocol: SSL
- URL: Your AWS Endpoint
- Port Number: 8883 (443 doesn't work)
- Username and Password: Empty
- Set Client Name, Device ID, Protocol, URL and Port Number.
- CA Certificate
- Thing Certificate
- Private Key Certificate
- Password Empty
- Import all the certificates (CA certificate inside "Cert" folder)
- Press "Save" in the upper right corner to complete the setup.
- To start broadcasting to AWS, press the following button in the application.
- If everything goes well, we should see the following in AWS IoT and DynamoDB.
- With this, we have the entire cloud backend of the project, so now we can focus on the frontend.
- Node Red is a tool for NodeJS where we can integrate services easily, without code and, of course, create excellent dashboards.
- NodeJS installation guide: https://www.guru99.com/download-install-node-js.html
- NodeRED installation guide: https://nodered.org/docs/getting-started/windows
- NodeRED installation guide: https://flows.nodered.org/node/node-red-dashboard
- The file "flows.json" in the folder "Node-RED Flow", has all the information to import the flow into your NodeRED.
- Once that is done we will edit the MQTT node to enter our credentials.
- Set Server and Port.
- Press in the pencil in TSL configuration to add the certificates.
- Note: RootCA certificate inside "Certs" folder.
- If everything works fine press the "Deploy" button and enter the following URL to check the Dashboard.
- The device's real-time location map is at:
http://localhost:1880/worldmap/
- This node performs the function of updating the location on the map every 10 seconds, the location is obtained by calling a free location API, processing with a function (written in Javascript) and sending it to the map node.
Note: We also send the location to AWS IoT so that we can notify you if the pet's location changes suddenly.
- This node receives each of the broker's payloads, filters according to the sensor which graph it has to go to and sends it to graph.
- This Node is one of the most interesting since its function is to wait for the temperature and humidity data to arrive in order to calculate the Dew Point, which is one of the standards for measuring comfort in the environment.
An important part of using our RSL10 kit is its ability to be an NFC tag. That opens up a world of possibilities for this product, so we may expand our market to anyone who has a dog. In addition to creating an ecosystem where, when you travel with your pet you can take care of it during the trip, it will also be an international ID for your pet in case it goes astray.
- This section has two main components, the identification web page and the API for user notification. We will explain them in detail:
For this we create a simple web page using NodeJS and ReactJS.
https://reactjs.org/docs/getting-started.html
The code of the web page is in the "WebPage" folder.
API:Lambda Creation:Create a "LocationLambdaPawMonitor" Lambda Function.
Note: Use your already created SNS ARN.
// Load the AWS SDK
var AWS = require("aws-sdk");
// Set up the code to call when the Lambda function is invoked
exports.handler = (event, context, callback) => {
var sns = new AWS.SNS();
var params = {
Message: "Your dog's tag was scanned, located at this location: https://www.google.com.mx/maps/@19.42,-99.1663,15z",
TopicArn: "arn:aws:sns:us-east-1:YOURSNSTOPIC"
};
sns.publish(params, context.done);
};
API Creation:Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.
In this API Gateway, you see a page that introduces you to the features of the service. Choose Get Started. When the Create Example API popup appears, choose OK.
If this is not your first time using API Gateway, choose Create API.
Create an empty API as follows:
Under Settings:
- For API name, enter PawMonitor-API.
- If desired, enter a description in the Description field; otherwise, leave it empty.
- Under Choose the protocol, choose REST.
- Under Create new API, choose New API.
Leave Endpoint Type set to Regional:
- Create the paw-monitor-api resource as follows:
- Choose the root resource (/) in the Resources tree.
- Choose Create Resource from the Actions dropdown menu.
- Leave Configure as proxy resource unchecked.
- Choose Create API.
- For Resource Name, enter paw-monitor-api.
- Leave Resource Path set to /paw-monitor-api.
- Leave Enable API Gateway CORS unchecked.
Choose Create Resource.
In a proxy integration, the entire request is sent to the backend Lambda function as-is, via a catch-all ANY method that represents any HTTP method. The actual HTTP method is specified by the client at run time. The ANY method allows you to use a single API method setup for all of the supported HTTP methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT.
To set up the ANY method, do the following:
- In the Resources list, choose /paw-monitor-api.
- In the Actions menu, choose Create method.
- Choose ANY from the dropdown menu, and choose the checkmark icon
- Leave the Integration type set to Lambda Function.
Choose Use Lambda Proxy integration.
- From the Lambda Region dropdown menu, choose the region where you created the GetStartedLambdaProxyIntegration Lambda function.
- In the Lambda Function field, type any character and choose GetStartedLambdaProxyIntegration from the dropdown menu.
- Leave Use Default Timeout checked.
- Choose Save.
- Choose OK when prompted with Add Permission to Lambda Function.
Deploy and Test the API
- Deploy the API in the API Gateway console
- Choose Deploy API from the Actions dropdown menu.
- For Deployment stage, choose [new stage].
- For Stage name, enter test.
- If desired, enter a Stage description.
- If desired, enter a Deployment description.
- Choose Deploy.
- Note the API's Invoke URL.
Checking the API with your invoke URL:
Due to the lack of NFC documentation, I will show the correct process for writing commands to NFC tags and simulating those commands.
Read the data in the NFC Tag:
Try to read the data inside the tag according to the ON Semiconductor IDE code.
According to the code you should be able to read the message "This is just a test".
In this case the reader of my cell phone tells me that it is not a compatible Tag, however what I could do was detect it as a Tag.
Since it could detect at least the tag, I created a simulation with an application called "NFC ReTag" to be able to perform actions with recycled tags or when it is not possible to rewrite them, in this case in particular a tag not compatible with reading.
NFC ReTag : https://play.google.com/store/apps/details?id=com.widgapp.NFC_ReTAG_FREE&hl=en_US
Video of how it works:
Real Process:The real process to write on NFC tags is the following one. We will make use of the NFC tools app, here I leave the example of how it works on a rewritable NFC tag, nevertheless when these tags are compatible with cellphone readers, this would be the process.
https://play.google.com/store/apps/details?id=com.wakdev.wdnfc&hl=en_US
Video of how it works:
Product:Travel dog crate with the device:
My dog with the device:
UI:
The device's real-time location map is:
http://localhost:1880/worldmap/
UI:
SMS:
Epic Demo:
Comments