Advertisement
Guest User

TTN

a guest
Mar 19th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <TheThingsNetwork.h>
  2.  
  3. // Set your AppEUI and AppKey
  4. const char *appEui = "70B3D57ED0017DB0";
  5. const char *appKey = "XXXXXXXXXXXXXXXXXXXXXXXXX";
  6.  
  7. #ifndef HAVE_HWSERIAL1
  8. #include "SoftwareSerial.h"
  9. SoftwareSerial Serial1(10, 11); // RX, TX
  10. #endif
  11. #define RST 12
  12. #define loraSerial Serial1
  13. #define debugSerial Serial
  14.  
  15. // Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
  16. #define freqPlan TTN_FP_EU868
  17.  
  18. TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
  19.  
  20. void setup()
  21. {
  22.   loraSerial.begin(57600);
  23.   debugSerial.begin(9600);
  24.  
  25.   // Wait a maximum of 10s for Serial Monitor
  26.   while (!debugSerial && millis() < 10000)
  27.     ;
  28.  
  29.   debugSerial.println("-- STATUS");
  30.   ttn.showStatus();
  31.  
  32.   debugSerial.println("-- JOIN");
  33.   ttn.join(appEui, appKey);
  34. }
  35.  
  36. void loop()
  37. {
  38.   debugSerial.println("-- LOOP");
  39.  
  40.   // Prepare payload of 1 byte to indicate LED status
  41.   byte payload[1];
  42.   payload[0] = (digitalRead(LED_BUILTIN) == HIGH) ? 1 : 0;
  43.  
  44.   // Send it off
  45.   ttn.sendBytes(payload, sizeof(payload));
  46.  
  47.   delay(10000);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement