The development of sophisticated energy-efficient protocols and the increasing complexity of applications in wireless sensor networks (WSNs) imposes the use of open and flexible programming architectures that enable access to the communication stack in a simple way. Nowadays, researchers in WSNs focus on not only the development of efficient mechanisms in the application level but also the interaction with the communication stack, in order to improve the performance. Because radio communication is the most energy-consuming component of a sensor node, the main challenge in WSNs is to reduce the communication cost by means of efficient in-network distributed processing. In this work, a probabilistic query routing mechanism is designed and implemented in a WSN, and a study of different operating systems (OS) and communication stacks available for WSNs is analyzed. This implementation enables flexible prototyping of novel mechanisms by using light communication protocols over a versatile operating system.