No description
| ai_ref | ||
| docs | ||
| device_simulator.py | ||
| README.md | ||
| requirements.txt | ||
| start.sh | ||
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
Using the Start Script (Recommended)
./start.sh
The start script will:
- Check for Python 3 installation
- Install the required
requestsmodule if needed - 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.shto automatically install dependencies - Or manually install:
pip3 install requests
Python Version
- Requires Python 3.6 or higher
- Use
python3 --versionto check your Python version