(This article introduces the realization of wireless sensor network simulation based on IEEE802.15.4 protocol by example. And combined with this example, the generation of random scenes in NS2 and the method of tcl script writing are explained in detail, as well as the analysis process of the simulation effect.)