Overview

Console application that generates and publishes simulated IoT sensor telemetry to Azure Event Hubs. Demonstrates Event Hub producer pattern for high-throughput data ingestion. Supports both simulated sensors (random data generation) and physical sensors via serial port communication.

Built as companion project to IOT Downloader for end-to-end telemetry pipeline demonstration.

Architecture

Telemetry Generation

  • Random number generator for simulated sensor readings
  • Heart rate: 70-190 BPM (normal to exercise range)
  • Temperature: 20-40°C (room temperature to body temperature)
  • 2-second polling interval mimics real sensor behavior

Message Construction

  • Manual JSON string building using StringBuilder
  • Metadata fields: displayname, location, organization, guid
  • Measurement fields: measurename, unitofmeasure, value
  • ISO 8601 timestamp (UTC) for time-series alignment
  • Typical payload size: 200-300 bytes

Event Hub Publishing

  • EventHubClient maintains persistent AMQP connection
  • SendAsync() for non-blocking message transmission
  • No explicit partition key (round-robin distribution)
  • Fire-and-forget pattern (no acknowledgment handling in demo)

Optional Serial Port Integration

  • SerialPort class for Arduino/hardware sensor integration
  • 9600 baud rate (common for Arduino Uno)
  • DataReceived event handler for asynchronous sensor readings
  • Parsing sensor output format (comma-separated values typical)

Technical Implementation

JSON Serialization: Used manual StringBuilder instead of Json.NET for performance. At 2-second intervals, serialization overhead negligible. Production code would use System.Text.Json or Newtonsoft.Json for maintainability and proper escaping.

EventHubClient Configuration: Connection string contains Event Hub namespace, entity path, and SAS token. Client creates single TCP connection with multiplexed AMQP links. Connection reused across all sends for efficiency.

Throughput Characteristics: 2-second send interval = 0.5 messages/second per device. Event Hubs standard tier supports millions of events/second, so single sender barely registers. Load testing would require 10,000+ parallel senders.

Error Handling: No try/catch in demo code. Production implementation needs retry logic for transient failures (network issues, throttling). Azure SDK provides exponential backoff by default, but application should handle exceptions gracefully.

Technical Challenges

Timestamp Synchronization: IoT devices often lack accurate system clocks. Used DateTime.UtcNow on sender side, which works for simulated data. Real sensors would need NTP synchronization or server-side timestamping for accurate time-series analysis.

Message Ordering: Event Hubs guarantees order within partition, but round-robin distribution means messages from single device can arrive out-of-order across partitions. Implemented partition key (device GUID) to ensure per-device ordering, though not shown in simplified demo code.

Serial Port Reliability: Physical sensors via serial port prone to connection drops, buffer overflows, malformed data. Implemented reconnection logic, data validation, and timeout handling for production deployment.

Backpressure Handling: If Event Hub throttles (throughput limit exceeded), SendAsync() throws ServerBusyException. Demo code doesn’t handle this; production code would implement queue with retry/backoff or circuit breaker pattern.

Results

Successfully generated and transmitted 43,200 messages per device per day (2-second interval). Event Hub ingested data with < 100ms end-to-end latency (send to receive in downloader). Zero message loss with stable network connection.

Used in Azure IoT workshops to demonstrate telemetry ingestion at scale. Students deployed 20-50 uploader instances to simulate IoT device fleet.

Tech Stack

  • Language: C#
  • Framework: .NET Framework 4.5+
  • Azure SDK: WindowsAzure.ServiceBus (Event Hubs v1.x SDK)
  • Azure Services: Event Hubs
  • Hardware Interface: System.IO.Ports.SerialPort (for Arduino integration)
  • Protocol: AMQP 1.0

Source Code

Code will be available on GitHub at: https://github.com/tanchunsiong/iot-uploader

Important: Remove hardcoded connection strings and GUIDs before committing. Use app.config or environment variables.

Project Created: 2015-2016


Connect: