lora-receive-message

antoniorrg/lora-k0515-keyestudio-receive-node/lora-receive-message

No description
lora-receive-message
@/lora-receive-message
RF69_FREQnumber
Frequency used for the communications (must be the same a the frequency on the sender end)
Powernumber
Power for the communications. Higher power allows a long-range communication, but consumes more energy.
UPDpulse
Update pin to control the signals
lora-receive-message
Message
DONE
RF69_FREQ
Power
UPD
DONEpulse
Pulses 1 once the node has been executed
Messagenumber
Displays the message received by the sender device (in decimal numbers)
To use the node in your project you should have the antoniorrg/lora-k0515-keyestudio-receive-node 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/adafruit/RadioHead"
#pragma XOD require "https://github.com/nandland/spi-master"
#pragma XOD require "https://github.com/LowPowerLab/RFM69"


#include <SPI.h>
#include <RH_RF69.h>
#include <RHReliableDatagram.h>

int RFM69_INT = 2;   
int RFM69_RST = 3;
int RFM69_CS = 10;
int RF69_FREQ = 343;
int DEST_ADDRESS = 2;
int MY_ADDRESS = 1;

RH_RF69 rf69(RFM69_CS, RFM69_INT);
RHReliableDatagram rf69_manager(rf69, MY_ADDRESS);

node {
    // Internal state variables defined at this level persists across evaluations

    Number foo;
    uint8_t bar = 5;
    void evaluate(Context ctx) {
        bar += 42;
        if (isSettingUp()) {
            // This run once
            foo = (Number)(bar + 1);

        }
       
       if (!isInputDirty<input_UPD>(ctx))
       return;

Number RFM69_INT;   
Number RF69_FREQ;
int Message;
int Power;
        
  RF69_FREQ = getValue<input_RF69_FREQ>(ctx);
  Power = getValue<input_Power>(ctx);

  ::pinMode(RFM69_RST, OUTPUT);
        
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
        

  ::digitalWrite(RFM69_RST, 0);

//Manual reset
  ::digitalWrite(RFM69_RST, 1);
    delay (10);
  ::digitalWrite(RFM69_RST, 0);
    delay (10);
        
  rf69.setFrequency(RF69_FREQ);
  rf69_manager.init();

  rf69.setTxPower(Power, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW
        
  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);

uint8_t buf[60];
delay (1000);

    while (!rf69_manager.available()){}
    uint8_t len = sizeof(buf);
    uint8_t from;
    while (!rf69_manager.recvfromAck(buf, &len, &from)){}
    buf[len] = 0; // zero out remaining string
    Message = atoi((const char*) buf);
    emitValue<output_Message>(ctx, Message); 
    emitValue<output_DONE>(ctx, 1);

    delay (10);
}
}