Wireless sensor networks (WSN) are being increasingly used for data acquisition and control of remote devices. However, they present some constraints in critical and large-scale scenarios. The main limitations come from the nature of their components, such as lossy links, and devices with power supply limitations, poor processing power and limited memory. The main feature of software-defined networks (SDN) is the separation between the control plane and the data plane, making available a logically unified view of the topology in the controllers. In this way, it is possible to build network applications that take into account this unified view, which makes the SDN an alternative approach to solve the mentioned limitations. This paper presents the SD6WSN (software-defined 6LoWPAN wireless sensor network) architecture, developed to control the behavior of the data traffic in 6LoWPAN according to the SDN approach. It takes into account the specific characteristics of WSN devices, such as low data transfer rate, high latency, packet loss and low processing power, and takes advantage of the flexibility provided by flow-based forwarding, allowing the development of specific networking applications based on a unified view. We provide a detailed description of how we have implemented SD6WSN in the Contiki operating system. The new architecture is assessed in two experiments. The first considers a typical advanced metering infrastructure (AMI) network and measures the overhead of SD6WSN control messages in configurations involving different path lengths. The results indicate that the overhead introduced is not excessive, given the advantages that the SDN approach can bring. The second considers a grid-topology to evaluate the average latency of the peer-to-peer communication. It was observed that the average latency in the SD6WSN is considerably lower than that obtained with standard 6LoWPAN, showing the potential of the proposed approach.