(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, the method of tcl script writing, and the analysis process of simulation results are explained in detail.)