In oreder to prolonge the lifetime and reduce the energy consumption of the wireless sensor networks,a energy efficient task allocation method oriented to layer structure and multi hop sensor network was proposed based on the task allocation in the wireless sensor networks. This method described a cost function based on entropy theory according to energy consumption, residual energy, and the states of each individual node. Particle swarm optimization algorithm was used to optimize dynamic task allocation.Meanwhile, the tasks can be dynamic adjusted due to sensor network changing.The simulation results showed that the execution time and energy consumption can be decreased, the lifetime of wireless sensor network is prolonged with the proposed method.