The article presents the development of an architectural software solution for Internet of Things (IoT) devices that implements the functionality of an automatic medical drug dispenser, based on the ESP32 hardware platform and utilizing the capabilities of the existing real-time operating systems (RTOS). The software architecture for IoT devices was designed with scalability and fault tolerance in mind. All components of the system interact with each other through asynchronous callback functions, which provides flexibility and extensibility to the architecture. Testing for system fault tolerance was conducted. The architecture can be implemented and used as the basis for any IoT device, allowing for support of modern security and functionality stacks, by implementing this functionality once in any of the devices. The process of designing the software architecture is presented, including the selection of suitable technologies and libraries. Particular attention was paid to ensuring the safety and reliability of the device, including protection against an unauthorized access and errors in operation. The experimental results show high efficiency and accuracy of the automatic medical drug dispenser based on the developed software. The practical part provides examples of implementing the proposed architecture in the C and C++ languages, with examples and basic interaction diagrams between the components. The rxcpp library was also used in writing the C++ implementation, which made it easier to write the code base for interacting with the operating system resources and reusing the multithreaded interaction with the system.