TheThingsNetwork / arduino-device-lib

Arduino Library for TTN Devices
MIT License
208 stars 96 forks source link

Add onMessage to set callback for downlink messages #43

Closed FokkeZB closed 8 years ago

FokkeZB commented 8 years ago

This fixes #23 in a more clean way than #34 by letting the user set a callback to receive downlink messages.

Note: For now, this doesn't touch the return value, which could now become success/error codes as requested in #11, for which #37 is pending.

In setup() set the callback:

void setup() {
  // ..
  ttn.onMessage(message);
  // ..
}

Elsewhere in your sketch define message or whatever you call it:

void message(const byte* buffer, int length, int port)
{
  debugPrint("Receive " + String(length) + " bytes on port " + String(port) + ": ");
  for (int i = 0; i < length; i++)
    debugPrint(String(buffer[i]) + " ");
  debugPrintLn();
}