In this project, we will kick start the path where Filipinos start building bridges that benefits both the pedestrians and vehicles that crosses it.
Backstory:In the Philippines, in the capital region to be exact, bridges are vital to the movement of people. Rivers and roads divides the region into bits and pieces on which people and cars needed bridges to cross over. Sadly, most bridges are built with only cars in mind ( Sadly moving cars are preferred than moving people ).
In the images below are some of the bridges here.
Bridges:
Sandoval Bridge
Bagong Ilog - Rotonda Bridge
Kaginhawaan Bridge
Some more extra details:
C5 corner Julia Vargas Pedestrian Bridge
C5 corner Lanuza Pedestrian Bridge
Bridges ( check limitations on type of bridges ) aren't made were both cars and pedestrians would both benefit
Limitation:The problem at hand won't be solved via the hardware alone, but hopefully this project kick starts the ball on which this problem would eventually be solved while still taking advantage of the AVNET SmartAgile Device
The bridges that I'll be experimenting on are mostly found near my location making the project biased by location.
I'll also try taking data on pedestrians bridges for comparison and see if any type of bridges in the area are built with pedestrians in mind
Solution:Create a device that identifies if the current bridges built are beneficial for both cars and pedestrians or not.
Process:With all the specifics done, let's start the project.
STEP 0: Prerequisites
Gather the needed materials. Check the Component and Apps section for the list of materials and apps.
STEP 1: Setup
Before we could start with our AVNET device, we must first setup our gateway. Power up your raspberry pi then connect your it to an external monitor, then let's start the process.
Let's start off with installing the needed dependencies to make our AVNET SmartAgile Device work. Open up a terminal then type the following commands.
First let's install bluez. Copy the command below to your terminal and run it. It'll install bluez and its dependencies
$ wget https://brainium.blob.core.windows.net/public/raspberry/bluez.run
$ sudo sh bluez.run
Note:
- Make sure that your os is updated and upgraded before installing bluez.
If ever you encountered any problem you could try running the commands below then restart running the bluez installation.
Last resort would be formatting the SD Card then installing the latest version of the distro you desired.
$ sudo apt-get -f install
$ sudo apt-get update
$ sudo apt-get upgrade
In the sample image below, I encountered an error in installing bluez, which was solved by formatting the SD Card then installing the latest version of Raspbian.
Next run the following commands
$ wget https://brainium.blob.core.windows.net/public/raspberry/brainium-gateway-latest.run$ sudo sh ./brainium-gateway-latest.run
The command will fetch the file brainium-gateway-latest.run from the link then install the brainium gateway.
You can then verify that you have a running brainium gateway by running the command
$ brainium-gateway
...which would return
$ brainium-gatewayCommand (h for help):
Great! Now we're finished setting up the raspberry pi. Let's move on to the next task
STEP 2: Setup Brainium
For this we'll setup the brainium accounts that we'll use to create our models in the cloud.
First, we need to create an account. We could create our accounts using the link: https://spa.brainium.com/signup. Follow the instructions given until you can login to your brainium account.
Once you are logged in, we'll need to connect the raspberry pi we've setup on STEP 1 as a gateway for our AVNET SmartAgile Device.
Go click the hamburger on the upper left side, beside the word Brainium, this would open up the tabs on the left, then click the Devices tab. This will redirect you to the Equipment page on which you'll be able to create connections to the devices you want to act as gateways.
To add our raspberry pi. Go back to the terminal you opened before. Then run the brainium-gateway, after running type login, which it will prompt you to login your credentials. After logging in, your device would be recognized by Brainium web service.
Run the commands below to login your brainium account
$ brainium-gatewayCommand (h for help): loginUser name: user@email.com
Password:Authenticating ... completed successfully!
Device information would be shown on the dashboard. You could see from the image below that the raspberry pi I'm using is currently shown in the dashboard. As an extra, if you'll be using multiple gateways, update the name of the device.
After connecting your gateway you'll now be able to see the same screen as the image above. Next, let's add the AVNET SmartEdge Agile Device to the gateway. Click the Plus Button then press the button, you'll then be redirected to a new page on which it will say Device Addition, there you'll need to press on your AVNET SmartEdge Agile Device button firmly. The image below shows where the button is placed. ( The button is placed beside a blinking LED ), I've also added other photos of the device for you to compare to your own device.
While pressing the AVNET SmartEdge Agile Device the device information would eventually show on the screen and allows you to confirm the device. After confirming, you now have successfully connected your AVNET SmartEdge Agile Device to the gateway. On the image below you could see what's happening to the page while it is still trying to connect to the device. Had a hard time connecting mine due to two reasons
- The button on my device was hard to press and kind a stucks every now and then.
- My internet connection that time was slow, causing the page and gateway connection to go down.
After confirming our gateway and devices are connected, we could now move to starting our project.
STEP 3: Create a Brainium Project
On the top left of your screen click the hamburger icon then click the List of Projects , you'll then be redirected to a new page, the same page as seen in the image below. Click the plus button on the lower right to create a project.
...you'll be redirected to the page below, add the name of the project. I'd name mine BridgeInformation. You could skip adding a widget image for now
...after creating a new project, you'll be redirected to the previous page. You then need to click the newly created folder with the name BridgeInformation. You'll now end up with the same page as what I have below.
...after clicking the dashboard tab, you'll also get the same dashboard page
...then click the plus button below, so that we could create our first new widget. A new view would pop up on the right side of the screen.
...then choose the necessary widget type and visualisation type. For this we'll pick Proximity distance for the widget type then Line Chart for the visualisation type.
I'll show all the various widgets that was used in the project on the last part of the story
...then click the next button. After clicking, we then need to choose the device where we could attach the newly created widget to.
STEP 4: CREATE YOUR TRAINING DATA
Now since we've created our widget and attached our device that widget we could start creating our training pipeline.
Click the hamburger on the upper left of the page then click Motion Recognition. You'll then be redirected to the page below
...click the plus button to create a new workspace.
...After creating the new workspace, you'll then be returned to the Motion Recognition page. The newly created workspace would now be visible there. On which after you click it, you'll then be redirected to the pipeline page below.
...next, click on the text field then add the name Proximity, then click the plus button beside it. After that we've now created our motion type.
Now we can run the Record New Set button to start creating our training data. You'll first be prompted to choose which device then the device would send the data it gathered to the gateway via bluetooth in turn it will send the data to the portal.
...the example below, signifies the generation of the training data and visualized line chart as we described earlier.
STEP 5: CREATE THE BACKEND
On this part we'll start creating the backend service that will retrieve all the data stored in the brainium portal for us to generate the necessary files
First, let's create our backend service. Run the commands below to initialize the repository.
$ mkdir bridge
$ cd bridge
$ git init
Then, let's create the backend microservice that will contact the Portal REST APIs to get the data. Run the commands below to initialise the package.json
$ mkdir backend
$ cd backend
$ yarn init
...after initializing the package.json, we then need to add / install our dependencies. Run the command below to create all the dependencies needed.
$ yarn add dotenv-safe esm got koa koa-bodyparser koa-router swagger swagger2-koa
$yarn add --dev chai eslint mocha nodemon
...then add the scripts key for us to run the project easily. Your package.json should now look like the image below.
...next we need to create our swagger specs. Copy the code from the image below or you could go to the code section to copy the swagger spec.
...we could then verify swagger errors by placing our swagger spec over editor.swagger.io. The image below shows the working client and swaggerui.
...next we need to build the server, I've added the index.js image below, follow the code section for the other parts of the server.
...next we need to query the Portal REST API to retrieve the data we need.
After building the necessary code for the backend, your directory ladder should be the same as the image below.
Now we are ready to run our backend application to fetch all the data we've gathered.
Open up a terminal.
Then type the command 'yarn start'. This will run the script `start` which was stored inside our package.json file.
Now, that we've run our server, we could now fetch the data
STEP 6: SETUP HARDWARE FOR TESTING OUTSIDE
Now that we have all the necessary parts of our project let's start gather some data.
So first, we must make our setup portable.
For this I've gathered the hardware listed below and attached them to my raspberry pi
- Powerbank
- USB Cord
- Phone
- Pocket Wifi ( You could also setup a hotspot with your phone )
Connect your Raspberry Pi to the powerbank and start it up.
Once the raspberry pi is on, connect the raspberry pi to your pocket wifi or to the hotspot you've created. Make sure that the brainium portal was able to detect the gateway you've created.
Once you see that the raspberry pi is present on the brainium portal, we could now go outside and test our setup.
STEP 7: GET OUTSIDE DATA
First I went to Sandoval Bridge, a well used bridge by both cars and pedestrians, here I placed the AVNET Smart Agile Device near a pole for a while and let it gather data. As it gathers data, I try to also check the data being passed to the portal using my phone.
On the image below you could see some of the images while the AVNEt Smart Agile Device is being tested on Sandoval Bridge
Sandoval Bridge
After a few minutes of testing and verifying that it was able to get the data we needed, I now moved to the next bridge. Kaginhawaan Bridge is a newly built bridge on which was made as a shortcut for pedestrians and vehicles so that Sandoval Bridge won't be overcrowded.
Again, same as what I did with the previous bridge. I placed the AVNET Smart Agile Device on one of the Poles of the bridge and waited again if it will get the data I needed.
On the images below, you'll see how I tested the device on the Kaginhawaan Bridge
Kaginhawaan Bridge
STEP 8: RUN THE BACKEND SERVICE TO RETRIEVE DATA
After retrieving our sample data, we could now return to our local setup.
Open up `localhost:4000/motion/:deviceId` and wait for the it to fetch the data we created.
The endpoints must return the data it found from the brainium portal.
Copy the data to a file then save it.
STEP 9: DOCUMENT DATA
Now that all the data we needed are present, we could collate those information and build a template where we can prove that the bridges that we use are not beneficial for both pedestrians and vehicles. I'll update this document once I've finished building the template and had it verified.
STEP 10: NEXT THINGS TO DO
Now that we've tested that we can gather data for our cause. Let's plan out the next task to do
- Deploy the service
- Create a python script to build the document
- Build a production ready sensor cluster for each bridge that will continue to retrieve data
- Also test pedestrian bridges
Resources:
- How to prepare your raspberry pi: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/3
- Hackster.io Blog about AVNET: https://blog.hackster.io/hands-on-with-the-smartedge-agile-b7b7f02b5d4b
- Brainium Signup: https://spa.brainium.com/signup
Comments