Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_LoRa_Connect_Example by
main.cpp
00001 #include "mbed.h" 00002 #include "mDot.h" 00003 #include "wrapper.h" 00004 #include "MTSLog.h" 00005 #include <string> 00006 #include"Thread.h" 00007 //#include <vector> 00008 //#include <algorithm> 00009 00010 // these options must match the settings on your Conduit 00011 // uncomment the following lines and edit their values to match your configuration 00012 char *config_network_name = "pathfinder"; 00013 char *config_network_pass = "pathfinder"; 00014 static int config_frequency_sub_band = 7; 00015 00016 //void startLoraTask(void); 00017 //void startZigbeeTask(void); 00018 //void startBLETask(void); 00019 00020 //void loraTask(void const *args); 00021 //void zigbeeTask(void const *args); 00022 //void bleTask(void const *args); 00023 00024 void receive_data_from_gateway(void const *args); 00025 void send_data_to_gateway(void const *args); 00026 00027 int main() 00028 { 00029 printf("starting main thread\r\n"); 00030 00031 int ret; 00032 //printf("lora task started\r\n"); 00033 printf("Initializing Lora mdot lib\r\n"); 00034 init_mdot(); 00035 00036 printf("Resetting Lora mdot config\r\n"); 00037 reset_config(); 00038 00039 printf("Setting Log info lavel\r\n"); 00040 set_log_lavel(4); 00041 00042 //set_public_network(false); 00043 00044 // set up the mDot with our network information: frequency sub band, network name, and network password 00045 // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig() 00046 00047 // frequency sub band is only applicable in the 915 (US) frequency band 00048 // if using a MultiTech Conduit gateway, use the same sub band as your Conduit (1-8) - the mDot will use the 8 channels in that sub band 00049 // if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels 00050 00051 printf("setting frequency sub band %d\r\n", config_frequency_sub_band); 00052 ret = set_frequency_sub_band(config_frequency_sub_band); 00053 if (ret < 0) { 00054 logError("failed to set frequency sub band"); 00055 } 00056 00057 printf("setting network name: %s\r\n", config_network_name); 00058 ret = set_network_name(config_network_name); 00059 if (ret < 0) { 00060 logError("failed to set network name"); 00061 } 00062 00063 printf("setting network password: %s\r\n", config_network_pass); 00064 ret = set_network_passphrase(config_network_pass); 00065 if (ret < 0) { 00066 logError("failed to set network password"); 00067 } 00068 00069 set_txpower(14); 00070 00071 // a higher spreading factor allows for longer range but lower throughput 00072 // in the 915 (US) frequency band, spreading factors 7 - 10 are available 00073 // in the 868 (EU) frequency band, spreading factors 7 - 12 are available 00074 printf("setting TX spreading factor\r\n"); 00075 ret = set_tx_datarate(); 00076 if (ret < 0) { 00077 logError("failed to set TX datarate"); 00078 } 00079 00080 // request receive confirmation of packets from the gateway 00081 printf("enabling ACKs\r\n"); 00082 ret = set_ack(true); 00083 if (ret < 0) { 00084 logError("failed to enable ACKs"); 00085 } 00086 00087 // save this configuration to the mDot's NVM 00088 printf("saving config\r\n"); 00089 ret = save_config(); 00090 if (ret < 0) { 00091 logError("failed to save configuration"); 00092 } 00093 00094 //******************************************* 00095 // end of configuration 00096 //******************************************* 00097 00098 // attempt to join the network 00099 printf("joining network\r\n"); 00100 ret = join_network(); 00101 /*if (ret < 0) { 00102 printf("error in join network\r\n"); 00103 }*/ 00104 logInfo("creating thread for sending and receving data from gateway"); 00105 00106 Thread send_lora_thread(send_data_to_gateway); 00107 Thread receive_lora_thread(receive_data_from_gateway); 00108 00109 while(1) { 00110 osDelay(5000); 00111 } 00112 return 0; 00113 }
Generated on Thu Jul 14 2022 07:06:07 by
1.7.2
