Xiaotian Fei
Forum Replies Created
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
Xiaotian FeiParticipant
I tried the same code again, it’s working now. Maybe I did something I have forgotten.
Thanks for running this code for me.
I have send the message {“t”:30.3} to TTN LoRa Server.
Network Key Saving Config Device ID {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x53 } Network Id/App EUI {0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 } Network Key/App Key {0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 } Joining Network {"t":30.3} {"t":30.3}
Xiaotian FeiParticipantHi, Mike
I compile following code in the mbed online compiler, libmDot version is 14, mbed lib version is 119, mbed-rtos lib is 111.
When I download the bin file into mDot 868, the program stop at:“mDot* dot = mDot::getInstance()”.
When using the mDot 915 the programming can pass this line.Can you help me with this problem, thanks.
#include "mbed.h" #include "mDot.h" #include "MTSLog.h" #include "MTSText.h" #include <string> #include <vector> using namespace mts; #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) // AppEUI uint8_t AppEUI[8] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0x06, 0x56 }; // AppKey uint8_t AppKey[16] = { 0x7F, 0xA6, 0xF7, 0x50, 0x9F, 0xE5, 0x92, 0x28, 0xD5, 0xF8, 0x79, 0xC3, 0xAD, 0x39, 0x3E, 0xD9 }; #define LORA_SF mDot::DR5 #define LORA_ACK 0 #define LORA_TXPOWER 14 Serial pc(XBEE_DOUT,XBEE_DIN);//tx, rx int main() { int32_t ret; std::vector<uint8_t> send_data; std::vector<uint8_t> recv_data; std::vector<uint8_t> nwkId; std::vector<uint8_t> nwkKey; float temperature = 28.7; pc.baud(115200); pc.printf("TTN OTAA mDot LoRa sensor \n\r"); // get a mDot handle // //dot->setLogLevel(MTSLog::TRACE_LEVEL); pc.printf("Checking Config "); // reset to default config so we know what state we're in mDot* dot = mDot::getInstance(); pc.printf("Resetting Config "); dot->resetConfig(); uint8_t *it = AppEUI; for (uint8_t i = 0; i<8; i++) nwkId.push_back((uint8_t) *it++); it = AppKey; for (uint8_t i = 0; i<16; i++) nwkKey.push_back((uint8_t) *it++); /***************** Config mDot *****************/ // Set Spreading Factor, higher is lower data rate, smaller packets but longer range // Lower is higher data rate, larger packets and shorter range. pc.printf("Set SF\n\r"); if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) { logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set TxPower\n\r"); if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) { logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set Public mode\n\r"); if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) { logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set AUTO_OTA Join mode\n\r"); if((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) { logError("Failed to set AUTO_OTA Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set Ack\n\r"); // 1 retries on Ack, 0 to disable if((ret = dot->setAck( LORA_ACK)) != mDot::MDOT_OK) { logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set Network Id\n\r"); if ((ret = dot->setNetworkId(nwkId)) != mDot::MDOT_OK) { logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Set Network Key\n\r"); if ((ret = dot->setNetworkKey(nwkKey)) != mDot::MDOT_OK) { logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } pc.printf("Saving Config\n\r"); // Save config if (! dot->saveConfig()) { logError("failed to save configuration"); } /***************** print mDot configs *****************/ pc.printf("Device ID {"); std::vector<uint8_t> deviceId; deviceId = dot->getDeviceId(); for (std::vector<uint8_t>::iterator it = deviceId.begin() ; it != deviceId.end(); ++it) { pc.printf("0x%2.2X",*it ); pc.printf("%s", it != (deviceId.end() -1 ) ? ", " : " " ); } pc.printf("}\r\n"); std::vector<uint8_t> netId; pc.printf("Network Id/App EUI {"); netId = dot->getNetworkId(); for (std::vector<uint8_t>::iterator it = netId.begin() ; it != netId.end(); ++it) { pc.printf("0x%2.2X", *it ); pc.printf("%s", it != (netId.end() -1 ) ? ", " : " " ); } pc.printf("}\r\n"); std::vector<uint8_t> netKey; pc.printf("Network Key/App Key {"); netKey = dot->getNetworkKey(); for (std::vector<uint8_t>::iterator it = netKey.begin() ; it != netKey.end(); ++it) { pc.printf("0x%2.2X", *it ); pc.printf("%s", it != (netKey.end() -1 ) ? ", " : " " ); } pc.printf("}\r\n"); /***************** connect *****************/ pc.printf("Joining Network\n\r"); while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); wait_ms(dot->getNextTxMs() + 1); } logInfo("Joined Network"); /***************** send data *****************/ char dataBuf[50]; while( 1 ) { temperature = 30.3; sprintf(dataBuf, "{\"t\":%3.1f}", temperature ); pc.printf("%s\n\r",dataBuf); send_data.clear(); // probably not the most efficent way to do this for( int i=0; i< strlen(dataBuf); i++ ) { send_data.push_back( dataBuf[i] ); } if ((ret = dot->send(send_data)) != mDot::MDOT_OK) { logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); } else { logInfo("send data: %s", Text::bin2hexString(send_data).c_str()); } // Should sleep here and wakeup after a set 5 minute interval. // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again uint32_t sleep_time = std::max((uint32_t)10000, (uint32_t)dot->getNextTxMs()) / 1000; //wait_ms(2000); // go to sleep and wake up automatically sleep_time seconds later dot->sleep(sleep_time, mDot::RTC_ALARM, false); } return 0; }
Xiaotian FeiParticipantThanks guys, I will try it.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)