init-ble-uart

gabbapeople/blynk/init-ble-uart

Initializes a BLE module connection. Connects to a Blynk application. Syncs with the application
init-ble-uart
@/init-ble-uart
Initializes a BLE module connection. Connects to a Blynk application. Syncs with the application
UARTxod/uart/uart
An UART interface to which BLE module is wired
AUTHstring
A 32-digit token value of a Blynk project
RUNpulse
Triggers a synchronization with the application
INITpulse
Triggets a new connection to a Blynk application
init-ble-uart
UART
AUTH
RUN
INIT
BLNK
ERR
DONE
DONEpulse
Fires on a successful connection
ERRpulse
Fires on a failed connection
BLNK@/blynk
To use the node in your project you should have the gabbapeople/blynk library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/blynkkk/blynk-library"

// clang-format off
{{#global}}
#define BLYNK_MSG_LIMIT      1500
#include <BlynkSimpleSerialBLE.h>

extern "C" {
    struct BlynkReq;
    struct BlynkParam;
    void BlynkWidgetWriteDefault(BlynkReq __attribute__((__unused__)) &request, const BlynkParam __attribute__((__unused__)) &param);
}

namespace xodBlynkBle {
    uint8_t blynkPin;
    char blynkPinData[24];
}

BLYNK_WRITE_DEFAULT() {
   xodBlynkBle::blynkPin = request.pin;
   strcpy(xodBlynkBle::blynkPinData,param.asStr());
}


{{/global}}
// clang-format on

struct State {
    char auth[33] = { 0 };
    uint8_t mem[sizeof(BlynkStream)];
    BlynkStream* xodBlynk;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto state = getState(ctx);
    auto uart = getValue<input_UART>(ctx);

    if (isInputDirty<input_INIT>(ctx)){

        state->xodBlynk = new (state->mem) BlynkStream(_blynkTransport);

        dump(getValue<input_AUTH>(ctx),state->auth);
        state->xodBlynk->begin(*(uart->toStream()),state->auth);
        if (state->xodBlynk->connect()){
            emitValue<output_DONE>(ctx, 1);
        } else {
            emitValue<output_ERR>(ctx, 1);
        }
    }

    if(isInputDirty<input_RUN>(ctx) ){
        state->xodBlynk->run();
    }

    ValueType<output_BLNK>::T obj;
    obj = { xodBlynkBle::blynkPin, xodBlynkBle::blynkPinData, state->xodBlynk };
    emitValue<output_BLNK>(ctx, obj);
}