Hi Johan,
The ledPins structure is a method to define a list of LEDs for the demo purpose. These are initialized using the function LED_Init() and controlled at the application level by using function Led_SetState(). Basically for each state of the device, you have a specific LED configuration.
For example, when the device is not joined the network, the LED configuration is (see file app_led.c):
- const appLedsConfig_t gLedCfgFactoryDefault = {LedCfg_BlueFlashing(LED_RGB, gLedSetup_Rgb_c, LED_MAX_RGB_VALUE_c), LedCfg_Flashing(LED1)};
where LED1 represent the first entry in ledPins structure, and as you noticed, modifying the LedPins stucture, your PTB2 will be associated to LED1 => it will flash when the device is not in the network.
To not be influenced by the default demo scenario you can do the following:
- on low power end device project:
1. define PTB2 as output:
gpioOutputPinConfig_t appExternalLed = {
.gpioPort = gpioPort_B_c,
.gpioPin = 2,
.outputLogic = 1,
.slewRate = pinSlewRate_Slow_c,
.driveStrength = pinDriveStrength_Low_c
}
2. Initialize the pin as output using :
void APP_InitExternalLed(void)
{
GpioOutputPinInit(&appExternalLed , 1);
}
4. Control the Led by using the following defines (I assumed that the LED is pull down to Ground):
#define APP_EXTERNAL_LED_ON() GpioSetPinOutput(&appExternalLed )
#define APP_EXTERNAL_LED_OFF() GpioClearPinOutput(&appExternalLed )
5. Test locally the LED configuration:
- in function APP_ConfigModeHandleKeyboard () -> add an operation when you press SW1:
switch(keyEvent){
case gKBD_EventPB1_c:{
/* locally toggle LED */
static bool_t isLedOn = FALSE;
if(isLedOn ){
APP_EXTERNAL_LED_OFF();
isLedOn= FALSE;
}else{
APP_EXTERNAL_LED_ON();
isLedOn= TRUE;
}
...
}
6. To remotely control this LED from the router_eligible_device, the easiest way is to update the function APP_ProcessLedCmd as below:
change the :
if (FLib_MemCmp(pCommand, "on",2))
App_UpdateStateLeds(gDeviceState_AppLedOn_c);
with:
if (FLib_MemCmp(pCommand, "on",2))
APP_EXTERNAL_LED_ON() ;
do the same for "off" event.
- on router eligible device project:
1. Update APP_AppModeHandleKeyboard function to send a LED ON or LED Off command when the sw is pressed:
switch(keyEvent){
case gKBD_EventPB1_c:{
/* remote led - on */
(void)NWKU_SendMsg(APP_SendLedRgbOn, NULL, mpAppThreadMsgQueue);
}
case gKBD_EventPB2_c:{
/* remote led rgb - on */
(void)NWKU_SendMsg(APP_SendLedRgbOn, NULL, mpAppThreadMsgQueue);
.........
}
2. Add the following functions to turn On/Off:
static void APP_SendLedOn(void *pParam)
{
uint8_t aCommand[] = {"on"};
APP_SendLedCommand(aCommand, sizeof(aCommand));
}
static void APP_SendLedOff(void *pParam)
{
uint8_t aCommand[] = {"off"};
APP_SendLedCommand(aCommand, sizeof(aCommand));
}
Test steps:
- create a network using router_eligible device (you can use shell command ; thr create, or double press on SWs -- please check the switchPins stucture to see the Sw configuration);
- join the low power end device - (you can use shell comand: thr join , if the serial is enabled, or Press Sw2, if you added the item 5, otherwise you can use any SW to join the network)
- control the remote LED by pressing : SW1 or Sw2...or you can use shell commands (consider chapter 10.7 Sending application data CoAP messages using the shell from Kinetis Thread Stack Demo Application User Guide document):
"coap CON POST RemoteNodeAddress /led on"
"coap CON POST RemoteNodeAddress /led off"
Regards,
Ovidiu