Open Source IoT Management System! Includes User Authorization System, Location Monitoring, Distance Calculation, and Service Health Monitoring

IoT management system based on Gin/Fiber and Vue3Source code

https://www.gitpp.com/laoxiangjun/project0922-iot-manage-system

Includes user authorization system, location monitoring, distance calculation, and service health monitoring

Detailed Functionality and Implementation Plan of the IoT Management System Based on Gin/Fiber and Vue3

1. Core Functional Architecture

The system adopts a front-end and back-end separation architecture, with the back-end based on the Go language’s Gin/Fiber framework (high-performance web framework), and the front-end built using Vue3 (reactive framework). The database is PostgreSQL (supports complex queries and JSON fields), with Redis as the caching layer. The functional modules include: User Authorization System, Location Monitoring, Distance Calculation, Service Health Monitoring.

2. Detailed Function Implementation

1. User Authorization System

Objective: To achieve fine-grained access control based on the RBAC model, supporting dynamic routing and menu generation.Technical Implementation:

  • Back-end:
    • Use the Casbin library (permission management middleware) to define policy models, supporting flexible binding of roles and permissions.
    • Intercept requests through Gin middleware to verify user permissions (e.g., <span>/system/user/list</span> requires <span>system:user:list</span> permission).
    • Interface example:
      // Role management interface
      func listRole(c *gin.Context) {
          roles, err := roleService.GetRoleList() // Query role list
          if err != nil {
              response.Fail(c, "Query failed")
              return
          }
          response.Success(c, roles)
      }
  • Front-end:
    • Dynamic route generation: Filter unauthorized routes based on the permission information returned from the back-end.
    • Button-level permission control: Hide unauthorized buttons using the <span>v-auth</span> directive (e.g., <span>v-auth="'system:user:add'"</span>).
    • Code example:
      // src/router/index.js
      const routes = [
          {
              path: '/user',
              component: () => import('@/views/user/list.vue'),
              meta: { title: 'User List', auth: ['system:user:list'] } // Route identifier
          }
      ]
2. Location Monitoring

Objective: To track device locations in real-time, supporting historical trajectory playback and geofencing alerts.Technical Implementation:

  • Data Collection:
    • The device reports location data (longitude, latitude, timestamp) to the back-end at regular intervals via the MQTT protocol.
    • The back-end uses WebSocket to push location updates to the front-end, achieving real-time map rendering.
  • Front-end Display:
    • Integrate Leaflet/OpenLayers mapping libraries to mark device locations and draw trajectories.
    • Historical trajectory query: Filter location records in the database by time range to generate dynamic trajectory animations.
  • Database Design:
    CREATE TABLE device_location (
        id SERIAL PRIMARY KEY,
        device_id VARCHAR(50) NOT NULL,
        longitude DECIMAL(10, 6) NOT NULL,
        latitude DECIMAL(10, 6) NOT NULL,
        timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
    
3. Distance Calculation

Objective: To calculate the straight-line distance or path distance between two devices based on their location data.Technical Implementation:

  • Algorithm Selection:
    • Haversine Formula: Calculates the great-circle distance between two points on a sphere (suitable for short distances, error < 0.5%).
    • OSRM/GraphHopper: Calls open-source routing services to calculate actual path distances (requires service deployment or API usage).
  • Back-end Interface:
    // Calculate distance between two devices
    func calculateDistance(c *gin.Context) {
        deviceA, deviceB := c.Param("deviceA"), c.Param("deviceB")
        locA, locB := locationService.GetLatestLocation(deviceA), locationService.GetLatestLocation(deviceB)
        distance := haversine(locA.Longitude, locA.Latitude, locB.Longitude, locB.Latitude)
        response.Success(c, map[string]interface{}{"distance": distance})
    }
4. Service Health Monitoring

Objective: To monitor the status of system services (e.g., database, MQTT broker, microservices) and automatically alert in case of anomalies.Technical Implementation:

  • Monitoring Metric Collection:
    • Use Prometheus to collect service metrics (e.g., HTTP request latency, memory usage).
    • Custom Exporter to monitor business metrics (e.g., number of online devices, message queue backlog).
  • Alert Rules:
    • Configure threshold alerts through Alertmanager (e.g., CPU usage > 90% for 5 minutes).
    • Integrate with WeChat/DingTalk bots to send alert notifications.
  • Front-end Dashboard:
    • Service Status: Green light (healthy) / Red light (anomalous).
    • Response Time: 95th percentile < 500ms.
    • Integrate Grafana to display real-time monitoring data, supporting custom dashboards.
    • Example dashboard:

3. System Advantages and Scalability

  1. High Performance:
  • The Gin/Fiber framework handles high concurrent requests (QPS > 10K), and Redis caches hot data (e.g., device status).
  • Easy to Expand:
    • Modular design supports adding new features (e.g., adding an “energy consumption monitoring” module only requires developing an independent service and connecting to the API).
  • Security and Compliance:
    • Data transmission encryption (HTTPS/WSS), sensitive operations recorded in audit logs.

    4. Application Scenarios

    • Smart Logistics: Real-time tracking of truck locations, calculating transport distances and times.
    • Industrial IoT: Monitoring equipment health status, preventive maintenance to reduce downtime.
    • Smart Cities: Managing the operational status of public facilities (e.g., streetlights, trash bins).

    Open Source IoT Management System! Includes User Authorization System, Location Monitoring, Distance Calculation, and Service Health MonitoringIoT management system based on Gin/Fiber and Vue3Source code

    https://www.gitpp.com/laoxiangjun/project0922-iot-manage-system

    Includes user authorization system, location monitoring, distance calculation, and service health monitoring

    Leave a Comment