cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with actuating a led with stm32WLJC!! in lora_app.c,line 507.

Dprad.1
Associate II

i modified the code for downlink turning on red led 3.

" case LORAWAN_USER_APP_PORT:"

for my case port 99:

to turn on led defined at PB1 which i defined.

as this was the default code for digital output given by cayenne port 99.

when i am gpio writing whenever channel 4 is comming its turning on. but if i read 3 byte its not turning on , i am confused the code is as follow.

 case 99:

            if (appData->BufferSize == 4)

            {

             AppLedStateOn = appData->Buffer[1] & 0x64;

             if (AppLedStateOn == RESET)

             {

              APP_LOG(TS_OFF, VLEVEL_H, "LED OFF\r\n");

              HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); // LED_RED

             // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); // LIGHT OFF

              HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); // LIGHT OFF

             }

             else

             {

              APP_LOG(TS_OFF, VLEVEL_H, "LED ON\r\n");

              HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); // LED_RED

            //  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); // LIGHT ON

              HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET); // LIGHT ON

             }

            }

            break;

from cayenne the downlink communication in port 99 is

for on- 04 00 64 FF

and off -04 00 00 FF

       

1 ACCEPTED SOLUTION

Accepted Solutions
Louis AUDOLY
ST Employee

Hello,

The issue come from the fact you check the wrong byte, 64 is the byte 2 and not the 1 in your payload.

Regards

Louis

View solution in original post

4 REPLIES 4
Louis AUDOLY
ST Employee

Hello and welcome to the community @Dprad.1​ ,

Are you sending your bytes on channel 4 or 99 ?

If you use channel 4, please give the code corresponding to this case. (there is an option to include code in your comment to make it easier to read).

If you send 3 bytes on channel 99, your BufferSize will be equal to 3 so it won't enter in the first if instruction, so nothing will happen.

Regards

Louis

Dprad.1
Associate II

Thank you Louis,

I am new to technical forums so please bear with me.

as for the issue I am facing , I am sending data to Port 99[this is the default port I am getting from mydevices.Cayenne as i was following tutorials for LoRaWAN by stm in youtube and trying to integrate switch , and normal sensors instead of using the sensors boards as in tutorial video provided by stm https://youtu.be/vuc6914B0KM["LoRaWAN with STM32 Getting Started"]

from the default code there was already a code for cayenne in analog output at channel 4 .

I modified the code for toggling led with writing set and rest for custom GPIO port.

but i am only able to use Toggle function by toggling after reading channel 4 from byte 1.

the on frame recieved is 04 00 64 FF

off frame is 04 00 00 FF

when i am modifing the code to read 3rd byte for reading 0x64 and 0x00 its not working.

 case 99:
 
            if (appData->BufferSize == 4)
 
            {
 
             AppLedStateOn = appData->Buffer[1] & 0x64;
 
             if (AppLedStateOn == RESET)
 
             {
 
              APP_LOG(TS_OFF, VLEVEL_H, "LED OFF\r\n");
 
              HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); // LED_RED
 
             // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); // LIGHT OFF
 
              HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); // LIGHT OFF
 
             }
 
             else
 
             {
 
              APP_LOG(TS_OFF, VLEVEL_H, "LED ON\r\n");
 
              HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); // LED_RED
 
            //  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); // LIGHT ON
 
              HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET); // LIGHT ON
 
             }
 
            }
 
            break;

Dprad.1
Associate II

these are the only modification ,different from the video series, yet not working, rest of the code is default code.

the modification is made just next to code for turning led on and off in lora_app.c through downlink communication at port 2 , 01 for led on and 00 for led off.

Louis AUDOLY
ST Employee

Hello,

The issue come from the fact you check the wrong byte, 64 is the byte 2 and not the 1 in your payload.

Regards

Louis