A simple program that connects to University of Queensland's Lora network and requests a joke, then prints the joke to usb serial.

Dependencies:   fota-mdot libmDot MTS-Serial

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "mDot.h"
00003 #include "LoraComms.h"
00004 #include "DebugTerminal.h"
00005 
00006 Serial pc(USBTX, USBRX); // The serial connection through micro-usb cable
00007 mDot* dot = NULL;
00008 Thread debugTerminalThread;
00009 
00010 // Callback function for running a terminal in its own thread
00011 void terminalThreadStarter(mts::DebugTerminal* term) {
00012     term->start();
00013 }
00014 
00015 int main() {
00016     std::vector<uint8_t> tx_data;
00017     std::vector<uint8_t> rx_data;
00018     
00019     pc.baud(115200);
00020     pc.printf("Started program\r\n");
00021     
00022     dot = initializeLora();
00023     
00024     // Create the terminal for the rs232 port and run it in its own thread
00025     mts::DebugTerminal* debugTerminal = new mts::DebugTerminal(dot, UART_TX, UART_RX);
00026     debugTerminal->baud(115200);
00027     debugTerminalThread.start(callback(terminalThreadStarter, debugTerminal));
00028     
00029     tx_data.push_back('s');
00030     tx_data.push_back('c');
00031     tx_data.push_back('/');
00032     tx_data.push_back('j');
00033     
00034     while (true) {
00035         // join network if not joined
00036         if (!dot->getNetworkJoinStatus()) {
00037             join_network(dot);
00038         }
00039         
00040         // Send what's in tx_data to server and print what's received
00041         if (dot->send(tx_data) == mDot::MDOT_OK) {
00042             if (dot->recv(rx_data) == mDot::MDOT_OK) {
00043                 pc.printf("Received data\r\n");
00044                 for (uint8_t i = 0; i < rx_data.size(); ++i) {
00045                     pc.printf("%c", rx_data[i]);
00046                 }
00047                 pc.printf("\r\n");
00048                 rx_data.clear();
00049             }
00050         }
00051         pc.printf("Waiting\r\n");
00052         wait(30.f);
00053     }
00054 }