mxchip press button send signal to Azure IoT

Viewed 23

Can someone share an example or provide some guidance how I can add that when a button in the mxchip IoT device is pressed the signal is sent to Azure IoT? I am using Azure's example code

I see the function in board_init.c that lights up the light:

weak void button_a_callback()
{

WIFI_LED_ON();
AZURE_LED_ON();
USER_LED_ON();
if (BUTTON_A_IS_PRESSED)
{
    val += 32;
    if (val > 2047)
        val = 2047;
    RGB_LED_SET_R(val);
    RGB_LED_SET_G(val);
    RGB_LED_SET_B(val);
}
//set_led_state(true); I'd like to add something like this

}

and in nx_client.c to set the led state (true or false) when the command is received from Azure IoT:

static void set_led_state(bool level)
{
if (level)
{
    printf("\tLED is turned ON\r\n");
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
}
else
{
    printf("\tLED is turned OFF\r\n");
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
}
}

How can I link these two functions, meaning from button_a_callback to call nx_client.c set_led_state function?

Thanks!

0 Answers
Related