Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #include <lmic.h>
  3. #include <hal/hal.h>
  4. #include <SPI.h>
  5. SoftwareSerial Kekistan(11, 12); // RX | TX
  6.  
  7. // This EUI must be in little-endian format, so least-significant-byte
  8. // first. When copying an EUI from ttnctl output, this means to reverse
  9. // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
  10. // 0x70.
  11. static const u1_t PROGMEM APPEUI[8]={ 0xDA, 0xBA, 0x02, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
  12. void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
  13.  
  14. // This should also be in little endian format, see above.
  15. static const u1_t PROGMEM DEVEUI[8]={ 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12 };
  16. void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
  17.  
  18. // This key should be in big endian format (or, since it is not really a
  19. // number but a block of memory, endianness does not really apply). In
  20. // practice, a key taken from ttnctl can be copied as-is.
  21. // The key shown here is the semtech default key.
  22. static const u1_t PROGMEM APPKEY[16] = { 0x92, 0xE4, 0xD5, 0xB7, 0x31, 0xC3, 0xB0, 0x65, 0x4B, 0x58, 0x62, 0xC9, 0xCA, 0x7B, 0xCA, 0x62 };
  23. void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}
  24.  
  25. static uint8_t mydata[7];
  26. static osjob_t sendjob;
  27.  
  28. // Schedule TX every this many seconds (might become longer due to duty
  29. // cycle limitations).
  30. const unsigned TX_INTERVAL = 30;
  31.  
  32. // Pin mapping
  33. const lmic_pinmap lmic_pins = {
  34.     .nss = 10,
  35.     .rxtx = LMIC_UNUSED_PIN,
  36.     .rst = 9,
  37.     .dio = {2, 6, 7},
  38. };
  39.  
  40.  
  41.  
  42. void setup()
  43. {
  44.    #ifdef VCC_ENABLE
  45.     // For Pinoccio Scout boards
  46.     pinMode(VCC_ENABLE, OUTPUT);
  47.     digitalWrite(VCC_ENABLE, HIGH);
  48.     delay(1000);
  49.     #endif
  50.  
  51.     // LMIC init
  52.     os_init();
  53.     // Reset the MAC state. Session and pending data transfers will be discarded.
  54.     LMIC_reset();
  55.  
  56.     // Start job (sending automatically starts OTAA too)
  57.     do_send(&sendjob);
  58.    
  59.   Serial.begin(9600);
  60.   Serial.println("The bluetooth gates are open.\n Connect to HC-05 from any other bluetooth device with 1234 as pairing key!.");
  61.   Kekistan.begin(38400);  //Default Baud for comm, it may be different for your Module.
  62.   Kekistan.println("WELCOME TO Kekistan");
  63. }
  64.  
  65. void loop()
  66. {
  67.      os_runloop_once();
  68.  
  69.      String a = "acc";
  70.      a.getBytes(mydata,a.length()+1);
  71.   // Feed any data from bluetooth to Terminal.
  72.   if (Kekistan.available()){
  73.     Serial.write(Kekistan.read());
  74.     String a = Kekistan.readString();
  75.      a.getBytes(mydata,a.length()+1);
  76.   }
  77.  
  78.   // Feed all data from termial to bluetooth
  79.   if (Serial.available())
  80.     Kekistan.write(Serial.read());
  81. }
  82.  
  83.  
  84. void onEvent (ev_t ev) {
  85.     Serial.print(os_getTime());
  86.     Serial.print(": ");
  87.     switch(ev) {
  88.         case EV_SCAN_TIMEOUT:
  89.             Serial.println(F("EV_SCAN_TIMEOUT"));
  90.             break;
  91.         case EV_BEACON_FOUND:
  92.             Serial.println(F("EV_BEACON_FOUND"));
  93.             break;
  94.         case EV_BEACON_MISSED:
  95.             Serial.println(F("EV_BEACON_MISSED"));
  96.             break;
  97.         case EV_BEACON_TRACKED:
  98.             Serial.println(F("EV_BEACON_TRACKED"));
  99.             break;
  100.         case EV_JOINING:
  101.             Serial.println(F("EV_JOINING"));
  102.             break;
  103.         case EV_JOINED:
  104.             Serial.println(F("EV_JOINED"));
  105.  
  106.             // Disable link check validation (automatically enabled
  107.             // during join, but not supported by TTN at this time).
  108.             LMIC_setLinkCheckMode(0);
  109.             break;
  110.         case EV_RFU1:
  111.             Serial.println(F("EV_RFU1"));
  112.             break;
  113.         case EV_JOIN_FAILED:
  114.             Serial.println(F("EV_JOIN_FAILED"));
  115.             break;
  116.         case EV_REJOIN_FAILED:
  117.             Serial.println(F("EV_REJOIN_FAILED"));
  118.             break;
  119.             break;
  120.         case EV_TXCOMPLETE:
  121.             Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
  122.             if (LMIC.txrxFlags & TXRX_ACK)
  123.               Serial.println(F("Received ack"));
  124.             if (LMIC.dataLen) {
  125.               Serial.println(F("Received "));
  126.               Serial.println(LMIC.dataLen);
  127.               Serial.println(F(" bytes of payload"));
  128.               uint8_t result = LMIC.frame[LMIC.dataBeg + 0];
  129.               Serial.println(F(" Payload: "));
  130.               Serial.println(result);
  131.             }
  132.             // Schedule next transmission
  133.             os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
  134.             break;
  135.         case EV_LOST_TSYNC:
  136.             Serial.println(F("EV_LOST_TSYNC"));
  137.             break;
  138.         case EV_RESET:
  139.             Serial.println(F("EV_RESET"));
  140.             break;
  141.         case EV_RXCOMPLETE:
  142.             // data received in ping slot
  143.             Serial.println(F("EV_RXCOMPLETE"));
  144.             break;
  145.         case EV_LINK_DEAD:
  146.             Serial.println(F("EV_LINK_DEAD"));
  147.             break;
  148.         case EV_LINK_ALIVE:
  149.             Serial.println(F("EV_LINK_ALIVE"));
  150.             break;
  151.          default:
  152.             Serial.println(F("Unknown event"));
  153.             break;
  154.     }
  155. }
  156.  
  157. void do_send(osjob_t* j){
  158.     // Check if there is not a current TX/RX job running
  159.     if (LMIC.opmode & OP_TXRXPEND) {
  160.         Serial.println(F("OP_TXRXPEND, not sending"));
  161.     } else {
  162.         // Prepare upstream data transmission at the next possible time.
  163.         LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
  164.         Serial.println(F("Packet queued"));
  165.     }
  166.     // Next TX is scheduled after TX_COMPLETE event.
  167. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top