I tend to hit the snooze button on my alarm clock a lot then end up waking later than I wanted to. The Azure Smart Snooze Alarm Clock adjusts the wake up time to compensate for the amount of time you tend to snooze. This way you wake up when you are supposed to wake up.
For example, if you snooze the alarm for 7 minutes one day. The next day, your alarm will activate 7 minutes earlier (well, an average of the past alarms, but you get the idea).
The alarm also aims to help you get better sleep so that you can live a healthier life. This can help you achieve the United Nations Development Programme Sustainable Development Goal 3 of Good Health and Well-Being. Sleep is very important to your immune system. I know personal anecdotal evidence of watching shows or playing games (just one more level syndrome) staying up all night then hardly getting any sleep and working the next day that I tend to get sick more often. You can use the IoT Central tracking of data to track how long you take to wake up. If you are taking long to wake up, that means you are probably not getting enough sleep and thus weakening your immune system.
This project uses the Azure Sphere MT3620 Starter Kit. I like this board because there are expansion ports that you can attach Mikroe Click Boards. This projects calls for you to make your own 2 very simple boards. One board houses the alarm Button A (not to be confused with the onboard button A) and buzzer. The second board hold Button B (also not to confuse with onboard button of the same name) and the OLED screen.
Hardware SetupPlease follow directions at Avnet's Azure Sphere Starter-Kit (Out of Box Demo) Part 1 of 3 for the Getting Started and First things first section.
Custom Click BoardsBelow is a Fritzing schematic of the two separate boards you will need to make.
I cut a small 5cm x 7cm protoboard in half. Each piece is just the right size for a snap on board. You could cut off the excess but I just left them.
There are only a few components and lots of room to work with. You can look at the pictures above to get a sense of where I put the parts but feel free to put them wherever as long as you connect the correct part to the correct pin of the sockets.
IoT Central SetupYou will need to a subscription to Azure or use the free trial. I link to Microsoft tutorials as my screenshots may get out of date but the information should still be similar.
1. Create an Azure IoT Central application with the following settings:
- Application Name: SmartSnoozeAlarmClock-[somethingunique]
- Url: [auto populates, okay to leave alone]
- Application template: Custom application
- Billing Info: Your info
- Location: Your location
I think you have to give your application a unique name so just tack something on to the end or make up your own name.
2. Define a new device type in your Azure IoT Central application with the following settings:
- Name: SnoozeAlarmClock
3. Add Telemetry with the following setting (instructions on the Define a new device... page):
- Display Name: Snooze Time
- Field Name: snoozeTime
- Units: minutes
- Minimum Value: 0
- Maximum Value: [blank]
- Decimal Places: 2
- Color: [whatever you want]
4. Add Event (similar to adding Telemetry above):
- Display Name: Alarm Tiime Set
- Field Name: alarmTimeSet
- Default Severity: Information
5. Setup a dashboard and add a Line Chart and Event History to view data. The event data is just a quick test to see if you are sending information to the cloud and not have to keep setting an alarm to test connectivity.
Reference Manage devices in your Azure IoT Central application if my images go out of date, should still be similar.
1. Click on Devices from the left menu and then click the + sign to the right and select Real.
2. In the Create New Device form you will need your Device ID. To get your device ID run the following command from the Azure Sphere Developer Command Prompt:
powershell -Command ((azsphere device show-attached)[0] -split ': ')[1].ToLower()
You should get a long string of numbers and letters. Copy and paste that into the Device ID textbox. The Device Name will auto populate, change if you want to.
1. Get CA certificate. Similar instructions also at Set up Azure IoT Central to work with Azure Sphere. Login to your tenant with the following command in the Azure Sphere Developer Command Prompt:
azsphere login
You should get something like 'The selected Azure sphere tenant 'blahblahblah' yada yada yad...'. Then enter the following command to get the Certificate Authority certificate:
azsphere tenant download-CA-certificate --output CAcertificate.cer
You should now have a CAcertificate.cer in the directory you ran the command.
2. Click Administration on the left menu then Device Connection when the new set of menus display.
3. Click on Manage Primary Certificate toward the bottom to open the certificate form. Click on the folder icon to the right of the Primary text box and upload the CACertificate.cer that you got earlier.
4. You will see a 'Needs verification' notice. Click on the refresh icon towards the bottom to generate a Verification Code. Do not hit Verify just yet. Take note of the code or press the copy icon to copy the code.
5. Back at the command prompt enter the following but replace <code> with the Verification Code in the previous step:
azsphere tenant download-validation-certificate --output ValidationCertification.cer --verificationcode <code>
You should now have a ValidationCertificate.cer file.
6. Click Verify in the Primary Certificate form and select the ValidationCertificate.cer file from the previous step. If all went correctly you should see that your certificate has been verified. Click Close.
1. Clone the Azure Spheres Sample from https://github.com/Azure/azure-sphere-samples as we will use their tool ShowIoTCentralConfig.exe to get information about your IoT Central Application for this project. The tool is in the Samples/AzureIoT/Tools/ folder.
2. Clone the Azure Smart Snooze Alarm project from https://github.com/bbtinkerer/azuresmartsnoozealarmclock
3. Rename app_manifest.example.json in the src/AzureSmartSnoozeAlarmClock/ folder to app_manifest.json
4. Run the ShowIoTCentralConfig.exe from the command prompt and answer the questions.
- Are you using a Work/School account to sign into your IoT Central Application (Y/N) ? [Y/N depending on what you used]
- Enter the Scope Id from the IoT Central App 'Administration | Device Connection' > [Exactly what it says, the ID Scope from the Device Connection page]
- Enter any real Device Id from the IoT Central App> [The device of your ID if you still have it in the command prompt or you can grab it from the Devices page]
If all went well, the tool will tell you what to modify in the app_manifest.json minus your tenant ID.
5. Get your tenant ID by running the following command:
Azsphere tenant show-selected
You should get your tenant ID as output.
6. Open the solution file AzureSmartSnoozeAlarmClock.sln in the src/ folder. Update app_manifest.json with the information from the previous two steps. You will update:
- CmdArgs
- AllowedConnections
- DeviceAuthentication
7. Build the application.
8. Press the Debugger button to load and run the program on your device (make sure your device is connected first).
The current snooze time is set 20 seconds that was meant more for testing. You can up the snooze time by update SNOOZE_LENGTH to however long you want in seconds.
Confirm IoT Central ConnectionYou should see debug messages in the Visual Studio Output window showing that the device connected to the cloud.
You may see a few "[Azure IoT] IoTHubDeviceClient_CreateWithAzureSphereDeviceAuthProvisioning returned 'AZURE_SPHERE_PROV_RESULT_DEVICEAUTH_NOT_READY'" messages but eventually the device should connect. If not, recheck your configurations.
Set an alarm or set off an alarm using the instruction in the next section.
In IoT Central, look at the device dashboard and you should see some activity.
In the above example, I took 22 minutes to turn of the alarm and the events show that I was setting the alarm often. Also, just looking at the alarm time triggers a time set.
Alarm InstructionsThe alarm has 4 buttons:
- A - Click Board 1
- B - Click Board 2
- C - Onboard button A
- Setup - Onboard button B
The board automatically gets UTC time. First you will want to set your timezone unless you like UTC. This is Unix style timezone so this is the amount of hours you need to add to your local time to get the UTC time.
To set timezone:
- Press Setup
- Press C
- Use A to toggle +/- and B/C to increment/decrement hours
- Press Setup to save the timezone.
To set alarm time:
- Press Setup
- Press A
- Use A/B to increment decrement hours
- Press Setup
- Use A/B to increment/decrement minutes
- Press Setup to save the alarm time
To enable/disable alarm:
- Press and hold A to view the current alarm time
- Press C to toggle alarm on/off
- Release A to save
The alarm will keep a rolling average of how long you take to turn off the alarm and try to wake you up before your set alarm. That way you snooze into your intended wake up time instead of snoozing away and waking up later.
Use the IoT Central Dashboard to keep track of how long you are snoozing. Change your sleeping habits to a healthier life so that you wake up on time. Make a game out of it, lowest time wins and the prize is you wake up on time and know that you are living healthier!
Thank you.
Comments