THE FUTURE OF THIS
THE FINAL (GIT) PUSH
My final update of actual progress is what I have done with the app. My final blog will be all the update and the future for this project that I see. Currently I have updated the weather part of the application to use the Geolocation module that ionic uses in order to tell you the weather in your area. I have also edited the theme to make it more custom and personally appealing. I also added information about the app and project in the about page. I will be pushing the entire code base to GitHub tonight/early tomorrow morning.
Feel free to comment or message me if you have any questions about Ionic or my project! Thank you all for following my progress.
STM32 CODE (MBED)
Here is my last push effort to get my IoT Bike lock working. Unfortunately I haven't been as successful as I wished to be, but will continue working on it, even after the deadline, but will have a few more updates today with where I am at. I have updated the mbed code in order to lock and unlock the bike lock upon a secured Bluetooth connection, however, I have not yet implemented a way to get it to unlock and lock based on the push of the button in the app. This will be my next big step. I connect to the app using the BLE_API library that is provided in the mbed online compiler and used the BLE_HeartRate_IDB0XA1 as a starting point. I also have an instance of the sensor board, but as I have not figured out a way to change the state (locked/unlocked) that the alarm system relies on, it does not work properly. To implement this I used the X_NUCLEO_IKS01A1 and HelloWorld_IKS01A1 as a basis for understanding how it all works.
So I currently have a lock which does lock and unlock, just not on command, so it is a pretty useless lock, also causing the alarm system to be useless. These will be my next steps. Unfortunately, due to unforeseen circumstances, I was behind the ball on this project, causing an incomplete submission on the deadline. However, I am able to present a mostly complete project with a clear idea of how the last 10% should look. As I said, I will be posting a few more updates tonight, with pictures, code, and information on other parts of this project. I have enjoyed working with this technology and learning many new things along the way, and want to thank Element14 and STMicroelectronics for the opportnunity, and wish I could have completed my project sooner.
WEATHER API TECHNICAL DETAILS
My previous post showed the weather for your specific location (it was currently hard coded in, but will be updated to use the Geolocation module). This was using the wunderground API to get these details based on your city and state (look at home.ts). In order to do this you will need to make an account on wunderground and generate a free (or paid) API key. Now you can edit src/providers/weather/weather.ts and insert your API key, which should get you up and running.
I ran into some issues while using wunderground, as it seems the website is very finicky. I was not able to request a key until I was asked to confirm my membership, and had to do so on mobile rather than their desktop site. While this may not be true for everyone, I wanted to give fair warning that it is not the most friendly API to set up, but very friendly, and easy to call. Just look through my GitHub repository (home.ts, home.html, home.scss, app.module.ts, and weather.ts)!
Unfortunately I have been behind in my blogging and updates on this project due to midterms, however I have been making progress and will be blasting through updates this weekend (starting now!), so let's begin!
APP DEVELOPMENT UPDATE
My main focus lately has been on the app for this project. I have added in Bluetooth functionality in order to search for and connect to devices (specifically the IoT bike). I have also added more information on the lock/unlock button as the small icon was hard to see. Below all of this on the homepage I have added weather details so you know whether or not you need to bring your seat cover, or what to wear, or if you should even ride your bike that day (maybe not if it has been like it has been where I am from. Cold, dark, wet days.). Below you can see the images from the updated Dashboard page and my GitHub Repository as been updated as well.
IoT Platforms and Connections (The Technical Details)
THE LIBRARY/FILES CHOSEN
Conveniently, STMicroelectronics has a file bundle which provides examples for connecting a variety of boards to the Azure platform. It can be found at the bottom of this page, and is labeled FP-CLD-AZURE1. This bundle allows transmitting of sensor data to the cloud and receiving commands from cloud applications, using the X-NUCLEO-IDW01M1 (WiFi expansion board) and the X-NUCLEO-IKS01A2 (Sensor expansion board). A good tutorial/walk through to use can be found here on GitHub.
I have switched over to using the AC6 System Workbench for STM32 for this part of the project, as this is what most of the tutorials use. However, I am looking into porting it over to the mbed online compiler. Make sure you have the IDW01M1 on your board and now we can get into coding!
We will start by editing azure1_config.h which can be found in the "Includes" folder.
You will want to set up the WiFi connection here by editing the AZURE_DEFAULT_SSID and AZURE_DEFAULT_SECKEY to match your personal network. Then you will need to set up the AZUREDEVICECONNECTIONSTRING, which can be found in you IoTHub on your Azure Dashboard.
Once you have finished editing azure1_config.h, you can build all (found under the "Project" tab in the Workbench), and flash the binary to the Nucleo and you are ready to go!
Now you can download TeraTerm, or use your favorite serial terminal to see the messages which are successfully sent to your Azure IoTHub (this is the step I am currently on and will make an update post with data and pictures!)
IoT Platforms and Connections
Choosing A Platform
To connect my bike lock to the Internet of Things, I needed to find a platform which allowed me to easily upload and control the data that I push from the STM32 Nucleo board to the Internet and eventually the users device. After looking into multiple options, such as Amazon's AWS, Microsoft's Azure, and IBM's Watson/Bluemix. Based on my experiences with the sign up processes and amount of documentation I chose to use Microsoft's platform moving forward. After making this choice I was also lucky enough to have $100 in free Microsoft Azure credit given to me at a tech talk I attended.
You can find more information about all 3 platforms with the following links:
Microsoft Azure and IoT Capabilities
I started connecting to Microsoft Azure by following the documentation. I first created an IoT Hub, and Event Hub and a Device Provisioning Service, and linked the three services/hubs together. Once this was done I went into the IoT Hub and added a device, which allowed me to get my connection string and keys which I will use to connect the STM32 Nucleo to the IoT Hub.
I will now be focusing my work on linking my STM32 Nucleo, sending data from the sensor board, and pushing that through to my Ionic application.
As requested I have made a GitHub repository for my Ionic Application. I have opted to only upload the files that I am editing, as GitHub limits each upload to only 100 files and it would take me awhile to upload the entire project, however I will add a detailed ReadMe file that will allow one to add the proper supporting files and libraries used to get a working and functioning app.
APP DEVELOPMENT ADVENTURES
In my very first blog, I said the main IoT component of this project would be the app which all of the STM32 modules would connect to. So this week I began development on it, as I have never done any sort of app development before, and knew it would be a learning curve for me (as is learning to use mbedOs and programming the STM32). I started with what I was more comfortable with, Web Development/Web Apps. Starting here, and knowing my eventual end point of wanting an iOS or Android application, I was able to find a frame work which allowed me to cross the gap where my knowledge was limited.
THE EVER WATCHING I(EYE)
To begin I just thought of a basic design. An app with a tabular navigation at the bottom of the screen, which allows you to navigate to pages which: allow you to locate and place markers at your bike(s) location(s), lock/unlock your bike(s), and POSSIBLY if your bike is stolen you can track it's location and see exactly when it was stolen, etc.
Since this week was the beginning of the learning curve for me, I have been able to get a lot of headway done. However, this is not an app that will be completed in a week, especially as it will depend partially on communication with the STM32 Nucleo. I have a template with the tabular navigation model, a map which defaults to your current location, and allows you to add a marker to your current location. I have also added a button which changes its icon from unlocked to locked when pressed, which will eventually communicate with the STM32 and arm the security system, and lock the bike lock from my previous blog. You can see a some images of what I have currently below:
I will first be focusing on functionality of the app as I wish to complete this project, and with it being my first go at app development, I do not want to get bogged down with stylizing the app. If I have time towards the end of this project I will be going back and stylizing the app and adding a splash screen and other aesthetics.
OTHER CODING STORIES
Along with my fellow challengers I have been trying to flesh out which IDE is best to use. I, as well as others, have found that the mbed compiler looks very promising, and allows for easy IoT integration. So due to this, and the fact that I can enlist the support of the community and other challengers, I have decided to proceed with mbed's online compiler as my IDE of choice.
While using this I have decided to forgo the Infenion DC Motor Driver and just run the DC Motor straight from the STM32 board. There is a Servo library for the STM32 which uses a PMW pin to control the motor, so I will be using that. I have already wrote some sample code just to make sure it works (and it does!) so you can see a screen shot of the code and a video of the servo below:
LOCK IT DOWN!
As I mentioned in my previous blog post, one of the main components of this project is the locking mechanism. I need to develop an O lock which I can make IoT connected. In order to this I am making a quick prototype using 3D modeling and printing for a proof of concept (as I only have access to a plastic printer, and that would serve no real purpose as a bike lock material). The first mock up of this lock is simply an O shaped ring which houses another O shaped ring that is pushed by a gear to complete the O. For a better understanding of that awfully worded idea, see below:
This will be attached to a DC motor which drives the gear. The DC motor will then be attached to an Infineon DC Motor Driver cape for Arduino, which will attach to the Arduino compatible GPIO on the STM32 board. Below is a block diagram for the basics of this project.
Once I had the idea, and a basic model of what I want the lock to look like, I started the 3D modeling process. Below are 3 images which show you what I was able to create.
Once I had these modeled, it was time to print. I used an Afina H800 and ABS plastic for these prints, as this is the best 3D printer I currently have access to. Below are some pictures of the final outcome!
Now onto writing the code to actually get the stepper motor working and get a functional lock!
Design Overview for CycleOps IoT Project
IDEA: When riding a bicycle, it is pretty hard to insure its security in the same way we do our cars. Bicycles are much lighter, and easier stolen, and often are not locked properly. This project aims to provide a solution to this problem. I want to provide a locking mechanism which will aid a U-Bolt lock in not only preventing a bike isn't stolen, but neither are the wheels. This along side an accelerometer to measure movement once the bicycle is locked in order to trip a security system. This security system and lock will be a part of the Internet of Things through an app which lets you remotely monitor your bike (as well as remember where you locked it up for those with the forgetful mind).
CONCEPT 1: THE LOCK
The first concept for this project is the lock which secures the tires to the frame of the bicycle preventing theft. The lock will look very similar to the following:
However, the lock I want to implement (and prototype) will be an electronic version of this which will be triggered to lock/unlock through the app that I am going to develop. Yet, we all know that the internet and wireless signals are not the most reliable things in the world, so I will have a manual override option in cases where it is needed (this solution: an old school key as seen in above).
CONCEPT 2: THE SECURITY SYSTEM
Once the bicycle enters the locked state, the STM32 Nucleo and Sensor Expansion Board will be monitoring its movements. If the bicycle is moved it will trigger the STM32 to blast an alarm sound through an attached speaker, as well as flash an LED. I want to also implement a way for this to send a notification to your phone that your bike was attempted to be stolen, allowing for a higher chance of retrieval. I also want to implement a panic mode into the security system which will alert an Emergency Contact that you are in danger or hurt and can be triggered through a button push.
CONCEPT 3: THE APP
The final concept that is involved in my design is the app that ties it all together and makes this IoT. To do this I plan on using the Ionic framework, a useful framework which allows you to build native apps using Angular2 and cordova. This app will have a pin on a map with the location of the bicycle, as well as a button/toggle which allows the user to lock/unlock it and arm/disarm the security system. The app will also be linked to the panic mode button and place the call to the provided Emergency Contact. Since there will only be the one prototype using this I will not have to worry about unique identifiers so that only the proper bicycle is paired with, but it will be something I explore so that this may be able to go live in the future!