Espotel
/
LoRaWAN_ELMO_TxRx_Template
Example Tx Rx LoRa code for Multitech Conduit. Based on Semtech stack for ELMO - ver. 4.1.0.
main.cpp@5:be347c6040c1, 2016-04-19 (annotated)
- Committer:
- Pasi
- Date:
- Tue Apr 19 19:51:17 2016 +0000
- Revision:
- 5:be347c6040c1
- Parent:
- 4:0aa5d153c316
- Child:
- 6:71b489e70063
The first functioning template code. Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mleksio | 1:2be292bd43f9 | 1 | /* |
Pasi | 5:be347c6040c1 | 2 | |
Pasi | 5:be347c6040c1 | 3 | _______ ______ ______ _______ _______ _______ _ |
Pasi | 5:be347c6040c1 | 4 | (_______)/ _____|_____ (_______|_______|_______|_) |
Pasi | 5:be347c6040c1 | 5 | _____ ( (____ _____) ) _ _ _____ _ |
Pasi | 5:be347c6040c1 | 6 | | ___) \____ \| ____/ | | | | | | ___) | | |
Pasi | 5:be347c6040c1 | 7 | | |_____ _____) ) | | |___| | | | | |_____| |_____ |
Pasi | 5:be347c6040c1 | 8 | |_______|______/|_| \_____/ |_| |_______)_______) |
Pasi | 5:be347c6040c1 | 9 | |
Pasi | 5:be347c6040c1 | 10 | (C)2016 Espotel Oy/Etteplan Oyj |
Pasi | 5:be347c6040c1 | 11 | Description: Main code for LORA radio code template |
mleksio | 0:c58229885f95 | 12 | License: Revised BSD License, see LICENSE.TXT file include in the project |
Pasi | 5:be347c6040c1 | 13 | Maintainer: Pasi Pulkkinen |
Pasi | 5:be347c6040c1 | 14 | Version 1.0 |
mleksio | 0:c58229885f95 | 15 | */ |
mleksio | 0:c58229885f95 | 16 | |
Pasi | 5:be347c6040c1 | 17 | #include "mbed.h" |
Pasi | 5:be347c6040c1 | 18 | #include "RadioHandler.h" |
mleksio | 0:c58229885f95 | 19 | |
Pasi | 5:be347c6040c1 | 20 | // --- Important notes! --- |
Pasi | 5:be347c6040c1 | 21 | // USE_BAND_868 has been defined in LoRaMac-board.h |
Pasi | 5:be347c6040c1 | 22 | // OVER_THE_AIR_ACTIVATION at Comissioning.h is enabled |
Pasi | 5:be347c6040c1 | 23 | // LORAWAN_PUBLIC_NETWORK at Comissioning.h is true |
Pasi | 5:be347c6040c1 | 24 | // LORAWAN_DEVICE_EUI at Comissioning.h should be unique for each board |
Pasi | 5:be347c6040c1 | 25 | // LORAWAN_APPLICATION_EUI at Comissioning.h should be unique for each conduit. Copy this to conduit network ID EUI |
Pasi | 5:be347c6040c1 | 26 | // LORAWAN_APPLICATION_KEY at Comissioning.h ensures secure end to end communication. Copy this to conduit network key |
Pasi | 5:be347c6040c1 | 27 | // dConduitBugs at LoRaMac.cpp patches a bug in Multitech Conduit Firmware 1.1.2 2016-01-13T09:59:04 |
mleksio | 0:c58229885f95 | 28 | |
mleksio | 1:2be292bd43f9 | 29 | DigitalOut Led1(LED1); |
mleksio | 0:c58229885f95 | 30 | |
Pasi | 5:be347c6040c1 | 31 | /* |
Pasi | 5:be347c6040c1 | 32 | * True if ELMO button was pressed |
mleksio | 0:c58229885f95 | 33 | */ |
Pasi | 5:be347c6040c1 | 34 | static bool ButtonPressed = false; |
mleksio | 0:c58229885f95 | 35 | |
Pasi | 5:be347c6040c1 | 36 | /* |
Pasi | 5:be347c6040c1 | 37 | ELMO Pushbutton interrupt |
Pasi | 5:be347c6040c1 | 38 | */ |
Pasi | 5:be347c6040c1 | 39 | void ButtonHandler( void ) |
mleksio | 0:c58229885f95 | 40 | { |
Pasi | 5:be347c6040c1 | 41 | ButtonPressed = true; |
mleksio | 0:c58229885f95 | 42 | } |
mleksio | 0:c58229885f95 | 43 | |
mleksio | 0:c58229885f95 | 44 | /** |
mleksio | 0:c58229885f95 | 45 | * Main application entry point. |
mleksio | 0:c58229885f95 | 46 | */ |
mleksio | 0:c58229885f95 | 47 | int main( void ) |
mleksio | 0:c58229885f95 | 48 | { |
Pasi | 5:be347c6040c1 | 49 | char XmitBuffer[100]; // Max 16 bytes in LoRa packet! |
Pasi | 5:be347c6040c1 | 50 | uint16_t PacketCount = 0; |
Pasi | 5:be347c6040c1 | 51 | InterruptIn pushButton(USER_BUTTON); |
Pasi | 5:be347c6040c1 | 52 | Serial debugPort(SERIAL_TX, SERIAL_RX); |
Pasi | 5:be347c6040c1 | 53 | |
Pasi | 5:be347c6040c1 | 54 | debugPort.baud(9600); |
mleksio | 0:c58229885f95 | 55 | |
Pasi | 5:be347c6040c1 | 56 | debugPort.printf("\r\n\r\nELMO Debugger Screen\r\n"); |
mleksio | 0:c58229885f95 | 57 | |
Pasi | 5:be347c6040c1 | 58 | pushButton.rise(&ButtonHandler); |
Pasi | 5:be347c6040c1 | 59 | pushButton.enable_irq(); |
Pasi | 5:be347c6040c1 | 60 | |
Pasi | 5:be347c6040c1 | 61 | RadioInit(); |
mleksio | 0:c58229885f95 | 62 | |
mleksio | 0:c58229885f95 | 63 | while( 1 ) |
mleksio | 0:c58229885f95 | 64 | { |
Pasi | 5:be347c6040c1 | 65 | // Show some debug stuff in case Elmo button is pressed. Request packet transmission |
Pasi | 5:be347c6040c1 | 66 | if (ButtonPressed) |
mleksio | 0:c58229885f95 | 67 | { |
Pasi | 5:be347c6040c1 | 68 | debugPort.printf("\r\nButton was pressed\r\n"); |
Pasi | 5:be347c6040c1 | 69 | Led1 = !Led1; |
Pasi | 5:be347c6040c1 | 70 | sprintf(XmitBuffer, "Elmo calling %d", PacketCount); |
Pasi | 5:be347c6040c1 | 71 | RequestPacketTx(XmitBuffer, true); // true = enable periodic transmissions. False = send just one packet |
Pasi | 5:be347c6040c1 | 72 | if(PacketCount < 99) |
mleksio | 1:2be292bd43f9 | 73 | { |
Pasi | 5:be347c6040c1 | 74 | PacketCount++; |
mleksio | 1:2be292bd43f9 | 75 | } |
Pasi | 5:be347c6040c1 | 76 | else |
mleksio | 1:2be292bd43f9 | 77 | { |
Pasi | 5:be347c6040c1 | 78 | // Start from 1 when 99 is reached |
Pasi | 5:be347c6040c1 | 79 | PacketCount = 1; |
Pasi | 5:be347c6040c1 | 80 | } |
Pasi | 5:be347c6040c1 | 81 | ButtonPressed = false; |
Pasi | 5:be347c6040c1 | 82 | } |
mleksio | 0:c58229885f95 | 83 | |
Pasi | 5:be347c6040c1 | 84 | RadioHandler(); |
mleksio | 0:c58229885f95 | 85 | } |
mleksio | 1:2be292bd43f9 | 86 | } |