The Internet of things (IoT) has emerged in numerous domains for collecting and exchanging large datasets in order to ensure a continuous monitoring and realtime decision-making. IoT incorporates sensors for carrying out raw data acquisition, while data processing and analysis tasks are addressed by high performance computational facilities, such as cloud-based infrastructures (remote processing approach). However, in several scenarios, the data export incurred by a remote processing approach is not desired, due to privacy issues, bandwidth limitations, or the lack of a reliable communication channel, among others. This paper presents MODALITi, a framework we develop for facing these recurring technical and social issues. In this framework, sensors collaboratively carry out a prediction algorithm by processing locally collected data. Their resources limitations are taken into account by relying on a context- aware adaptation of their behavior, as well as an optimised data exchange and processing.