<p>Disclosed are a method and device for code matching. The method includes the following steps: an Internet of Things gateway entering a code matching state; and the Internet of Things gateway extracting information about a sensor from a received sensor message, and allocating a sensor identification code to the sensor.The present invention realizes effective management of various sensors by an Internet of Things gateway.</p>