Wireless sensor networks (WSNs) play important roles in systems that interact with the real world (e.g., cyber-physical systems and internet of things). To mitigate the complex nature of WSNs, many platforms at different abstraction levels (e.g., abstraction of hardware, communications, and individual nodes) have been proposed in the last decade. WSNs in different environments might employ different platforms to satisfy nonfunctional requirements (NFRs) because the diversity of platforms results in trade-offs of NFRs and the quality of WSN heavily depends on the environment it runs. Although WSN software should be highly portable, existing approaches only support porting between operating systems and not more abstract middleware. Herein we propose a methodology with a framework to capture various platforms in the WSN domain with platform-independent multi-level models. A case study demonstrates that our framework can port WSN software to platforms at different abstraction levels and adapt the software to the new platform to improve performance.