sim900-gprs-sendsms

gabbapeople/on-board-computer/sim900-gprs-sendsms

Node allows to send an SMS messages using GPRS shield based on sim900 chip.
sim900-gprs-sendsms
@/sim900-gprs-sendsms
Node allows to send an SMS messages using GPRS shield based on sim900 chip.
UARTnumber
Hardware serial port number.
BAUDnumber
Data rate in bits per second (baud) for serial data transmission.
TELstring
Mobile telephone number in a format used in your country.
MSGstring
SMS text message. The limit is 128 characters.
SENDpulse
Triggers a new SMS sending.
RSTpulse
Triggers UART initialization.
sim900-gprs-sendsms
UART
BAUD
TEL
MSG
SEND
RST
DONE
ERR
ERRpulse
Fires if sending failed.
DONEpulse
Fires on sending complete.
To use the node in your project you should have the gabbapeople/on-board-computer 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

{{#global}}
#include <AmperkaGPRS.h>
{{/global}}

struct State {
    GPRS* gprs;
};

{{ GENERATED_CODE }}

HardwareSerial* getSerial(int8_t no) {
#if defined(HAVE_HWSERIAL0)
    if (no == 0)
        return &Serial;
#endif
#if defined(HAVE_HWSERIAL1)
    if (no == 1)
        return &Serial1;
#endif
#if defined(HAVE_HWSERIAL2)
    if (no == 2)
        return &Serial2;
#endif
#if defined(HAVE_HWSERIAL3)
    if (no == 3)
        return &Serial3;
#endif

    return nullptr;
}

template<typename TSerial>
void begin(Context ctx, TSerial* serial, uint32_t baud) {
    if (!serial)
        //emitValue<output_ERR>(ctx, 1);
        return;
    serial->begin(baud);
}

void sendSMS(Context ctx) {
    State* state = getState(ctx);
    char dataSMS[128] = { 0 };
    char phoneNumber[20] = { 0 };
    dump(getValue<input_TEL>(ctx), phoneNumber);
    dump(getValue<input_MSG>(ctx), dataSMS);
    state->gprs->sendSMS(phoneNumber, dataSMS);
    emitValue<output_DONE>(ctx, 1);
}

void evaluate(Context ctx) {
    State* state = getState(ctx);
    if(isInputDirty<input_RST>(ctx)){
        auto uartNo = getValue<input_UART>(ctx);
        auto baud = getValue<input_BAUD>(ctx);
        Stream *serialPort;	
        serialPort = getSerial(uartNo);
        begin(ctx,getSerial(uartNo), baud);
        auto gprs = state->gprs;
        state->gprs = gprs = new GPRS(*serialPort);

        gprs->powerOn();
        delay(1000);
        if (!gprs->begin()) {
            emitValue<output_ERR>(ctx, 1);
            }
    }
    if(isInputDirty<input_SEND>(ctx)){
        sendSMS(ctx);
    }
}