LoRa SDK improvements - code of conduct for SDK

There is page how to contribute to documentation. Is there something similar for code contribution?

E.g. should I discuss feature request here on forum, create issue or just make pull request directly? :slight_smile:

We will be happy for pull request,
But creating an issue is also good for improving the documentation.

Pull request with forum thread or github issue to discuss would be fine.
What is your suggested area of code/sdk improvement?

Few missing features of SDK for LoRa module (bc_cmwx1zzabz). I already wrote some:

Perfect, thanks for your tips.
We will improve LoRa SDK based on customers needs. There’s lot of parameters to configure and it’s good to have someone with practical skills who knows what is important.

I can add all three functionality soon in a few days. Is it ok for you?

Glad to help.

No need to rush. I’m working on simple LoRaWAN thermometer example application with more professional like LoRa communication - my current design. But it is hobby/evening type of project.

Hello Adam,

please check this pull request that should add API to all your requested parameters. Let me know if there’s something missing or if you would suggest to change calling/parameters of SDK functions.

I’m appending my dirty test code which could show you how use the new SDK functions.
Please take a look at

  • bc_cmwx1zzabz_set_rx2 / bc_cmwx1zzabz_get_rx2
  • bc_cmwx1zzabz_set_port()
  • bc_cmwx1zzabz_send_message_confirmed() and respective events BC_CMWX1ZZABZ_EVENT_MESSAGE_CONFIRMED, BC_CMWX1ZZABZ_EVENT_MESSAGE_RETRANSMISSION, BC_CMWX1ZZABZ_EVENT_MESSAGE_NOT_CONFIRMED

Martin

#include <application.h>

// LED instance
bc_led_t led;

bc_button_t button;

// LoRa instance
bc_cmwx1zzabz_t lora;

char deveui[20] = "...";
char devaddr[20] = "...";

uint8_t port = 5;

void lcd_redraw(char *state)
{
    bc_module_lcd_clear();

    bc_module_lcd_set_font(&bc_font_ubuntu_15);
    bc_module_lcd_draw_string(10, 5, "LoRaWAN Tester", true);
    bc_module_lcd_draw_line(5, 20, 115, 20, true);

    bc_module_lcd_draw_string(1, 24, deveui, true);
    bc_module_lcd_draw_string(5, 36, devaddr, true);

    bc_module_lcd_draw_string(5, 50, state, true);

    bc_module_lcd_update();
}

void lora_callback(bc_cmwx1zzabz_t *self, bc_cmwx1zzabz_event_t event, void *event_param)
{
    if (event == BC_CMWX1ZZABZ_EVENT_READY)
    {

        bc_cmwx1zzabz_get_deveui(&lora, (char*)deveui);
        bc_cmwx1zzabz_get_devaddr(&lora, (char*)devaddr);

        bc_log_debug("deveui: %s", deveui);
        bc_log_debug("devaddr: %s", devaddr);

        uint32_t rx2_frequency;
        uint8_t rx2_datarate;
        bc_cmwx1zzabz_get_rx2(&lora, &rx2_frequency, &rx2_datarate);
        bc_log_debug("RX2 freq: %d, dr: %d", rx2_frequency, rx2_datarate);

        bc_led_pulse(&led, 50);
    }

    if (event == BC_CMWX1ZZABZ_EVENT_ERROR)
    {
        bc_led_set_mode(&led, BC_LED_MODE_BLINK_FAST);
        bc_log_debug("Modem ERROR");
        lcd_redraw("Modem ERROR");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_JOIN_ERROR)
    {
        bc_log_debug("Join ERROR");
        lcd_redraw("Join ERR");
        bc_led_set_mode(&led, BC_LED_MODE_BLINK_FAST);
    }

    if (event == BC_CMWX1ZZABZ_EVENT_JOIN_SUCCESS)
    {
        bc_log_debug("Join OK");
        lcd_redraw("Join OK");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_SEND_MESSAGE_START)
    {
        bc_led_set_mode(&led, BC_LED_MODE_ON);
        bc_log_debug("Sending start");
        lcd_redraw("Sending start");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_SEND_MESSAGE_DONE)
    {
        bc_led_set_mode(&led, BC_LED_MODE_OFF);
        bc_log_debug("Sending done");
        lcd_redraw("Sending done");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_MESSAGE_RECEIVED)
    {
        volatile uint8_t port = bc_cmwx1zzabz_get_received_message_port(self);
        volatile uint32_t length = bc_cmwx1zzabz_get_received_message_length(self);

        uint8_t msg_buffer[51];
        volatile uint32_t len = bc_cmwx1zzabz_get_received_message_data(self, msg_buffer, sizeof(msg_buffer));

        bc_led_pulse(&led, 800);

        bc_log_debug("Message received");
        lcd_redraw("Message received");

        (void) len;
        (void) length;
        (void) port;
    }

    if (event == BC_CMWX1ZZABZ_EVENT_MESSAGE_CONFIRMED)
    {
        bc_log_debug("Message confirmed");
        lcd_redraw("Message confirmed");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_MESSAGE_NOT_CONFIRMED)
    {
        bc_log_debug("Message not confirmed");
        lcd_redraw("Message not confirmed");
    }

    if (event == BC_CMWX1ZZABZ_EVENT_MESSAGE_RETRANSMISSION)
    {
        bc_log_debug("Message rexmit");
        lcd_redraw("Message rexmit");
    }

}

