Quantcast
Channel: MultiTech Developer Resources » All Posts
Viewing all articles
Browse latest Browse all 7111

Reply To: mDot running out of memory after around 800 frames

$
0
0
std::vector<uint8_t> payload;

int main() {
    /*--------LoRa Configuration-----------------*/
    // Custom event handler for automatically displaying RX data
    RadioEvent events;
    mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
    dot = mDot::getInstance();
    logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
    
    // start from a well-known state
    logInfo("defaulting Dot configuration");
    dot->resetConfig();
    dot->resetNetworkSession();

    // make sure library logging is turned on
    dot->setLogLevel(mts::MTSLog::INFO_LEVEL);

    // attach the custom events handler
    dot->setEvents(&events);

    // update configuration if necessary
    if (dot->getJoinMode() != mDot::OTA) {
        logInfo("changing network join mode to OTA");
        if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK)
            logError("failed to set network join mode to OTA");
    }
    // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY
    update_ota_config_name_phrase(network_name, network_passphrase, 0, public_network, ack);
    
    // configure the Dot for class C operation
    // the Dot must also be configured on the gateway for class C
    // use the lora-query application to do this on a Conduit: http://www.multitech.net/developer/software/lora/lora-network-server/
    logInfo("changing network mode to class C");
    if (dot->setClass("C") != mDot::MDOT_OK)
        logError("failed to set network mode to class C");
    
    if (dot->setTxDataRate(DataRate) != mDot::MDOT_OK)
        logError("failed to set TX DR");
        
    if (dot->setTxPower(20) != mDot::MDOT_OK)
        logError("failed to set TX Power");
        
    // save changes to configuration
    logInfo("saving configuration");
    if (!dot->saveConfig())
        logError("failed to save configuration");

    // display configuration
    display_config();
    
    
    //Tell the gateway that this device is up and running
    if (!dot->getNetworkJoinStatus())
        join_network();
    payload.push_back((int8_t) var0);
    send_data(payload);

/*--------------LOOP------------------------------------*/
    while (true) {  
        if (refresh_Timer.read_ms() >= refresh_Time) {
                refresh_Timer.reset();
                // join network if not joined
                if (!dot->getNetworkJoinStatus())
                    join_network();
                //std::vector<uint8_t> payload; //tried changing the payload variable's 
	       //scope so that it would always be destroyed after sending, but that didn't help
                payload.clear();
                //std::vector<uint8_t>(payload).swap(payload); // also didn't help
                payload.push_back((int8_t) var1);
                payload.push_back((int8_t) var2);
                payload.push_back((int8_t) var3);
	        //var4 and var5 are uint32_t (conversion from float)
                for(int i=24; i>=0; i-=8)
                    payload.push_back((var4>>i)&0xFF);
                for(int i=24; i>=0; i-=8)
                    payload.push_back((var5>>i)&0xFF);
                payload.push_back((int8_t) var6);
                payload.push_back((int8_t) var7);
                logInfo("Time-on-air for %d byte: %ld",payload.size(), dot->getTimeOnAir(payload.size()));
                send_data(payload);
                next_tx = dot->getNextTxMs();
                logInfo("Time to next TX: %ld", next_tx);
        }
        
        //soft reset solution I was talking about
        if (reset_cpu_Timer.read_ms() >= reset_cpu_Time)
            dot->resetCpu();
    }
    return 0;
}

Viewing all articles
Browse latest Browse all 7111

Trending Articles