Skip to content

Pier4201/tilt_detection_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tilt Detection System – Embedded C++ + Node.js Server + Web Interface

A complete system for tilt detection using the MPU6050 sensor with a Raspberry Pi 5.
This project includes:

  • C++ embedded code for sensor data acquisition
  • Node.js server with REST API
  • A static HTML+JS frontend served via Express whose content will then be dinamically updated through WebSocket and JavaScript

Repository Structure

main branch: current working version
reactjs-version branch: previous version with React interface


Development Environment

  • Host machine: Ubuntu 24.04 (amd64)
  • Target machine: Raspberry Pi 5 (Debian 12 – arm64)
  • IDE: Visual Studio Code

Toolchain

  • Compilers: aarch64-linux-gnu-gcc/g++-12
  • Libraries: i2c, curl, pthread
  • Build system: CMake

Embedded Code (Example.cpp)

  • Language: C++
  • Description:
    • Initializes MPU6050 (3 axys accelerometer + 3 axys gyroscope)
    • Computes offsets
    • Reads raw sensor data and calculates tilt angles
    • Packs data into a JSON object
    • Sends it to the server using a POST HTTP request via curl

Backend + Frontend

Stack

  • Languages: JavaScript (Node.js + Express), HTML/CSS
  • Runtime: Node.js
  • Security: TLS encryption over HTTPS
  • Real-time updates: socket.io (bidirectional, real-time and low latency communication)

Communication Flow

C++ → Node.js (POST)

  • The embedded client sends a JSON payload to /data

Node.js → Browser (WebSocket)

  • The server forwards real-time data to connected clients via socket.io. Data contained in the chart and table will update every time a new JSON payload is received.

Browser → Node.js (GET)

  • The browser sends a GET request to / and receives the HTML page index.html
  • The page includes:
    • A table displaying all received tilt data
    • A live-updating chart
    • Filter by ID working on both table and chart
    • Visual alerts when thresholds (2.5 °) on roll pitch and yaw values are exceeded

Web page preview

A preview of what the user would see on his browser when visiting the web page:

Web Interface Screenshot