lora-send-message

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

No description
lora-send-message
@/lora-send-message
RF69_FREQnumber
Frequency used for the communications (must be the same a the frequency on the receiver end)
DEST_ADDRESSnumber
Address of the receiver Lora
Powernumber
Power for the communications. Higher power allows a long-range communication, but consumes more energy.
Messagenumber
Message to be sent
UPDpulse
Pin to update the node
lora-send-message
Received
DONE
RF69_FREQ
DEST_ADDRESS
Power
Message
UPD
DONEpulse
Pulses 1 once the node has been executed
Receivednumber
If the receiver device sends a message, it will be displayed here
To use the node in your project you should have the antoniorrg/lora-k0515-keyestudio-send-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 = 1;
int MY_ADDRESS = 2;

  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);
        }
        
    Number foo;
    uint8_t bar = 5;
    
       if (!isInputDirty<input_UPD>(ctx))
       return;

        
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);

Number RF69_FREQ;
char radiopacket [20];
int Power;
int DEST_ADDRESS;
int Received;
int Message;
       
Message = getValue<input_Message>(ctx);
itoa(Message, radiopacket, 10);
        
  RF69_FREQ = getValue<input_RF69_FREQ>(ctx);
  DEST_ADDRESS = getValue<input_DEST_ADDRESS>(ctx);
  Power = getValue<input_Power>(ctx);
        
  ::pinMode(RFM69_RST, OUTPUT);
  ::digitalWrite(RFM69_RST, 0);

  rf69_manager.init();
  rf69.setFrequency(RF69_FREQ);
        
//Manual reset
  ::digitalWrite(RFM69_RST, 1);
    delay (10);
  ::digitalWrite(RFM69_RST, 0);
    delay (10);
        
  rf69.setTxPower(20, 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);

// Dont put this on the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
delay (1000);

if (rf69_manager.sendtoWait((uint8_t *)radiopacket, strlen(radiopacket), DEST_ADDRESS)) {
    // Now wait for a reply from the server
    uint8_t len = sizeof(buf);
    uint8_t from;   
      if (rf69_manager.recvfromAckTimeout(buf, &len, 2000, &from)) {
      buf[len] = 0; // zero out remaining string
      Received = atoi((const char*) buf);
      emitValue<output_Received>(ctx, Received);
    } 
  } 

radiopacket [0] = '\0';
emitValue<output_DONE>(ctx, 1);
}
}