This paper presents EmbJXTAChord, a novel peer-to-peer (P2P) architecture that integrates the good features of different sources, such as JXTA, EXI, CoAP, combining and augmenting them to provide a framework that is specifically devised for developing IoT applications over heterogeneous networks.EmbJXTAChord provides for several interesting properties, such as, distributed and fault-tolerant resource discovery, transparent routing over subnetworks, application protocol independence from the transport protocol in narrowband Wireless Sensor Networks, thus eliminating the need for using dedicated software or configuring custom gateways to achieve these functionalities.Moreover, EmbJXTAChord offers native support not only for TCP/HTTP, but also for Bluetooth RFCOMM and 6LoWPAN, thus opening to a broad range of IoT devices in supernetworks composed of networks using different interconnection technologies, not necessarily IP-based. In addition, EmbJXTAChord offers security over heterogeneous networks providing support for secure peergroups (even nested) and for group encryption, thus allowing for unicast and multicast communication between groups of objects sharing the same resources. The users of the proposed architecture will benefit from an integrated solution and the applications developed on the proposed framework will be able to reconfigure themselves, adapting automatically to the network topology of the execution environment.Finally, EmbJXTAChord provides jxCOAP-E, a new CoAP implementation that leverages on the transport mechanisms for heterogeneous networks offered by EmbJX-TAChord. jxCOAP-E enables to realize a RESTful service architecture for peer-topeer narrowband or broadband networks composed of devices connected via Ethernet, Bluetooth, BLE or IEEE 802.15.4. Differently from CoAP, jxCOAP-E provides a distributed and fault-tolerant service discovery mechanism and support for secure multicast communications. The paper presents EmbJXTAChord, discusses all the relevant design challenges and presents a comparative experimental performance assessment with state-of-the-art solutions on commercial-off-the-shelf devices.Note:This is a preprint version of an Elsevier accepted paper. The formal version of the work is available at https://doi.