State Machine Temp Sensor with Bluetooth

Job ID: 39365465

Budget: $30 – $250 USD

I need a developer to finalize a project using VS Code. The project involves a state machine framework to manage temperature sensor data and coordinate system behavior.

Key requirements:
- Implement a state machine to manage temperature sensor data.
- Integrate Bluetooth communication.
- Use a state machine framework like XState, SML, or PHP State Machine.
Use best version control practices throughout the development of your firmware.
Use branches for development and merge into your main branch when the code is stable.
Commit often with meaningful commit messages.
Branches should be merged when focused, functional changes are complete.


Best Coding Practices

Use best coding practices throughout the development of your firmware.
Functions should be short and do one thing. They should return an exit code that is checked in the calling function, indicating success or failure.
MACROS! Avoid hard-coded values in your code.
Use structs to organize related data.
Use libraries for code that is self-contained.
Use the LOGGING module to log errors, warnings, information and debug messages.
You should not have any compiler/build warnings. The CI script will build against v2.9.0 of the Zephyr SDK.


Firmware Functional Specifications

Write all firmware using the state machine framework.

Do all device initialization in an INIT state.
Have an IDLE state when the device isn't making any measurements.
Have an ERROR state if any error exit codes are returned from any functions.

All 4 LEDs should blink at a 50% duty cycle (ON:OFF time), in-phase with each other, in the ERROR state.
An error condition should post an error-related event that causes the device to enter the ERROR state.
The error code should specify the error condition that caused the device to enter the ERROR state. For example, you may choose to have a bit array that can capture multiple error conditions.
A BLE notification should be sent with the error code (see BLE custom service/characteristic below).


Implement states of your choosing for the following measurements, calculations and BLE communications.


Have a heartbeat LED0 that blinks every 1 second with a 50% duty cycle (ON:OFF time) in all states.
Implement functionality to measure a battery voltage (0-3.0 V) using AIN0:

When the device first powers on, and then
Every 1 minute thereafter, but only when in the IDLE state.
You won't actually be connecting a battery to your device; you can use a power support or another voltage source to input a voltage to AIN0 to simulate a battery level.


Have the brightness of LED1 linearly modulated by the percentage of the battery level.
Implement functionality to make two measurements after pressing BUTTON1:

Read temperature with your MCP9808 sensor (in degrees Celsius).
Calculate the average heart rate (40-200 BPM) using 25-30 seconds of an ECG signal (ranging from -500 - 500 mV, note this is bipolar) from the function generator (see video on how to setup the function generator to output an ECG signal).


Pressing BUTTON1 during the measurements should post an error and go to the ERROR state.
Blink LED2 with a 25% duty cycle (ON:OFF time) at the average heart rate after the measurements are complete.
Have Bluetooth notifications after the measurements are complete and data have been processed, using the BLE services and characteristics described below.

Configure the DIS (Device Information Service) to report the device model as your Team Name (come up with something fun).
Set the BAS (Battery Service) to report the battery level of your device. (This isn't actually a battery level, but we're using the AIN0 measurement as a surrogate for a battery level.)
Set the Heart Rate Service to report the average heart rate. (See Resources section below.)
Setup a custom service with the following custom characterisitics:


Temperature for the I2C temperature sensor data in degrees Celcius.

Error Code for the error code that caused the device to enter the ERROR state.





BUTTON2 should clear (turn off) a blinking LED2, and if LED2 is not blinking because a measurement hasn't been taken, then it should log a warning (LOG_WRN()) as to why it appears nothing happened.

BUTTON3 should be used to reset the device from the ERROR state and return to the IDLE state.
Use timers, kernel events, work queues, threads and any other Zephyr RTOS features as needed to implement the above functionality.


BLE Server (Mobile App)

Your device can connect via BLE to a mobile app called nRF Connect.
This app can be used to read the services and characteristics that your device is advertising.