This repository contains the code for an ESP8266 based pedometer which makes use of the MPU6050 sensor to measure the motion and provides HTTP endpoints for the data. It also includes various utility functions to manipulate the data gathered from the sensor.
- PlatformIO
- ESP8266 Development Board
- MPU6050 Sensor
- Adafruit MPU6050 v2.0.3
- Adafruit Unified Sensor v1.1.4
- ArduinoJson v6.21.2
Firstly, clone the repository to your local machine.
To install the required libraries, follow these steps:
- Open the PlatformIO home page in your IDE.
- Go to
Libraries
. - Search for
Adafruit MPU6050
,Adafruit Unified Sensor
andArduinoJson
. - Click on each library and click
Add to Project
. Choose this project to add the library to it.
After installing the required libraries, build the project using the PlatformIO Build
option.
Connect the ESP8266 and upload the code using the PlatformIO Upload
option. The sensor data can be viewed from the serial monitor.
The firmware provides the following HTTP endpoints:
GET /api/data
- Returns the sensor data.GET /api/user
- Returns the user data.POST /api/user
- Accepts the user data in the form of JSON. The format of the data should be:{"weight": <value>, "height": <value>, "age": <value>, "gender": <value>, "calorieGoal": <value>}
.POST /api/start_workout
- Starts a workout session.POST /api/stop_workout
- Stops a workout session.POST /api/pause_workout
- Pauses a workout session.POST /api/resume_workout
- Resumes a paused workout session.GET /api/workouts
- Returns a list of all workouts.GET /api/workout?file=<workout file>
- Returns the details of a specific workout.
The data from the /api/data
endpoint is returned in the following format:
{
"acceleration_x": "<float>",
"acceleration_y": "<float>",
"acceleration_z": "<float>",
"gyro_x": "<float>",
"gyro_y": "<float>",
"gyro_z": "<float>",
"motion_state": "<string>",
"calorie_burn": "<float>",
"step_count": "<int>",
"timestamp": "<unsigned_long>"
}
The user data from the /api/user
endpoint is returned in the following format:
{
"weight": "<float>",
"height": "<float>",
"age": "<int>",
"gender": "<string>",
"calorie_goal": "<float>"
}
Ensure that the sensor is connected correctly. If the device fails to find the MPU6050 sensor, check the connections.
If the device does not connect to WiFi, ensure that the correct SSID and password are entered in the ssid
and password
variables respectively in the web_handlers.h
file.
For further issues or assistance, you can raise an issue on this repository.
- Tim Vučina & Andrej Kronovšek