void button_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param)
{
    (void) self;
    (void) event_param;

    if (event == BC_BUTTON_EVENT_PRESS)
    {
        bc_led_pulse(&led, 100);

        bc_cmwx1zzabz_set_port(&lora, port++);

        uint8_t buffer[] = {'A', 'B', 'C'};
        bc_cmwx1zzabz_send_message_confirmed(&lora, buffer, sizeof(buffer) );

    } else if (event == BC_BUTTON_EVENT_HOLD ) {
        bc_cmwx1zzabz_join(&lora);
    }
}

void application_init(void)
{
    // Initialize LED
    bc_led_init(&led, BC_GPIO_LED, false, false);
    bc_led_pulse(&led, 100);

    bc_button_init(&button, BC_GPIO_BUTTON,  BC_GPIO_PULL_DOWN, 0);
    bc_button_set_event_handler(&button, button_event_handler, NULL);

    bc_cmwx1zzabz_init(&lora, BC_UART_UART1);
    bc_cmwx1zzabz_set_event_handler(&lora, lora_callback, NULL);

    // nastevené
    // 3738363750378B04
    bc_cmwx1zzabz_set_devaddr(&lora, "26012621");

    bc_cmwx1zzabz_set_appeui(&lora, "70B3D57ED001013D");
    bc_cmwx1zzabz_set_appkey(&lora, "E6AEF60D900574A3DC55D5585E6992FF");

    //bc_cmwx1zzabz_set_appskey(&lora, "4357FAD1D73C3B7D4C2EDBAE6EBDA740");
    //bc_cmwx1zzabz_set_nwkskey(&lora, "4457FAD1D73C3B7D4C2EDBAE6EBDA740");

    bc_cmwx1zzabz_set_band(&lora, BC_CMWX1ZZABZ_CONFIG_BAND_EU868);
    bc_cmwx1zzabz_set_mode(&lora, BC_CMWX1ZZABZ_CONFIG_MODE_OTAA);
    bc_cmwx1zzabz_set_class(&lora, BC_CMWX1ZZABZ_CONFIG_CLASS_A);

    //bc_cmwx1zzabz_set_rx2(&lora, 869525000, 0);

    bc_log_init(BC_LOG_LEVEL_DEBUG, BC_LOG_TIMESTAMP_REL);

    bc_cmwx1zzabz_join(&lora);

    bc_module_lcd_init();
    lcd_redraw("JOIN request...");
}

It was already pushed to the main branch. Just do make update in your project directory and you can use this new functions.

Thanks for implementation :+1:
I will definitely test it on weekend.