Accelerometer values through MQTT

Hi folks,

I have a Core Module (using the ‘generic node’ firmware) and PIR Module connected through MQTT and it’s all working fine with temperature and PIR events. I’d now like to access the accelerometer values in the same way, but I checked the generic firmware source and it has nothing to support it. Is there a firmware that does? Ideally I’d like one firmware that just published everything it had available…

Many thanks

Paul

Hi Paul,
the button firmware is sending data based on which side you rotate the kit.

Try it and let me know if this 6 side “dice” detection is enough, or you would like to have raw float data of each axis. Then we decide what next steps would be,

Hi, thanks! But yes, I need the raw float values - the idea is to control audio and laser output by waving your arms about :smiley:

But if it doesn’t exist the code to read the MEMS in bcf-radio-push-button should be enough create a Frankenstein’s Monster combined with bcf-generic-node - I just have to get the build system working!

Thanks again

Paul

Hi again,

OK, I got the build system working (brilliant tools, by the way!) and created a custom application to publish the accelerometer values - here’s the code, in case it’s useful to anyone!

// Stripped down firmware to report accelerometer only
#include <application.h>

#define ACCELEROMETER_UPDATE_INTERVAL 1000
#define PUBLISH_INDIVIDUAL_AXES 1

// Accelerometer instance
bc_lis2dh12_t lis2dh12;

// This function dispatches accelerometer events
void lis2dh12_event_handler(bc_lis2dh12_t *self, bc_lis2dh12_event_t event,
                            void *event_param)
{
    // Update event?
    if (event == BC_LIS2DH12_EVENT_UPDATE)
    {
        bc_lis2dh12_result_g_t result;

        // Successfully read accelerometer vectors?
        if (bc_lis2dh12_get_result_g(self, &result))
        {
            bc_log_info("APP: Acceleration = [%.2f,%.2f,%.2f]",
                        result.x_axis, result.y_axis, result.z_axis);

#if PUBLISH_INDIVIDUAL_AXES
            // Split for ViGraph input, one topic per axis
            bc_radio_pub_float("accelerometer/-/x-axis", &result.x_axis);
            bc_radio_pub_float("accelerometer/-/y-axis", &result.y_axis);
            bc_radio_pub_float("accelerometer/-/z-axis", &result.z_axis);
#else
            // Standard way - publish a vector on 'accelerometer/-/acceleration'
            bc_radio_pub_acceleration(&result.x_axis, &result.y_axis,
                                      &result.z_axis);
#endif
       }
    }
    // Error event?
    else if (event == BC_LIS2DH12_EVENT_ERROR)
    {
        bc_log_error("APP: Accelerometer error");
    }
}

void application_init(void)
{
    // Initialize log
    bc_log_init(BC_LOG_LEVEL_INFO, BC_LOG_TIMESTAMP_ABS);
    bc_log_info("APP: Reset");

    // Initialize accelerometer
    bc_lis2dh12_init(&lis2dh12, BC_I2C_I2C0, 0x19);
    bc_lis2dh12_set_event_handler(&lis2dh12, lis2dh12_event_handler, NULL);
    bc_lis2dh12_set_update_interval(&lis2dh12, ACCELEROMETER_UPDATE_INTERVAL);

    // Initialize radio
    bc_radio_init(BC_RADIO_MODE_NODE_SLEEPING);

    // Send radio pairing request
    bc_radio_pairing_request("accelerometer", VERSION);
}

My MQTT interface can’t handle vectors yet so I’ve split the usual vector publish into three custom ones. That allows me to connect to our ViGraph system through MQTT and graph the output:

Result :smiley:!

However there is one issue - if I publish the 3 results every second (as in code above) it works OK, but if I decrease the interval to 100ms it can’t handle 3 publishes any more and I get erratic results. If I only send one axis it seems fine. Am I hitting some message speed limit? What’s the maximum rate I can send?

Many thanks

Paul

Hi Paul,

we’re glad you like toolchain and environment.

Thanks for nice write-up of what you did! I’ve never heard of ViGraph and I’ll check it out. If you will have a video of your project, don’t hesitate to share it.

Radio communication has its limits. We use low-power low-bandwith and all messages are also confirmed which adds up.

The solution is really to send them in a single packet.

We have packet for accelerometer http://sdk.bigclown.com/group__bc__radio.html#ga6114c688e82c6619f6bcb2d1f064f9e4

Also check for other functions in that module. You can run node-red or our HARDWARIO Playground and try to separate vectors there to different topics which ViGraph can understand.