element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle IoT Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Upcycle IoT Design Challenge
  • More
  • Cancel
Upcycle IoT Design Challenge
Blog ColdCase - Blog #6 - The Android app
  • Blog
  • Forum
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Upcycle IoT Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 25 Jan 2024 5:49 PM Date Created
  • Views 493 views
  • Likes 5 likes
  • Comments 2 comments
  • coldcase
  • Upcycle IoT Design Challenge
Related
Recommended

ColdCase - Blog #6 - The Android app

amgalbu
amgalbu
25 Jan 2024

To control the mini fridge remotely, I developed an Android app that connects on a Bluetooth channel to the Curiosity Nano board.

Other posts in this serie

  • ColdCase - Blog# 1 - Introduction
  • ColdCase - Blog #2 - The refrigerated cell
  • ColdCase - Blog #3 - Preparing the environment
  • ColdCase - Blog #4 - The software
  • ColdCase - Blog #5 - Final assembly
  • ColdCase - Blog #6 - The Android app
  • ColdCase - Blog #7 - Final assembly

1. Bluesmirf module

Inside the mini fridge, I installed a Bluesmirf board. This board is now obsolete, but it can easily be replaced by a more up-to-date board that implements the Bluetooth serial-replacement profile

 image

image

image

The Bluesmirf has a default baudrate of 115200 and I am not going to change this default. The init() function performs the following tasks

  • Switch from data mode command mode, by sending the string “$$$”
  • Send the command to set Bluetooth slave mode (this is not strictly required, since this is the Bluesmirf’s default mode
  • Switch from command mode back to data mode by sending the string “---”

void BlueSmirf::init()
{
    SERCOM3_USART_Write((uint8_t*)"$$$", 3);
    SYSTICK_DelayMs(100);
    
    SERCOM3_USART_Write((uint8_t*)"SM,0\r", 5);
    SYSTICK_DelayMs(100);
    
    SERCOM3_USART_Write((uint8_t*)"---\r", 4);
    SYSTICK_DelayMs(100);
}

2. Communication protocol
I implemented a protocol where the Android app continuously sends commands and the Arduino board continuously replies with its current status. The request is made of the following bytes

‘$’: Start-of-frame character
<Mode>: 0=automatic, 1=manual. In manual mode, user can drive the robot up, down, left or right
<Command>: the command to execute.
                The supported commands are
                    Open front door
                    Close front door

                When no command has to be executed, this field is 0

<Outputs>: output status to set. This is a bits field, where the bits have the following meanings
                Bit 0: 1=switch fan on
                Bit 1: 1=switch Peltier cell on
‘#’: End-of-frame character

 

The response has the following fields

‘$’: Start-of-frame character
<Application status>: 0=automatic, 1=manual. In manual mode, user can drive the robot up, down, left or right
<Outputs>: current status of the outputs. This is a bits field, where the bits have the following meanings
                Bit 0: 1= motor roller running, 0=motor roller stopped
                Bit 1: 1= valve open, 0=valve closed
<Temperature>: current temperature in degrees multiplied by 10, represented on two bytes (first byte is the MSB)
<Humidity>: current Y position, represented on two bytes (first byte is the MSB)
‘#’: End-of-frame character

All the logic to manage the communication protocol is implemented in class BlueSmirf (see bluesmirf.h and bluesmirf.cpp)

3. Android app

User can interact with the robot by means of an Android app, whose interface is shown in picture below

 image

4. Biometric authentication

When user wants to open the fridge's door from the app, its identity is authenticated by means of fingerprint detection. This is implemented in the BiometricCheck class. First, the application checks if the biometric authentication has been enabled on the phone. If this is not the case, the authentication fails and user is not allowed to open the fridge's door

    private void checkBiometric() {

        BiometricManager biometricManager = BiometricManager.from(context);
        String error;
        switch (biometricManager.canAuthenticate()) {
            case BiometricManager.BIOMETRIC_SUCCESS:
                Log.d(TAG, "App can authenticate using biometrics.");
                showBiometricDialog();
                break;
            case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
                error = "No biometric features available on this device";
                showToast(error);
                break;
            case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
                error = "Biometric features are currently unavailable.";
                showToast(error);
                break;
            case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
                error = "The user hasn't associated any biometric credentials with their account.";
                showToast(error);
                break;
        }
    }

If the biometric authentication is available, the biometric dialog is initialized. Here, we also define the callback to be called when authentication is successful or fails

   private void initBiometrics() {
        executor = ContextCompat.getMainExecutor(context);

        FragmentActivity fragment = (FragmentActivity) context;
        biometricPrompt = new BiometricPrompt(fragment, executor, new BiometricPrompt.AuthenticationCallback() {
            @Override
            public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
                super.onAuthenticationError(errorCode, errString);
                showToast("Authentication error: " + errString);
                listener.onFailed();
            }

            @Override
            public void onAuthenticationSucceeded(
                    @NonNull BiometricPrompt.AuthenticationResult result) {
                super.onAuthenticationSucceeded(result);
                listener.onSuccess();
            }

            @Override
            public void onAuthenticationFailed() {
                super.onAuthenticationFailed();
                showToast("Authentication failed");
                listener.onFailed();
            }
        });

        //create prompt dialog
        promptInfo = new BiometricPrompt.PromptInfo.Builder()
                .setTitle("Biometric login for my app")
                .setSubtitle("Log in using your biometric credential")
                .setNegativeButtonText("Cancel")
                .build();
    }

Finally, the biometric authentication dialog is shown

   private void showBiometricDialog() {
        //initialize everything needed for authentication
        initBiometrics();

        //show biometric dialog for authentication
        biometricPrompt.authenticate(promptInfo);
    }

  • Sign in to reply
Parents
  • DAB
    DAB over 1 year ago

    Nice update.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 1 year ago in reply to DAB

    Thanks DAB 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • amgalbu
    amgalbu over 1 year ago in reply to DAB

    Thanks DAB 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube