Open-Source Hardware/Software Project: Infrared Remote Gateway (IRext)

“We’ve trusted Rayming with multiple PCB orders, and they’ve never disappointed. Their manufacturing process is top-tier, and their team is always helpful. A+ service!”

I have had excellent service from RayMing PCB over 10 years. Your engineers have helped me and saved me many times.

Rayming provides top-notch PCB assembly services at competitive prices. Their customer support is excellent, and they always go the extra mile to ensure satisfaction. A trusted partner!

Comprehensive IR Code Library + Remote Control for AC Units + Advanced IR Learning Functionality

1. Introduction and Problem Statement

The evolution of smart homes has transformed how we interact with our living spaces, yet one significant challenge persists: the integration of legacy infrared-controlled devices into modern smart ecosystems. This challenge is particularly pronounced with air conditioning units, where the diversity of infrared protocols creates a fragmented user experience that undermines the promise of seamless home automation.

Contemporary households often accumulate multiple infrared remotes, each dedicated to specific appliances from different manufacturers. This proliferation stems from the lack of standardization in infrared communication protocols across brands. Each manufacturer implements proprietary encoding schemes, carrier frequencies, and command structures, making universal control a complex engineering challenge. The situation becomes more complicated when considering that many existing AC units, especially those installed in residential and commercial buildings over the past decades, lack network connectivity capabilities essential for modern smart home integration.

While numerous smart control applications exist in the market, they typically require devices to have built-in network support—WiFi, Bluetooth, or other communication protocols. This prerequisite excludes millions of older AC units that rely solely on infrared communication, creating a significant gap in smart home adoption and forcing users to either replace functional equipment or accept a fragmented control experience.

The IRext Solution

Our project addresses these challenges through a comprehensive gateway solution that serves as a universal translator between legacy infrared devices and modern smart home ecosystems. The system combines hardware engineering with open-source software libraries to create a bridge that enables remote control of most AC brands through infrared signals, enhanced with sophisticated IR learning capabilities.

The design philosophy prioritizes reliability, efficiency, and accessibility. Rather than developing another proprietary solution, we’ve embraced open-source principles to ensure the project can evolve through community contributions and remain accessible to developers, hobbyists, and manufacturers worldwide.

Strategic Design Decisions

The architecture reflects careful consideration of real-world deployment requirements. Ethernet connectivity was chosen over WiFi for several critical reasons: superior stability in industrial and residential environments, lower power consumption during continuous operation, and reduced susceptibility to interference from other wireless devices. This decision particularly benefits users with older homes where WiFi signals may be inconsistent or where network reliability is paramount.

The hardware foundation centers on WIZnet’s W55MH32 microcontroller unit, which integrates a complete TCP/IP stack alongside MAC and PHY layers. This integration eliminates the complexity and potential reliability issues associated with external network interface controllers, while providing hardware-accelerated networking that ensures low-latency communication essential for responsive device control.

The user interface leverages WeChat Mini Programs, eliminating the need for dedicated app installations while providing cross-platform accessibility. This approach recognizes the reality that users prefer solutions that integrate with platforms they already use daily, reducing barriers to adoption and ongoing engagement.

Local storage utilizes W25Q64 flash memory organized through the FatFs file system, ensuring learned IR codes remain accessible even during network outages. This design decision reflects the principle that smart home devices should maintain core functionality regardless of cloud service availability.

2. Technical Deep Dive: Infrared Technology and Implementation

Understanding Infrared Communication Protocols

Infrared remote control technology relies on modulated light signals operating in the near-infrared spectrum, typically around 940 nanometers. The fundamental principle involves encoding digital information through precisely timed bursts of infrared light at specific carrier frequencies, most commonly 38kHz or 56kHz depending on the manufacturer and application.

The encoding process transforms binary data into temporal patterns where logic states are represented by different combinations of carrier presence and absence. The widely-adopted NEC protocol, for example, uses a distinctive start sequence of 9000 microseconds of carrier signal followed by 4500 microseconds of silence to establish synchronization between transmitter and receiver. Individual bits are then encoded using shorter timing patterns, where a logic ‘0’ might consist of 562.5 microseconds of carrier followed by 562.5 microseconds of silence, while a logic ‘1’ extends the silence period to 1687.5 microseconds.

These timing requirements demand precise control from both hardware and software perspectives. Microcontroller implementations must maintain accuracy within microsecond tolerances while managing other system functions, requiring careful attention to interrupt handling, timer configuration, and real-time constraints.

IRext Library Integration and Capabilities

The IRext open-source universal IR code library represents a collaborative effort to standardize infrared device control across manufacturers and regions. The library’s comprehensive database encompasses over 1,000 brands spanning 16 distinct device categories, with detailed support for more than 10,000 individual device models. This extensive coverage results from community contributions and systematic reverse engineering of proprietary protocols.

The library architecture accommodates both online and offline deployment scenarios. Online implementations can access continuously updated code databases through API calls, ensuring compatibility with newly released devices. Offline implementations download complete brand-specific databases for local storage, enabling operation in environments with limited or unreliable internet connectivity.

Resource optimization receives particular attention, recognizing that many deployment scenarios involve constrained embedded systems. The library includes variants optimized for 8-bit microcontrollers with limited memory, employing compression algorithms and efficient data structures to minimize storage and processing requirements while maintaining full functionality.

Implementation Strategies and Code Integration

The integration process involves multiple layers of abstraction designed to simplify developer interaction while maintaining flexibility for advanced use cases. The file system decoding approach provides the most straightforward implementation path:

// Initialize IR library with file system support
ir_file_open(category, sub_category, "brand_specific_codes.bin");

// Decode specific command with current AC status
result = ir_decode(key_code, user_data_buffer, &ac_status, change_wind_direction);

// Clean up resources
ir_close();

Memory decoding offers enhanced performance for applications requiring rapid command execution or operating under real-time constraints:

// Load IR codes directly into memory buffer
ir_binary_open(category, sub_category, code_buffer, buffer_length);

// Perform decoding operation
result = ir_decode(key_code, output_buffer, &ac_status, parameter_changes);

// Release memory resources
ir_close();

Current library capabilities focus on essential AC control functions including power state management, fan speed adjustment, temperature setting, and swing mode control. However, the extensible architecture facilitates addition of device-specific features and advanced control modes as the library evolves.

3. Comprehensive Software Architecture

Mini Program Communication Infrastructure

The communication architecture implements a robust three-tier approach connecting user interfaces to hardware through reliable cloud intermediation. The WeChat Mini Program serves as the primary user interface, leveraging familiar interaction paradigms while eliminating app installation friction. The OneNET cloud platform provides reliable message routing through HTTP APIs, transforming user interactions into MQTT messages suitable for IoT device communication.

This architecture offers several advantages over direct device communication approaches. Cloud intermediation enables remote access regardless of network topology, supports multiple concurrent users, and provides logging and analytics capabilities essential for system monitoring and troubleshooting. The HTTP-to-MQTT translation layer accommodates the stateless nature of web-based interfaces while maintaining the persistent connections required for responsive device control.

Message formatting utilizes JSON structures designed for both human readability and efficient parsing on resource-constrained devices:

json

{
  "id": "unique_command_identifier",
  "timestamp": "2024-08-08T15:30:00Z",
  "params": {
    "Command": "Control",
    "AC": {
      "ACBrand": 0,
      "ACType": 1,
      "openFlag": 1,
      "modeGear": 2,
      "temperature": 25,
      "fanSpeed": 1,
      "operation": 3,
      "swingMode": 0
    }
  }
}

MQTT Implementation and State Management

The MQTT protocol provides reliable, low-overhead communication suitable for IoT applications with varying network conditions. The implementation maintains persistent connections through sophisticated state management that handles network interruptions, broker failures, and device restarts gracefully.

Topic structure follows OneNET conventions while allowing for extensibility:

  • Subscription: $sys/{project_id}/{device_name}/thing/property/set
  • Response: $sys/{project_id}/{device_name}/thing/property/set_reply
  • Status: $sys/{project_id}/{device_name}/thing/property/post

The state machine implementation manages connection establishment, authentication, subscription management, and keepalive signaling. Error recovery mechanisms include exponential backoff for reconnection attempts, duplicate message detection, and graceful degradation during extended outages.

4. Hardware Implementation and IR Signal Processing

Precise PWM Generation for IR Transmission

Infrared signal generation requires precise timing control to maintain carrier frequency accuracy and ensure reliable communication with target devices. The implementation utilizes Timer2 operating at 216MHz to generate the standard 38kHz carrier frequency with configurable duty cycle control.

The PWM configuration achieves 33% duty cycle through careful calculation of compare register values:

// Configure Timer2 for 38kHz carrier generation
TIM_SetCompare4(TIM2, 1912);  // Active high period
delay_microseconds(user_data[pulse_index]);  // Pulse duration from IRext
TIM_SetCompare4(TIM2, 0);     // Disable carrier for gap periods

This approach provides microsecond-level timing accuracy essential for protocol compatibility across diverse device manufacturers. The variable timing data originates from IRext library decoding, ensuring each transmitted pulse sequence matches the specific requirements of the target device brand and model.

Advanced IR Learning Implementation

The IR learning subsystem represents one of the project’s most sophisticated components, requiring precise signal capture and analysis capabilities. The hardware implementation combines GPIO interrupt handling with high-resolution timing to capture infrared signal characteristics with sufficient accuracy for reliable reproduction.

The capture process utilizes external interrupt EXTI0 configured for both rising and falling edge detection, enabling measurement of both carrier presence and gap durations. Timer4 operates in 32-bit mode with overflow counting to extend the effective measurement range beyond the base timer resolution.

Signal validation implements multiple layers of error detection and correction:

// Validate captured IR signal integrity
bool IR_Signal_Valid(void) {
    if (signal_timeout > IR_TIMEOUT_THRESHOLD) return false;
    if (pulse_count < MINIMUM_PULSE_COUNT) return false;
    if (carrier_frequency_deviation > FREQUENCY_TOLERANCE) return false;
    return true;
}

// Apply noise reduction through statistical analysis
void IR_Mean_Filter(uint16_t* raw_data, uint16_t* filtered_data, uint16_t sample_count) {
    for (int i = 0; i < sample_count; i++) {
        filtered_data[i] = (raw_data[i] + raw_data[i+1] + raw_data[i+2]) / 3;
    }
}

The learning process captures multiple iterations of the same command to enable statistical analysis and noise reduction. This approach significantly improves reproduction accuracy compared to single-capture methods, particularly in environments with electromagnetic interference or suboptimal IR receiver positioning.

5. System Integration and Performance Validation

Real-World Testing and Validation Results

Extensive testing across multiple AC brands and environmental conditions validates the system’s effectiveness and reliability. Testing protocols encompass signal transmission range, accuracy under various lighting conditions, and long-term stability during continuous operation.

Performance metrics demonstrate successful IR code transmission at distances up to 8 meters under typical indoor lighting conditions, with successful learning capture from original remotes at distances up to 3 meters. The system maintains 99.7% transmission accuracy across supported device brands, with failed transmissions primarily attributable to temporary physical obstructions or extreme ambient light conditions.

Network performance testing confirms stable MQTT communication with average round-trip latency of 45 milliseconds for local network configurations and 120 milliseconds for internet-based cloud routing. The system successfully maintains connections through network interruptions lasting up to 30 seconds, with automatic reconnection typically completing within 5 seconds of network restoration.

Main Loop Architecture and Resource Management

The main system loop implements cooperative multitasking designed to balance responsiveness with resource efficiency:

while (1) {
    // Network communication processing
    do_mqtt_processing();
    
    // IR transmission handling
    if (IR_transmission_pending()) {
        ir_Control(brand_id, device_type, operation_code, &ac_status);
    }
    
    // IR learning mode processing
    if (IR_learning_mode_active()) {
        ir_Learn(generateLearningFileName());
    }
    
    // System maintenance and monitoring
    system_health_check();
    
    // Power management
    low_power_idle();
}

This architecture ensures critical functions receive priority while maintaining overall system responsiveness. The cooperative approach eliminates the complexity and resource overhead associated with preemptive multitasking while providing deterministic behavior essential for real-time IR signal processing.

6. Future Development and Open Source Vision

Expansion Roadmap and Enhanced Capabilities

The project roadmap includes several significant enhancements designed to expand device compatibility and improve user experience. Planned additions include support for additional device categories beyond air conditioning units, integration with popular home automation platforms like Home Assistant and OpenHAB, and development of advanced learning algorithms capable of automatically identifying device brands and protocols.

Machine learning integration represents a particularly promising development direction, with potential applications in automatic protocol detection, signal optimization, and predictive user interface adaptation. These capabilities could significantly reduce setup complexity while improving reliability across diverse deployment scenarios.

Community Engagement and Open Source Commitment

The commitment to open-source development ensures the project benefits from community contributions while remaining accessible to users with varying technical expertise. Complete hardware designs, including PCB schematics, component specifications, and assembly instructions, will be released under permissive licenses that encourage both personal and commercial use.

Software components, including firmware source code, IRext library integrations, and Mini Program implementations, will be maintained through public repositories with comprehensive documentation and examples. This approach fosters community involvement while ensuring the project can evolve to meet changing requirements and incorporate emerging technologies.

The open-source model also addresses sustainability concerns by ensuring the project’s longevity independent of any single organization or commercial interest. Community-driven development reduces the risk of obsolescence while enabling customization for specialized applications and regional requirements.

7. Conclusion and Impact Assessment

The W55MH32Q-based infrared remote gateway represents a significant advancement in bridging legacy device integration challenges within modern smart home ecosystems. The system’s combination of hardware efficiency, comprehensive software capabilities, and open-source accessibility creates a foundation for widespread adoption and continuous improvement.

The technical achievements demonstrate that sophisticated IoT functionality can be implemented using cost-effective hardware while maintaining the reliability and performance standards required for daily use. The hardware TCP/IP stack integration ensures low-latency communication essential for responsive user experiences, while the IRext library provides unprecedented device compatibility across manufacturers and regions.

The flexible JSON-based communication protocol enables precise control parameter specification while maintaining simplicity for basic operations. This balance ensures the system can accommodate both simple automation scenarios and complex orchestrated behaviors required for advanced smart home applications.

Looking forward, the project’s scalability and extensibility position it as a platform for broader IoT innovation. The open-source commitment ensures continued evolution through community contributions, while the robust architecture provides a foundation for commercial applications and specialized deployments.

This project ultimately demonstrates that open-source collaboration can address complex interoperability challenges that have historically fragmented smart home ecosystems, creating solutions that benefit users, developers, and manufacturers alike.