Minimal MQTT demo


#1

Hi,
I am trying to write my first firmware with MQTT interface, but I have probably some issue in my code or workflow.

My setup is: Core module + CO2 module + Humidity/Pressure tags connected to RPi USB port. RPi is running your distribution.

I would like ask you:

  1. Is my code below OK?
  2. Is it OK when dfu-util print Invalid DFU suffix signature message prior to FW download? (process ends with File downloaded succesfully)
  3. How I could communicate with Core modul from RPi? I am using commands like mosquitto_pub -t 'muj01/led/-/state/set' -m '{"state": false}' (or true) for changing LED state, and mosquitto_pub -t 'muj01/led/-/state/get' -m "" for reading; but I don’t see any response from module. I also try to run mosquitto_sub -v -t '#' on second terminal – I see my payloads sent from RPi, but no response from Core module

My code is based on bc-core-module project. I just replace app/application.c source code and copy into app/usb_talk.* files.

Content of app/application.c:

#include <application.h>
#include <usb_talk.h>

#define PREFIX_TALK "muj01"

static bc_led_t led;
static bool led_state = false;

static void led_state_set(usb_talk_payload_t *payload);
static void led_state_get(usb_talk_payload_t *payload);

void application_init(void)
{
    bc_led_init(&led, BC_GPIO_LED, false, false);
    bc_led_set_mode(&led, BC_LED_MODE_ON);

    usb_talk_init();

    usb_talk_sub(PREFIX_TALK "/led/-/state/set", led_state_set);
    usb_talk_sub(PREFIX_TALK "/led/-/state/get", led_state_get);
}

static void led_state_set(usb_talk_payload_t *payload)
{
    if (!usb_talk_payload_get_bool(payload, &led_state))
    {
        return;
    }

    bc_led_set_mode(&led, led_state ? BC_LED_MODE_ON : BC_LED_MODE_OFF);

    usb_talk_publish_led(PREFIX_TALK, &led_state);
}

static void led_state_get(usb_talk_payload_t *payload)
{
    (void) payload;

    usb_talk_publish_led(PREFIX_TALK, &led_state);
}


#2

Hi,

  1. problem is old gateway “bc-workroom-gateway” subscribe “nodes/base/#”, you must use new gateway repository is here https://github.com/bigclownlabs/bch-gateway, I created package called bc-gateway, but is labeled as beta.

On your rpi use this commands
sudo apt remove bc-workroom-gateway
sudo apt update
sudo apt install bc-gateway

  1. we change talk, new command can read here https://github.com/bigclownlabs/bcp-wireless-circus for example led on
    mosquitto_pub -t “node/base/led/-/state/set” -m true

I apologize for the inconvenience, but we are currently preparing a new radio stack and we have not yet received the documentation update. Now there will be no base and remote but id nodes.


#3

Hi,
I look on bc-gateway scripts and change my FW slightly (I have wrong topics) and it works now.

Thank you!