B4R Question Wrapping Radiohead RH_Serial

Discussion in 'B4R Questions' started by janderkan, Nov 1, 2018.

  1. janderkan

    janderkan Active Member Licensed User

    I have succesfully wrapped RH_ASK class in Radiohead library by cut and paste Erels RFM95 class :)

    Now I need the RH_Serial class, but it needs a Hardware serial in the constructor.
    I managed to compile it using a Esp8266 but get a hardware reset when I try to send data.

    This is my addition to rRadiohead.h

    class B4RRHSERIAL {

                uint8_t backend[sizeof(RH_Serial)];
                RH_Serial* rhserial;
                PollerNode pnode;
                SubVoidByteArray DataAvailableSub;
                Byte buffer[RH_SERIAL_MAX_PAYLOAD_LEN];
                static void looper(void* b);
                bool Initialize(SubVoidByteArray DataAvailableSub, byte ThisAddress);
                bool Send(ArrayByte* Data);
    and this is a new rRHSerial.cpp

    #include "B4RDefines.h"

    namespace B4R {
        bool B4RRHSERIAL::Initialize(SubVoidByteArray DataAvailableSub, byte ThisAddress) {
            this->DataAvailableSub = DataAvailableSub;
            FunctionUnion fu;
            fu.PollerFunction = looper;
            pnode.functionUnion = fu;
            pnode.tag = this;

            HardwareSerial MySerial(
            rhserial = new (backend) RH_Serial(MySerial);

            bool r = rhserial->init();
    if (r) {
    if (pnode.next == NULL)
            return r;

        void B4RRHSERIAL::looper(void* b) {
            B4RRHSERIAL* me = (B4RRHSERIAL*)b;
            if (me->rhserial->available()) {
                const UInt cp = B4R::StackMemory::cp;
                ArrayByte* arrPayload = CreateStackMemoryObject(ArrayByte);
                arrPayload->data = me->buffer;
                Byte len = RH_SERIAL_MAX_PAYLOAD_LEN;
                me->rhserial->recv(me->buffer, &len);
                arrPayload->length = len;
                B4R::StackMemory::cp = cp;

        bool B4RRHSERIAL::Send(Array* Data) {
            return rhserial->send((Byte*)Data->data, Data->length);
    Please help me......
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that HardwareSerial(0) is available? It is probably the same as Serial1.

    The way to debug such issues is by adding log outputs:
    Use these messages to find the error point.

    You might also need to add delay(100) after each call.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice