Factory firmware for the MultiTech Dotbox (MTDOT-BOX) and EVB (MTDOT-EVB) products.

Dependencies:   NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2

MTDOT-BOX/EVB Firmware Description

This Firmware is what ships on DotBox and EVB devices. It is intended to be used as a proof of concept and site survey tool for planning LoRa deployments. The firmware provides a number of different modes of operation:

  • Configuration - Use AT commands to configure network credentials, TX power, TX data rate, view the survey data file, etc.
  • Survey Single - Test network connectivity at current location at a specific TX power and TX data rate. Uplink information, downlink information, and GPS information are saved to the survey data file and can also be sent to the gateway.
  • Survey Sweep - Test network connectivity at current location across a range of TX powers and TX data rates. Uplink information, downlink information, and GPS information for each survey in the sweep are saved to the survey data file and can also be sent to the gateway.
  • LoRa Demo - Gather data from onboard sensors and display it on the screen in real time. Send packets containing sensor data to the gateway either on an interval or when triggered by the user. GPS data is not transmitted.
  • Survey GPS - Gather sensor and GPS data and transmit it to the gateway either on an interval or when triggered by the user. Add padding to packets, switch frequency sub bands, TX power, TX data rate, and more all without exiting Survey GPS Mode.
  • View Data - View the survey data file on the screen one survey at a time.

Additional documentation and information for the MTDOT-BOX/EVB Factory Firmware can be found here.


Dot Libraries

Dot Library Limitations

The commit messages in libmDot-mbed5 and libmDot-dev-mbed5 specify the version of the Dot library the commit contains and the version of mbed-os it was compiled against. We recommend building your application with the version of mbed-os specified in the commit message of the version of the Dot library you're using. This will ensure that you don't run into any runtime issues caused by differences in the mbed-os versions.

Development library for mDot.

[Repository '/teams/MultiTech/code/libmDot-dev-mbed5/' not found]

Stable library for mDot.

Import librarylibmDot-mbed5

Stable version of the mDot library for mbed 5. This version of the library is suitable for deployment scenarios. See lastest commit message for version of mbed-os library that has been tested against.

Revision:
12:05435282f899
Parent:
7:a31236c2e75c
Child:
16:e76cec0eec43
--- a/main.cpp	Thu Nov 10 22:10:58 2016 +0000
+++ b/main.cpp	Tue Oct 09 13:49:30 2018 -0500
@@ -43,19 +43,26 @@
 #include "ModeConfig.h"
 #include "ModeGps.h"
 #include "ModeData.h"
+#include "ModeRegion.h"
 // misc heders
 #include "FileName.h"
 #include <string>
 
+#ifndef CHANNEL_PLAN
+#define CHANNEL_PLAN  CP_US915
+#endif
+
 #define DISABLE_DUTY_CYCLE true
 
-
 // LCD and LED controllers
 SPI lcd_spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
-I2C led_i2c(I2C_SDA, I2C_SCL);
 DigitalOut lcd_spi_cs(SPI1_CS, 1);
 DigitalOut lcd_cd(XBEE_ON_SLEEP, 1);
 DOGS102* lcd;
+
+I2C i2c(I2C_SDA, I2C_SCL);
+static const int i2c_freq = 400000;  // i2c bus frequency in Hz
+
 NCP5623B* led_cont;
 
 // Thread informaiton
@@ -67,11 +74,12 @@
 // LoRa controller
 LoRaHandler* lora_handler;
 
+lora::ChannelPlan* plan;
 mDot* dot;
 
 // GPS
 GPSPARSER* gps;
-MTSSerial gps_serial(XBEE_DOUT, XBEE_DIN, 256, 2048);
+MTSSerial  gps_serial(XBEE_DOUT, XBEE_DIN, 256, 2048);
 
 // Sensors
 SensorHandler* sensors;
@@ -84,43 +92,125 @@
 ModeConfig* modeConfig;
 ModeGps* modeGps;
 ModeData* modeData;
+ModeRegion* modeRegion;
 
 // Serial debug port
