Arduino Function: node.onReceive




Function to set a callback that will be called when the node receives a packet.




readMsgFunction: function to be called when a packet is received.




The callback function has to have three parameters as input:
  • unsigned char * buffer that contains the message;
  • int buffSize that is the dimension of the buffer;
  • int port that indicate the port in which the packet has been received.


* loraABP.ino
* A simple example to use the Arduino LoRa Node shield.
* This example join the LoRaWan network and send periodically
* packets to the server. The activation method used is
* Activation By Personalization (ABP).
* If you register an application on a server with the same
* keys used in this example you will be able to see the
* packets sent from the node.
* Change the keys below to fit the application in your server.
* Note : If you're using this example with an Arduino Primo download
* the ArduinoLowPower library from the library manager.
* This example code is in the public domain.
* created April 2017
* by

// Application's keys
const char * deviceAddress         = "26011AD0";
const char * networkSessionKey     = "F60F30CF0900CE09E07301104E02B0D3";
const char * applicationSessionKey = "0CE04D0B30C80970D30A00A101D01001";

#include "LoRaNode.h"

void setup() {  
 pinMode(31, OUTPUT);
 digitalWrite(31, HIGH);


 //register the keys for this application
 node.joinABP(deviceAddress, networkSessionKey, applicationSessionKey);
 //register callback for incoming messages
 //begin initialization
 //show the node's main parameters

void loop() {
 //send a frame every 10 seconds
 char frame[] = {0x00, 0x00, 0x00, 0xA0};

 //             data , dataLength   , port
 node.sendFrame(frame, sizeof(frame), 2);

 //wait 10 seconds sleeping to save power

void readMsg(unsigned char * rcvData, int dim, int port){
 Serial.print("data = ");
 for(int i=0; i<dim; i++)
   Serial.print(rcvData[i], HEX);
 Serial.println("on port " + String(port));

Written by