Espotel / Mbed 2 deprecated LoRaWAN_Serial_port_driven_and_configurable_ELMO_based_on_TxRx_Template

Dependencies:   SX1272lib-PABOOST-HW-Modification mbed

Fork of LoRaWAN_ELMO_TxRx_Template by Espotel

main.cpp

Committer:
KosTee
Date:
2016-10-07
Revision:
7:3d16d6fe3b12
Parent:
6:71b489e70063
Child:
9:c7c39e01bda1

File content as of revision 7:3d16d6fe3b12:

/*

 _______  ______ ______ _______ _______ _______ _       
(_______)/ _____|_____ (_______|_______|_______|_)      
 _____  ( (____  _____) )     _    _    _____   _       
|  ___)  \____ \|  ____/ |   | |  | |  |  ___) | |      
| |_____ _____) ) |    | |___| |  | |  | |_____| |_____ 
|_______|______/|_|     \_____/   |_|  |_______)_______)

    (C)2016 Espotel Oy/Etteplan Oyj
Description: Main code for LORA radio code template
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Pasi Pulkkinen
Version 1.0
*/

#include "mbed.h"
#include "RadioHandler.h"
#include "Comissioning.h"


// --- Important notes! ---
// USE_BAND_868 has been defined in LoRaMac-board.h
// OVER_THE_AIR_ACTIVATION at Comissioning.h is enabled
// LORAWAN_PUBLIC_NETWORK at Comissioning.h is true
// LORAWAN_DEVICE_EUI at Comissioning.h should be unique for each board
// LORAWAN_APPLICATION_EUI at Comissioning.h should be unique for each conduit. Copy this to conduit network ID EUI
// LORAWAN_APPLICATION_KEY at Comissioning.h ensures secure end to end communication. Copy this to conduit network key
// dConduitBugs at LoRaMac.cpp patches a bug in Multitech Conduit Firmware 1.1.2 2016-01-13T09:59:04

DigitalOut Led1(LED1);
static bool ButtonPressed = false;

//ELMO Pushbutton interrupt
void ButtonHandler( void )
{
    ButtonPressed = true;
}

//Main application entry point.
int main( void )
{
    char XmitBuffer[100]; // Max 16 bytes in LoRa packet!
    char data[100];
    uint16_t index = 0;
    InterruptIn pushButton(USER_BUTTON);
    Serial debugPort(SERIAL_TX, SERIAL_RX);
    debugPort.baud(9600);
    debugPort.printf("\r\n\r\nELMO Debug Screen\r\n");
    pushButton.rise(&ButtonHandler);
    pushButton.enable_irq();
    RadioInit();

    while( 1 )
    {
        // Show some debug stuff in case Elmo button is pressed. Request packet transmission    
        if (debugPort.readable()) {
            data[index]=debugPort.getc();
            
            if (data[index]=='\n'){
                debugPort.printf("Your input was: %s\r\n", data);
                sprintf(XmitBuffer, "%s\r\n", data);
                Led1 = !Led1;
                RequestPacketTx(XmitBuffer, false);
                memset(data,' ', sizeof(data));
                index=0;
                }
            index++;
            if (index>100) {
                index=0;
                }
        }  
        




                
        if (ButtonPressed)
        {        
            debugPort.printf("\r\nButton was pressed\r\n");
            RadioSetup();
            debugPort.printf("JOB DONE\r\n");
            Led1 = !Led1;
            //State/Status resets for next time
            ButtonPressed = false;
        }
        
        RadioHandler();
    }
}