Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MPU6050 Grove_temperature
communication/LoRaWanComm.cpp@11:14864dee8646, 2019-07-11 (annotated)
- Committer:
- AndersonIctus
- Date:
- Thu Jul 11 22:28:25 2019 -0300
- Revision:
- 11:14864dee8646
- Parent:
- 10:d2ce206bd94e
- Child:
- 13:2dda4a91be01
- implementacao da leitura do lorawan !!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndersonIctus | 6:806043bf1a2c | 1 | #include "sgam_mdw.h" |
AndersonIctus | 6:806043bf1a2c | 2 | #include "mbed.h" |
AndersonIctus | 7:8db3e62ac4e2 | 3 | #include "mbed_events.h" |
AndersonIctus | 8:e00fa6ea253c | 4 | #include "LoRaWANInterface.h" |
AndersonIctus | 6:806043bf1a2c | 5 | |
AndersonIctus | 6:806043bf1a2c | 6 | #include "LoRAWanComm.h" |
AndersonIctus | 6:806043bf1a2c | 7 | |
AndersonIctus | 10:d2ce206bd94e | 8 | LoRAWanComm::LoRAWanComm(const char* parameters) { } |
AndersonIctus | 6:806043bf1a2c | 9 | LoRAWanComm::~LoRAWanComm() { } |
AndersonIctus | 6:806043bf1a2c | 10 | |
AndersonIctus | 7:8db3e62ac4e2 | 11 | int LoRAWanComm::initialize(LoraData* data) { |
AndersonIctus | 7:8db3e62ac4e2 | 12 | D_LOG("INITIALIZE %s! \r\n", this->getName() ); |
AndersonIctus | 7:8db3e62ac4e2 | 13 | |
AndersonIctus | 10:d2ce206bd94e | 14 | // INICIANDO O LORAWAN !! |
AndersonIctus | 10:d2ce206bd94e | 15 | this->data = data; |
AndersonIctus | 10:d2ce206bd94e | 16 | if(data->getCallBack() == NULL) { |
AndersonIctus | 11:14864dee8646 | 17 | D_LOG("You must pass a call bak method to LoraData before the initialization process! \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 18 | return FALSE; |
AndersonIctus | 10:d2ce206bd94e | 19 | } |
AndersonIctus | 8:e00fa6ea253c | 20 | |
AndersonIctus | 8:e00fa6ea253c | 21 | lorawan = new LoRaWANInterface(*data->radio); |
AndersonIctus | 7:8db3e62ac4e2 | 22 | |
AndersonIctus | 8:e00fa6ea253c | 23 | // 1 - Initialize LoRaWAN stack |
AndersonIctus | 10:d2ce206bd94e | 24 | if (lorawan->initialize(data->ev_queue) != LORAWAN_STATUS_OK) { |
AndersonIctus | 10:d2ce206bd94e | 25 | D_LOG("LoRa initialization failed! \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 26 | return FALSE; |
AndersonIctus | 8:e00fa6ea253c | 27 | } |
AndersonIctus | 7:8db3e62ac4e2 | 28 | |
AndersonIctus | 10:d2ce206bd94e | 29 | D_LOG("Mbed LoRaWANStack initialized \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 30 | |
AndersonIctus | 10:d2ce206bd94e | 31 | // prepare application callbacks |
AndersonIctus | 10:d2ce206bd94e | 32 | lorawan->add_app_callbacks( data->getCallBack() ); |
AndersonIctus | 10:d2ce206bd94e | 33 | |
AndersonIctus | 10:d2ce206bd94e | 34 | // confirmed messages !! |
AndersonIctus | 10:d2ce206bd94e | 35 | if(data->confirmed_msg_retries > 0) |
AndersonIctus | 10:d2ce206bd94e | 36 | lorawan->set_confirmed_msg_retries(data->confirmed_msg_retries); |
AndersonIctus | 10:d2ce206bd94e | 37 | |
AndersonIctus | 10:d2ce206bd94e | 38 | // Enable adaptive data rate |
AndersonIctus | 10:d2ce206bd94e | 39 | if(data->enable_adaptive_datarate) { |
AndersonIctus | 10:d2ce206bd94e | 40 | if (lorawan->enable_adaptive_datarate() != LORAWAN_STATUS_OK) { |
AndersonIctus | 10:d2ce206bd94e | 41 | D_LOG("enable_adaptive_datarate failed! \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 42 | return FALSE; |
AndersonIctus | 10:d2ce206bd94e | 43 | } |
AndersonIctus | 10:d2ce206bd94e | 44 | |
AndersonIctus | 10:d2ce206bd94e | 45 | D_LOG("Adaptive data rate (ADR) - Enabled \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 46 | } |
AndersonIctus | 10:d2ce206bd94e | 47 | |
AndersonIctus | 10:d2ce206bd94e | 48 | return TRUE; |
AndersonIctus | 7:8db3e62ac4e2 | 49 | } |
AndersonIctus | 8:e00fa6ea253c | 50 | |
AndersonIctus | 8:e00fa6ea253c | 51 | int LoRAWanComm::finalize() { |
AndersonIctus | 8:e00fa6ea253c | 52 | D_LOG("FINALIZE %s! \r\n", this->getName() ); |
AndersonIctus | 8:e00fa6ea253c | 53 | |
AndersonIctus | 8:e00fa6ea253c | 54 | if(lorawan != NULL) delete lorawan; |
AndersonIctus | 8:e00fa6ea253c | 55 | |
AndersonIctus | 8:e00fa6ea253c | 56 | return 1; |
AndersonIctus | 8:e00fa6ea253c | 57 | } |
AndersonIctus | 6:806043bf1a2c | 58 | |
AndersonIctus | 6:806043bf1a2c | 59 | const char* LoRAWanComm::getName() { |
AndersonIctus | 6:806043bf1a2c | 60 | return "LoRAWAN"; |
AndersonIctus | 6:806043bf1a2c | 61 | } |
AndersonIctus | 6:806043bf1a2c | 62 | |
AndersonIctus | 10:d2ce206bd94e | 63 | int LoRAWanComm::connect() { |
AndersonIctus | 10:d2ce206bd94e | 64 | if(data->connect_params == NULL) { |
AndersonIctus | 10:d2ce206bd94e | 65 | D_LOG("Please, initialize the 'connect_params' in the LoraData instance before the connection process. \r\n"); |
AndersonIctus | 10:d2ce206bd94e | 66 | return FALSE; |
AndersonIctus | 10:d2ce206bd94e | 67 | } |
AndersonIctus | 10:d2ce206bd94e | 68 | |
AndersonIctus | 10:d2ce206bd94e | 69 | return lorawan->connect(*data->connect_params); |
AndersonIctus | 7:8db3e62ac4e2 | 70 | } |
AndersonIctus | 7:8db3e62ac4e2 | 71 | |
AndersonIctus | 7:8db3e62ac4e2 | 72 | int LoRAWanComm::disconnect() { |
AndersonIctus | 10:d2ce206bd94e | 73 | return -1; // lorawan->dis |
AndersonIctus | 8:e00fa6ea253c | 74 | } |
AndersonIctus | 8:e00fa6ea253c | 75 | |
AndersonIctus | 8:e00fa6ea253c | 76 | //////////////////////////////////////////////////////////////////////////////////// |
AndersonIctus | 6:806043bf1a2c | 77 | int LoRAWanComm::write(const char* data) { |
AndersonIctus | 11:14864dee8646 | 78 | |
AndersonIctus | 6:806043bf1a2c | 79 | return 0; |
AndersonIctus | 6:806043bf1a2c | 80 | } |
AndersonIctus | 6:806043bf1a2c | 81 | |
AndersonIctus | 11:14864dee8646 | 82 | int LoRAWanComm::read(unsigned char* buffer, int offset) { |
AndersonIctus | 11:14864dee8646 | 83 | return lorawan->receive(data->read_port, buffer, offset, data->read_flags); |
AndersonIctus | 6:806043bf1a2c | 84 | } |