-Serial debug(USBTX, USBRX);
+Serial debug_port(USBTX, USBRX);
 
 // Survey Data File
 char file_name[] = "SurveyData.txt";
 
+// Channel plan file
+char file_cp[] = "ChannelPlan";
+
 // Prototypes
 void mainMenu();
 
 int main() {
-    debug.baud(115200);
+    debug_port.baud(115200);
+
+    i2c.frequency(i2c_freq);
 
     lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd);
     // NCP5623B::LEDs 1 & 2 are the screen backlight - not used on default build
     // NCP5623B::LED3 is EVB LED2
-    led_cont = new NCP5623B(led_i2c);
+    led_cont = new NCP5623B(i2c);
+    gps = new GPSPARSER(&gps_serial, led_cont);
+    sensors = new SensorHandler(i2c);
 
     main_id = Thread::gettid();
     buttons = new ButtonHandler(main_id);
-    dot = mDot::getInstance();
-    lora_handler = new LoRaHandler(main_id);
+    MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
+
+    logDebug("Loading default plan");
+
+#if CHANNEL_PLAN == CP_AS923
+    plan = new lora::ChannelPlan_AS923();
+#elif CHANNEL_PLAN == CP_US915
+    plan = new lora::ChannelPlan_US915();
+#elif CHANNEL_PLAN == CP_AU915
+    plan = new lora::ChannelPlan_AU915();
+#elif CHANNEL_PLAN == CP_EU868
+    plan = new lora::ChannelPlan_EU868();
+#elif CHANNEL_PLAN == CP_KR920
+    plan = new lora::ChannelPlan_KR920();
+#elif CHANNEL_PLAN == CP_IN865
+    plan = new lora::ChannelPlan_IN865();
+#elif CHANNEL_PLAN == CP_AS923_JAPAN
+    plan = new lora::ChannelPlan_AS923_Japan();
+#endif
+    mDot* dot = mDot::getInstance(plan);
+
+    uint8_t cplan[] = { 0 };
+    mDot::mdot_file file;	
+    vector<mDot::mdot_file> files = dot->listUserFiles();
+
+    for (vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) {
+        if (strcmp(file_cp,it->name)==0) {
+            file = dot->openUserFile(it->name, mDot::FM_RDWR);
+            dot->seekUserFile(file, 0, SEEK_SET);
+            dot->readUserFile(file, cplan, 1); 
+            dot->closeUserFile(file);
+        }
+    }
+
+    if(cplan[0]) {
+        if(cplan[0] != CHANNEL_PLAN){
+            logDebug("Loading saved channel plan");
+            switch (cplan[0]){
+                case CP_AS923:
+                    delete plan;  
+                    plan = new lora::ChannelPlan_AS923();
+                    break;
+
+                case CP_US915:
+                    delete plan;
+                    plan = new lora::ChannelPlan_US915();
+                    break;
+
+                case CP_AU915:
+                    delete plan;
+                    plan = new lora::ChannelPlan_AU915();
+                    break;
+
+                case CP_EU868:
+                    delete plan;
+                    plan = new lora::ChannelPlan_EU868();
+                    break;
+
+                case CP_KR920:
+                    delete plan;
+                    plan = new lora::ChannelPlan_KR920();
+                    break;
+
+                case CP_AS923_JAPAN:
+                    delete plan;
+                    plan = new lora::ChannelPlan_AS923_Japan();
+                    break;
+
+                default:
+                    logInfo("Saved channel plan not valid Defaulting US915");
+                    delete plan;
+                    plan = new lora::ChannelPlan_US915();
+                    break;
+            }
+            dot->setChannelPlan(plan);   
+        }
+    } 
+    lora_handler = new LoRaHandler(main_id, dot);
 
     dot->setDisableDutyCycle(DISABLE_DUTY_CYCLE);
     dot->setLinkCheckThreshold(0);
     dot->setLinkCheckCount(0);
-
+    //Adr off to make sure modes work, auto sleep off seems to cause issues, haven't looked into it yet
+    dot->setAdr(false);
+    dot->setLogLevel(MTSLog::DEBUG_LEVEL);
+    dot->setAutoSleep(false); 
     // Seed the RNG
     srand(dot->getRadioRandom());
 
-    gps = new GPSPARSER(&gps_serial, led_cont);
-    sensors = new SensorHandler();
-
     led_cont->setLEDCurrent(16);
 
-    MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
-
     modeJoin = new ModeJoin(lcd, buttons, dot, lora_handler, gps, sensors);
     modeSingle = new ModeSingle(lcd, buttons, dot, lora_handler, gps, sensors);
     modeSweep = new ModeSweep(lcd, buttons, dot, lora_handler, gps, sensors);
@@ -128,17 +218,21 @@
     modeConfig = new ModeConfig(lcd, buttons, dot, lora_handler, gps, sensors);
     modeGps = new ModeGps(lcd, buttons, dot, lora_handler, gps, sensors, modeJoin);
     modeData = new ModeData(lcd, buttons, dot, lora_handler, gps, sensors);
-
+    modeRegion = new ModeRegion(lcd, buttons, dot, lora_handler, gps, sensors, file_cp);
 
     osDelay(1000);
     logInfo("%sGPS detected", gps->gpsDetected() ? "" : "no ");
 
+    if(!cplan[0]) {
+        dot->saveUserFile(file_cp, cplan, 1);    
+        modeRegion->start();
+    }
+
     // display startup screen for 3 seconds
     LayoutStartup ls(lcd, dot);
     ls.display();
     ls.updateGPS(gps->gpsDetected());
     osDelay(3000);
-
     logInfo("displaying main menu");
     mainMenu();
 
@@ -149,15 +243,15 @@
     bool mode_selected = false;
     std::string selected;
     std::string product;
-    
+
     typedef enum {
         demo = 1,
         config,
         single,
         sweep,
         gps,
-        data
-
+        data,
+        region
     } menu_items;
 
     std::string menu_strings[] = {
@@ -167,8 +261,10 @@
         "Survey Single",
         "Survey Sweep",
         "Survey GPS",
-        "View Data"
+        "View Data",
+        "Select Region"
     };
+
     std::vector<std::string> items;
     items.push_back(menu_strings[demo]);
     items.push_back(menu_strings[config]);
@@ -176,19 +272,21 @@
     items.push_back(menu_strings[sweep]);
     items.push_back(menu_strings[gps]);
     items.push_back(menu_strings[data]);
+    items.push_back(menu_strings[region]);
 
     while (true) {
-        product = "DOT-BOX/EVB ";
-        product += mDot::FrequencyBandStr(dot->getFrequencyBand());
-
         // reset session between modes
         dot->resetNetworkSession();
-        lora_handler->resetActivityLed();
-
+        selected = "";
+        //dot->getChannelPlanName causes hard faults, not sure why.
+        product = "DOT-BOX/EVB " + plan->GetPlanName();
+        if(product.size() > 17)
+            product = "DOT-BOX/EVB JAPAN";    
         LayoutScrollSelect menu(lcd, items, product, menu_strings[0]);
         menu.display();
 
         while (! mode_selected) {
+            lora_handler->resetActivityLed();
             osEvent e = Thread::signal_wait(buttonSignal);
             if (e.status == osEventSignal) {
                 ButtonHandler::ButtonEvent ev = buttons->getButtonEvent();
@@ -219,17 +317,19 @@
             if (modeJoin->start())
                 modeSweep->start();
         } else if (selected == menu_strings[gps]) {
-            if(dot->getFrequencyBand() == mDot::FB_EU868) {
-                modeJoin->start();
+            if (plan->IsPlanDynamic()) {
+                if(modeJoin->start())
+                    modeGps->start();
             }
-            modeGps->start();
+            else { 
+                modeGps->start();
+            }
         } else if (selected == menu_strings[data]) {
             modeData->start();
-        } 
-
+        } else if (selected == menu_strings[region]) {
+            modeRegion->start();
+        }
+        lora_handler->resetActivityLed();  
         mode_selected = false;
     }
 }
-
-
-