tinyosnesc

How to connect LED's in nesC?


I am trying to understand how nesC's modules, configurations, interfaces, and components work. To do this I have tried to implement a very simple application; when its done booting up, it should turn on its three LED's to show its ID. But I get the error:

/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc: In function `CL.setCoolLed':
/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc:12: Leds.led0On not connected
/home/tinyos/WSN-Project/src/CoolLed/CoolLedM.nc:14: Leds.led0Off not connected

I have used the Blink and BlinkToRadio examples as guides, but have not seen each individual led connected. So what does this error message mean? And how do i fix this problem?


Here is my program with the comment showing in which file it is placed.

// AppC.nc
configuration AppC{}
implementation{
    components AppM;
    components MainC;
    AppM.Boot -> MainC;
    components CoolLedM;
    AppM.CL -> CoolLedM;
}

// AppM.nc
module AppM{
    uses interface Boot;
    uses interface CoolLedI as CL;  
}
implementation{
    event void Boot.booted(){
        call CL.setCoolLed((uint8_t)TOS_NODE_ID);
    }
}

// CoolLedI.nc
interface CoolLedI{
    command void setCoolLed(uint8_t mask);
}

// CoolLedC.nc
configuration CoolLedC{}
implementation
{
    components CoolLedM;
    components LedsC;
    CoolLedM.Leds -> LedsC;
}

// CoolLedM.nc
module CoolLedM{
    provides interface CoolLedI as CL;
    uses interface Leds;
}
implementation{
    command void CL.setCoolLed(uint8_t mask){
        if(mask & 0x01)
            call Leds.led0On();
        else
            call Leds.led0Off();
        ...
    }
}

Solution

  • The error says that CoolLedM uses interface Leds, but the interface isn't connected to any implementation. Let's look at AppC.nc:

    configuration AppC{}
    implementation{
        components AppM;
        components MainC;
        AppM.Boot -> MainC;
        components CoolLedM;
        AppM.CL -> CoolLedM;
    }
    

    Indeed: you use CoolLedM in the application, but nothing defines what implementation of Leds that module uses.

    You also define CoolLedC, which does wire the Leds interface of CoolLedM, but it has two issues:

    To immediately fix, your problem, wire Leds in AppC like you did in CoolLedC (and delete unused CoolLedC):

        components LedsC;
        CoolLedM.Leds -> LedsC;
    

    A better and more common design (see the links below) is to define CoolLedC as a self-contained module that provides the CoolLedI interface. I recommend starting with some tutorial to learn more about nesC and TinyOS: