Here is the video of the project!
Full documentation coming next.
Introduction:I built a BT and BLE signal monitoring system that can detect the distance between one person and another by doing an analysis of the signal strength. In addition to being able to give the user a risk score on the exposure they have had to several people.
In addition to giving a daily exposure analysis through a website.
WebPage: https://d628z7yj7y4ti.cloudfront.net/
Differences with existing technologies and why our solution is better:
- 2020 PPC Video Role in Public Health Crisis | BriefCam
- Machine learning could check if you’re social distancing properly at work.
Most Ideas need an implementation of video cameras, image processing center, etc.
Our solution has the advantage of not needing to carry out complex video analytics to give distance results.
- Understand the impact of COVID-19 using real data
The Disadvantage of those ideas is that they perform an extrapolation of the social distance by country, instead of making a solution based on real data. Which our solution can generate.
SolutionOur solution has the advantage of not needing to carry out complex video analytics to give distance results. The advantage of using these simple systems is that they are easily achievable at a large-scale manufacturing level and can prevent the spread of new COVID-19 patients, in addition to generating an enormous amount of information and data on the social distancing of people in real time, added to this we can generate heat maps where we can see crowds and more risk of contagion.
Connection Diagram:Fortunately, the M5Core2 has many frameworks to be able to program them, however since my greater knowledge and code snippets have been done in the Arduino IDE. I took advantage of the Arduino support of the device to develop the solution more efficiently.
Install the ESP32 board support and the M5Core2 library to start working with the Arduino IDE.
- Arduino IDE - Program Link
- Arduino M5Core2 Library - Library Link
Although the Arduino IDE already comes with several examples to use the board, I leave several optimized and improved codes for you to get used to programming on this board.
Warning: The compilation of the code in Arduino can take up to 5 min, do not despair if the first compilation is taking long haha.
Main Code:The BlueSpace core code does the following:
There are two main reasons for using a JSON format:
- When scanning BT devices, it is normal to obtain two or more detections of the same device, when saving it in JSON it allows us to use the Address as a Key, which will eliminate multiple references.
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
doc[getAddress(advertisedDevice.toString().c_str())][0] = advertisedDevice.getRSSI();
// Device Address as a JSON Key
doc[getAddress(advertisedDevice.toString().c_str())][1] = dist(advertisedDevice.getRSSI());
// Saving the distance
if (minDist >= dist(advertisedDevice.getRSSI())) {
minDist = dist(advertisedDevice.getRSSI());
}
}
};
- In the Backend and Frontend of the application, the json format allows easier manipulation and organization of data.
To configure the credentials of the certs.h file, please go to this section AWS IoT Thing Creation
AWS Services:All the Cloud services used were exclusively from AWS for the development of the app, you do not need previous experience for this tutorial, however we recommend reading all the documentation of the services that we are going to use to avoid being confused with any term.
The services used are divided into two large branches, the services that the device uses mainly and the services that the WebApp uses to consume AWS.
Device Services:AWS IoT:This service is mainly intended to be able to communicate to our device in a secure way with AWS, this is done through MQTTS, that is, a subscription service and publication of data through topics.
In this case, our device will be the publisher, as you can see in the main code.
client.publish(AWS_IOT_TOPIC, string2char(output1));
In order to establish the connection correctly with AWS, a system of 2 certificates and a private Key are used that identify the device to AWS when we send messages to an Endpoint in HTTPS.
The steps to create a thing are currently very simple, first we must enter the AWS IoT Core service from the AWS Management Console.
Now we will create our thing, if it is the first time you create one, things should not appear as shown on the screen.
With AWS it is possible to create a whole brigade of devices at the same time, however for this project we will only need to create one.
As we can see in the following menu, we will see that we can configure many characteristics of things in order to be able to create categories, allowed digits between things, etc. However, we will only name our thing and press next at the bottom of the screen.
I highly recommend that you let AWS create the certify and manage them, so we leave the configuration that AWS offers us as recommended and click Next.
So that our device can send data correctly to AWS we must add a policy which allows this correctly.
The policy that we must implement for this prototype without any complications is going to be the following.
When creating the Thing AWS will give us all the necessary certificates, download them all.
With this, the only data that we would need to configure our device would be the AWS Endpoint, however that is in the Settings section.
So you should see the data arrive on your monitor in AWS.
Since we can send data to AWS, we cannot let it go to waste, we must analyze the data to be able to do an exposure tracing later in our app. So, as a first step we will now go to the DynamoDB service and create a DB with the following characteristics.
We just have to remember the name of the DB for the next step.
The simplest way to store the data we receive in the cloud automatically, is through an IoT Rule, this rule is a process that will be executed every time we receive a message in our Topic, as a serverless function. To create the rule we must go to the AWS IoT rules section.
We will create our rule only by placing the name we want and putting the following in the Rule query statement section.
The rule requires that we configure an action that will occur each data entry, in this case it will be the following.
Within this action the required configuration will be the following.
Once we finish this configuration, we will have the action of uploading data to the DB automatically.
Since we have all the services of the device running and sending data to our DB, now we must consume them in our App to show relevant data.
AWS Lambda:As the Connection Diagram says, the first step to consume the DB will be to create a lambda that performs a reading of the data, in addition, since our app must be able to perform readings by date, we must correctly program a scan of the DB.
In my case my solution was to use python as the Backend of the lambda function.
import json
import boto3
from boto3.dynamodb.conditions import Key
dynamodb = boto3.resource('dynamodb')
def lambda_handler(event, context):
table = dynamodb.Table("BlueSpace")
try:
response = table.scan(FilterExpression = Key('Time').gte(event["headers"]["first"]) & Key('Time').lte(event["headers"]["last"]))
return(response['Items'])
except:
return("Error")
We will notice that the code contains the reference of event ["headers]["ANY_LABEL"], this will make that API Gateway can send the variables in the headers.
AWS API Gateway:In order to consume the lambda function from our website, we must create an API that we can call from the app.
We put the name we want to our API and we give it next until it is created.
Once we have our API, we will have to create a route, which will be the "path" to which you will make the call.
The integration of Lambda in the API will be the following.
NOTE: When adding the Lambda integration to our API Gateway, the permissions will be automatically configured.
Postman Test:To test that our API is working, we will use some software to test the request like Postman. If we put two dates in the API, our scan will return as the image shows.
Now if we want to consume the API in our web page we will have to configure the Cross-Origin Resource Sharing as shown in the image, the important part of this configuration is to allow our web pages as Authorized Origin.
NOTE: without this we will not be able to consume the API from the web page.
AWS S3:In order to deploy the web app to the entire internet, we must create an S3 bucket, which will be in charge of storing the files of the web page and performing the static web site hosting.
Being an application made with the ReactJS framework, it is only necessary to place the files inside the bucket by dragging them.
In the properties section we can activate the static website hosting, this will give us a URL which we can access from anywhere in the world, however for the deployment of an application to production, this alone is NOT enough.
AWS CloudFront:With this service we can ensure that our page obtains an SSL certificate and give us the benefits of the CDN.
Since this service works without problem, we will be able to see our web page running, with access to the api that we created and with its SSL certificate.
Feel free to enter the page and explore my history of exposure to people in my day to day.
WebPage: https://d628z7yj7y4ti.cloudfront.net/
Final Product:Device:To test that the device worked in a real environment, I did a field test with the device on my weekly visit to the supermarket.
Final DemoConclusion:The project is valuable on the hardware side because it has economies of scale on its side. Nevertheless, the most important part is all the data that we can be recollecting with several of these devices programmed in that way. The M5 Core in combination with AWS cloud and tools offers us a quick and easy way to get data from the physical world to the digital one and well if we are already carrying a cellphone with us, I do not see why we wouldn't carry a device to protect ourselves.
Comments