RUI3 (RAK Unified Interface 3) - RAK4631
RAKLorawan::encry

Public Member Functions

bool get ()
 
bool set (bool value)
 

Detailed Description

Description
This api configures P2P mode encryption

Member Function Documentation

◆ get()

bool get ( )
Description
This api allows to get the status of P2P mode encryption
Syntax
api.lorawan.encry.get()
Returns
bool
Return values
TRUE: P2P mode encryption is enable
FALSE: P2P mode encryption is disable
Example
  long startTime;
  char * node_encrypt_key = "aaaabbbbccccdddd";
  uint8_t encrypt_buff[16];
  
  void setup()
  {
      Serial.begin(115200);
      startTime = millis();
    
      Serial.println("P2P Start");
      
      Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
      Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
      Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
      Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
      Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
      Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
      Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
  Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
  Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set((uint8_t *)node_encrypt_key, 16) ? "Success" : "Fail");
  
      Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enbale" : "Disable");

  api.lorawan.enckey.get(encrypt_buff, 16);
  Serial.printf("P2P encryption Key = 0x");
      for (int i = 0 ; i < 16 ; i++) {
          Serial.printf("%02X", encrypt_buff[i]);
      }
  Serial.println("");
    
      randomSeed(millis());
  }

  void loop()
  {
      uint8_t payload[] = "payload";

      int rxDelay = random(3000, 5000);
    
      // Receive P2P data every 10 seconds
      if(millis() - startTime >= 10*1000) {
        Serial.printf("P2P Rx start for %d millisSconds\r\n", rxDelay);
        startTime = millis();
        Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
        delay(rxDelay);
      } else {
      
        Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
        delay(1000);
      }

  }

◆ set()

bool set ( bool  value)
Description
This api allows to enable or disable P2P mode encryption
Syntax
api.lorawan.encry.set(value)
Parameters
valuethe status of P2P mode encryption
Returns
bool
Return values
TRUE: for Setting status of encryption success
FALSE: for setting status of encryption failure
Example
  long startTime;
  char *  node_encrypt_key = "aaaabbbbccccdddd";
  uint8_t encrypt_buff[16];
  
  void setup()
  {
      Serial.begin(115200);
      startTime = millis();
    
      Serial.println("P2P Start");
      
      Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
      Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
      Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
      Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
      Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
      Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
      Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
  Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
  Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set((uint8_t *)node_encrypt_key, 16) ? "Success" : "Fail");
  
      Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enbale" : "Disable");

  api.lorawan.enckey.get(encrypt_buff, 16);
  Serial.printf("P2P encryption Key = 0x");
      for (int i = 0 ; i < 16 ; i++) {
          Serial.printf("%02X", encrypt_buff[i]);
      }
  Serial.println("");
    
      randomSeed(millis());
  }

  void loop()
  {
      uint8_t payload[] = "payload";

      int rxDelay = random(3000, 5000);
    
      // Receive P2P data every 10 seconds
      if(millis() - startTime >= 10*1000) {
        Serial.printf("P2P Rx start for %d millisSconds\r\n", rxDelay);
        startTime = millis();
        Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
        delay(rxDelay);
      } else {
      
        Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
        delay(1000);
      }
  }