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_Street_light by
main.cpp@2:20a5d4681abf, 2017-01-31 (annotated)
- Committer:
- hariom
- Date:
- Tue Jan 31 12:56:05 2017 +0000
- Revision:
- 2:20a5d4681abf
- Parent:
- 1:c999b29cd8ad
- Child:
- 6:db60638d7f9a
commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ivaneco | 0:451bc0b1d5ee | 1 | #include "mbed.h" |
| ivaneco | 0:451bc0b1d5ee | 2 | #include "mDot.h" |
| hariom | 2:20a5d4681abf | 3 | #include "wrapper.h" |
| ivaneco | 0:451bc0b1d5ee | 4 | #include "MTSLog.h" |
| ivaneco | 0:451bc0b1d5ee | 5 | #include <string> |
| hariom | 2:20a5d4681abf | 6 | #include"Thread.h" |
| hariom | 2:20a5d4681abf | 7 | //#include <vector> |
| hariom | 2:20a5d4681abf | 8 | //#include <algorithm> |
| ivaneco | 0:451bc0b1d5ee | 9 | |
| ivaneco | 0:451bc0b1d5ee | 10 | // these options must match the settings on your Conduit |
| ivaneco | 0:451bc0b1d5ee | 11 | // uncomment the following lines and edit their values to match your configuration |
| hariom | 2:20a5d4681abf | 12 | char *config_network_name = "pathfinder"; |
| hariom | 2:20a5d4681abf | 13 | char *config_network_pass = "pathfinder"; |
| hariom | 2:20a5d4681abf | 14 | static int config_frequency_sub_band = 7; |
| hariom | 2:20a5d4681abf | 15 | |
| hariom | 2:20a5d4681abf | 16 | //void startLoraTask(void); |
| hariom | 2:20a5d4681abf | 17 | //void startZigbeeTask(void); |
| hariom | 2:20a5d4681abf | 18 | //void startBLETask(void); |
| ivaneco | 0:451bc0b1d5ee | 19 | |
| hariom | 2:20a5d4681abf | 20 | //void loraTask(void const *args); |
| hariom | 2:20a5d4681abf | 21 | //void zigbeeTask(void const *args); |
| hariom | 2:20a5d4681abf | 22 | //void bleTask(void const *args); |
| hariom | 2:20a5d4681abf | 23 | |
| hariom | 2:20a5d4681abf | 24 | void receive_data_from_gateway(void const *args); |
| hariom | 2:20a5d4681abf | 25 | void send_data_to_gateway(void const *args); |
| hariom | 2:20a5d4681abf | 26 | |
| hariom | 2:20a5d4681abf | 27 | int main() |
| hariom | 2:20a5d4681abf | 28 | { |
| hariom | 2:20a5d4681abf | 29 | printf("starting main thread\r\n"); |
| ivaneco | 0:451bc0b1d5ee | 30 | |
| hariom | 2:20a5d4681abf | 31 | int ret; |
| hariom | 2:20a5d4681abf | 32 | //printf("lora task started\r\n"); |
| hariom | 2:20a5d4681abf | 33 | printf("Initializing Lora mdot lib\r\n"); |
| hariom | 2:20a5d4681abf | 34 | init_mdot(); |
| ivaneco | 0:451bc0b1d5ee | 35 | |
| hariom | 2:20a5d4681abf | 36 | printf("Resetting Lora mdot config\r\n"); |
| hariom | 2:20a5d4681abf | 37 | reset_config(); |
| ivaneco | 0:451bc0b1d5ee | 38 | |
| hariom | 2:20a5d4681abf | 39 | printf("Setting Log info lavel\r\n"); |
| hariom | 2:20a5d4681abf | 40 | set_log_lavel(4); |
| hariom | 2:20a5d4681abf | 41 | |
| hariom | 2:20a5d4681abf | 42 | //set_public_network(false); |
| hariom | 2:20a5d4681abf | 43 | |
| ivaneco | 0:451bc0b1d5ee | 44 | // set up the mDot with our network information: frequency sub band, network name, and network password |
| ivaneco | 0:451bc0b1d5ee | 45 | // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig() |
| ivaneco | 0:451bc0b1d5ee | 46 | |
| ivaneco | 0:451bc0b1d5ee | 47 | // frequency sub band is only applicable in the 915 (US) frequency band |
| ivaneco | 0:451bc0b1d5ee | 48 | // 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 |
| ivaneco | 0:451bc0b1d5ee | 49 | // if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels |
| hariom | 2:20a5d4681abf | 50 | |
| hariom | 2:20a5d4681abf | 51 | printf("setting frequency sub band %d\r\n", config_frequency_sub_band); |
| hariom | 2:20a5d4681abf | 52 | ret = set_frequency_sub_band(config_frequency_sub_band); |
| hariom | 2:20a5d4681abf | 53 | if (ret < 0) { |
| hariom | 2:20a5d4681abf | 54 | logError("failed to set frequency sub band"); |
| ivaneco | 0:451bc0b1d5ee | 55 | } |
| ivaneco | 0:451bc0b1d5ee | 56 | |
| hariom | 2:20a5d4681abf | 57 | printf("setting network name: %s\r\n", config_network_name); |
| hariom | 2:20a5d4681abf | 58 | ret = set_network_name(config_network_name); |
| hariom | 2:20a5d4681abf | 59 | if (ret < 0) { |
| hariom | 2:20a5d4681abf | 60 | logError("failed to set network name"); |
| ivaneco | 0:451bc0b1d5ee | 61 | } |
| ivaneco | 0:451bc0b1d5ee | 62 | |
| hariom | 2:20a5d4681abf | 63 | printf("setting network password: %s\r\n", config_network_pass); |
| hariom | 2:20a5d4681abf | 64 | ret = set_network_passphrase(config_network_pass); |
| hariom | 2:20a5d4681abf | 65 | if (ret < 0) { |
| hariom | 2:20a5d4681abf | 66 | logError("failed to set network password"); |
| ivaneco | 0:451bc0b1d5ee | 67 | } |
| ivaneco | 0:451bc0b1d5ee | 68 | |
| hariom | 2:20a5d4681abf | 69 | set_txpower(14); |
| hariom | 2:20a5d4681abf | 70 | |
| ivaneco | 0:451bc0b1d5ee | 71 | // a higher spreading factor allows for longer range but lower throughput |
| ivaneco | 0:451bc0b1d5ee | 72 | // in the 915 (US) frequency band, spreading factors 7 - 10 are available |
| ivaneco | 0:451bc0b1d5ee | 73 | // in the 868 (EU) frequency band, spreading factors 7 - 12 are available |
| hariom | 2:20a5d4681abf | 74 | printf("setting TX spreading factor\r\n"); |
| hariom | 2:20a5d4681abf | 75 | ret = set_tx_datarate(); |
| hariom | 2:20a5d4681abf | 76 | if (ret < 0) { |
| hariom | 2:20a5d4681abf | 77 | logError("failed to set TX datarate"); |
| ivaneco | 0:451bc0b1d5ee | 78 | } |
| ivaneco | 0:451bc0b1d5ee | 79 | |
| ivaneco | 0:451bc0b1d5ee | 80 | // request receive confirmation of packets from the gateway |
| hariom | 2:20a5d4681abf | 81 | printf("enabling ACKs\r\n"); |
| hariom | 2:20a5d4681abf | 82 | ret = set_ack(true); |
| hariom | 2:20a5d4681abf | 83 | if (ret < 0) { |
| hariom | 2:20a5d4681abf | 84 | logError("failed to enable ACKs"); |
| ivaneco | 0:451bc0b1d5ee | 85 | } |
| ivaneco | 0:451bc0b1d5ee | 86 | |
| ivaneco | 0:451bc0b1d5ee | 87 | // save this configuration to the mDot's NVM |
| hariom | 2:20a5d4681abf | 88 | printf("saving config\r\n"); |
| hariom | 2:20a5d4681abf | 89 | ret = save_config(); |
| hariom | 2:20a5d4681abf | 90 | if (ret < 0) { |
| ivaneco | 0:451bc0b1d5ee | 91 | logError("failed to save configuration"); |
| ivaneco | 0:451bc0b1d5ee | 92 | } |
| hariom | 2:20a5d4681abf | 93 | |
| ivaneco | 0:451bc0b1d5ee | 94 | //******************************************* |
| ivaneco | 0:451bc0b1d5ee | 95 | // end of configuration |
| ivaneco | 0:451bc0b1d5ee | 96 | //******************************************* |
| ivaneco | 0:451bc0b1d5ee | 97 | |
| ivaneco | 0:451bc0b1d5ee | 98 | // attempt to join the network |
| hariom | 2:20a5d4681abf | 99 | printf("joining network\r\n"); |
| hariom | 2:20a5d4681abf | 100 | ret = join_network(); |
| hariom | 2:20a5d4681abf | 101 | /*if (ret < 0) { |
| hariom | 2:20a5d4681abf | 102 | printf("error in join network\r\n"); |
| hariom | 2:20a5d4681abf | 103 | }*/ |
| hariom | 2:20a5d4681abf | 104 | logInfo("creating thread for sending and receving data from gateway"); |
| hariom | 2:20a5d4681abf | 105 | |
| hariom | 2:20a5d4681abf | 106 | Thread send_lora_thread(send_data_to_gateway); |
| hariom | 2:20a5d4681abf | 107 | Thread receive_lora_thread(receive_data_from_gateway); |
| hariom | 2:20a5d4681abf | 108 | |
| hariom | 2:20a5d4681abf | 109 | while(1) { |
| hariom | 2:20a5d4681abf | 110 | osDelay(5000); |
| ivaneco | 0:451bc0b1d5ee | 111 | } |
| ivaneco | 0:451bc0b1d5ee | 112 | return 0; |
| ivaneco | 0:451bc0b1d5ee | 113 | } |
