No description
Find a file
Zalán Tóth 363a26f9e1 Reference
2026-03-06 07:37:47 +00:00
ai_ref Reference 2026-03-06 07:37:47 +00:00
docs Added sample code /AI/ 2026-03-06 07:37:18 +00:00
device_simulator.py Added sample code /AI/ 2026-03-06 07:37:18 +00:00
README.md Added sample code /AI/ 2026-03-06 07:37:18 +00:00
requirements.txt Added sample code /AI/ 2026-03-06 07:37:18 +00:00
start.sh Added sample code /AI/ 2026-03-06 07:37:18 +00:00

Sample Device Simulator

A simple device simulator that sends realistic temperature monitoring data to the Távlink ingestion endpoint.

Device Configuration

  • Device ID: dev_70f0669585711a85
  • Organization ID: 699e52b18a53ff450ef301d2
  • Ingestion Endpoint: http://0.0.0.0:8268/api/v0/ingestion/ingest
  • Metric: Temperature (°C)
  • Data Range: 10-30°C with realistic movements
  • Interval: Every 5 seconds

Features

  • Realistic Temperature Simulation: Uses sine wave patterns with small random variations to simulate natural temperature fluctuations
  • Continuous Operation: Runs indefinitely until stopped with Ctrl+C
  • Error Handling: Robust error handling with connection timeouts and retry logic
  • Real-time Feedback: Shows successful transmissions and any errors in the console

Quick Start

./start.sh

The start script will:

  1. Check for Python 3 installation
  2. Install the required requests module if needed
  3. Start the device simulator

Manual Start

# Install dependencies
pip3 install -r requirements.txt

# Run the simulator
python3 device_simulator.py

Output Example

Starting device simulator...
Device ID: dev_70f0669585711a85
Organization ID: 699e52b18a53ff450ef301d2
Ingestion URL: http://0.0.0.0:8268/api/v0/ingestion/ingest
Metric: temperature
Interval: 5000ms
Temperature range: 10-30°C
------------------------------------------------------------
Press Ctrl+C to stop the simulator

[14:30:15] ✓ Sent: 22.35°C | Accepted: 1, Rejected: 0
[14:30:20] ✓ Sent: 22.41°C | Accepted: 1, Rejected: 0
[14:30:25] ✓ Sent: 22.48°C | Accepted: 1, Rejected: 0

Temperature Simulation

The simulator generates realistic temperature data using:

  • Base Temperature: 20°C
  • Smooth Drift: Sine wave patterns for natural temperature changes
  • Small Variations: Random noise (±0.2°C) for realism
  • Range Constraints: Temperature stays within 10-30°C range

Data Format

Each data point sent to the ingestion endpoint follows this format:

{
  "datapoints": [
    {
      "metric_slug": "temperature",
      "value": 22.35,
      "ts": "2024-01-15T14:30:15Z",
      "quality": "ok"
    }
  ],
  "device_ts": "2024-01-15T14:30:15Z",
  "batch_id": "batch_1705315815"
}

Authentication

The simulator uses Bearer token authentication in the format:

Authorization: Bearer dev_70f0669585711a85:699e52b18a53ff450ef301d2

Stopping the Simulator

Press Ctrl+C to stop the simulator at any time.

Troubleshooting

Connection Issues

  • Ensure the ingestion server is running at 0.0.0.0:8268
  • Check network connectivity to the server
  • Verify the server URL is correct

Missing Dependencies

  • Run ./start.sh to automatically install dependencies
  • Or manually install: pip3 install requests

Python Version

  • Requires Python 3.6 or higher
  • Use python3 --version to check your Python version