Advertisement
Guest User

Untitled

a guest
Dec 30th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #include <lmic.h>
  2. #include <hal/hal.h>
  3.  
  4. /*************************************
  5. * TODO: Change the following keys
  6. * NwkSKey: network session key, AppSKey: application session key, and DevAddr: end-device address
  7. *************************************/
  8. //untuk app bonmicro
  9. //static const u1_t NWKSKEY[16] = { 0xCD, 0xA8, 0x1E, 0x11, 0x93, 0x6E, 0x2E, 0xFC, 0xB3, 0xBF, 0x29, 0x7B, 0x6E, 0x48, 0xF7, 0xCC };
  10. //static const u1_t APPSKEY[16] = { 0x6C, 0xEF, 0xF5, 0xDB, 0xCA, 0x39, 0x15, 0x5F, 0x07, 0xAA, 0xB1, 0x52, 0x57, 0xDD, 0xC5, 0x50 };
  11. //static const u4_t DEVADDR = 0x26041122 ;
  12.  
  13. //untuk app rak7249_sensortest node1
  14. //static const u1_t NWKSKEY[16] ={ 0x82, 0xD5, 0x76, 0xEF, 0xDB, 0x50, 0xE9, 0x29, 0x05, 0xCC, 0xA0, 0x85, 0x3A, 0x83, 0x98, 0xA3 };
  15. //static const u1_t APPSKEY[16] = { 0xCC, 0xDF, 0x11, 0xA7, 0xAD, 0x12, 0x87, 0x10, 0x03, 0xA8, 0x68, 0xCC, 0x4D, 0xED, 0xC5, 0xCA };
  16. //static const u4_t DEVADDR = 0x260413F3 ;
  17.  
  18. //untuk app rak7249_sensortest node2
  19. static const u1_t NWKSKEY[16] ={ 0x4E, 0x67, 0x62, 0x5F, 0xC0, 0x2D, 0x88, 0xDE, 0xC6, 0xE7, 0xA4, 0xC5, 0x4B, 0x0C, 0xEA, 0xFB };
  20. static const u1_t APPSKEY[16] = { 0x4C, 0x6D, 0x95, 0xF0, 0x13, 0x84, 0xBD, 0x18, 0x3A, 0x33, 0x82, 0xA0, 0x4A, 0x31, 0xE0, 0x1B };
  21. static const u4_t DEVADDR = 0x26041EC8 ;
  22.  
  23.  
  24.  
  25. // These callbacks are only used in over-the-air activation, so they are
  26. // left empty here (we cannot leave them out completely unless
  27. // DISABLE_JOIN is set in config.h, otherwise the linker will complain).
  28. void os_getArtEui (u1_t* buf) { }
  29. void os_getDevEui (u1_t* buf) { }
  30. void os_getDevKey (u1_t* buf) { }
  31.  
  32. static osjob_t sendjob;
  33.  
  34. // Schedule TX every this many seconds (might become longer due to duty
  35. // cycle limitations).
  36. const unsigned TX_INTERVAL = 60;
  37.  
  38. // Pin mapping for cytron lora shield
  39. /*const lmic_pinmap lmic_pins = {
  40. .nss = 10,
  41. .rxtx = LMIC_UNUSED_PIN,
  42. .rst = 7,
  43. .dio = {2, 5, 6},
  44. */
  45. // Pin mapping for dragino shield
  46. const lmic_pinmap lmic_pins = {
  47. .nss = 10,
  48. .rxtx = LMIC_UNUSED_PIN,
  49. .rst = 9,
  50. .dio = {2, 6, 7},
  51. };
  52.  
  53. void onEvent (ev_t ev) {
  54. if (ev == EV_TXCOMPLETE) {
  55. Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
  56. // Schedule next transmission
  57. os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
  58. }
  59. }
  60.  
  61. void do_send(osjob_t* j){
  62. // Payload to send (uplink)
  63. static uint8_t message[2];
  64.  
  65. int value = analogRead(A0);
  66. message[0] = highByte(value);
  67. message[1] = lowByte(value);
  68.  
  69. // Check if there is not a current TX/RX job running
  70. if (LMIC.opmode & OP_TXRXPEND) {
  71. Serial.println(F("OP_TXRXPEND, not sending"));
  72. } else {
  73. // Prepare upstream data transmission at the next possible time.
  74. LMIC_setTxData2(1, message, sizeof(message), 0);
  75. Serial.println(F("Sending uplink packet..."));
  76. }
  77. // Next TX is scheduled after TX_COMPLETE event.
  78. }
  79.  
  80. void setup() {
  81. Serial.begin(115200);
  82. Serial.println(F("Starting..."));
  83.  
  84. // LMIC init
  85. os_init();
  86.  
  87. // Reset the MAC state. Session and pending data transfers will be discarded.
  88. LMIC_reset();
  89.  
  90. // Set static session parameters.
  91. LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
  92.  
  93. // Disable link check validation
  94. LMIC_setLinkCheckMode(0);
  95.  
  96. // TTN uses SF9 for its RX2 window.
  97. LMIC.dn2Dr = DR_SF9;
  98.  
  99. // Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
  100. LMIC_setDrTxpow(DR_SF7,14);
  101.  
  102. // Start job
  103. do_send(&sendjob);
  104. }
  105.  
  106. void loop() {
  107. os_runloop_once();
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement