test demo
Dependencies: PinDetect libmDot mbed-rtos mbed-src
Fork of mDot_LoRa_Connect_Woodstream_Demo by
main.cpp@5:66abb6adfdc5, 2015-11-10 (annotated)
- Committer:
- tmulrooney
- Date:
- Tue Nov 10 23:55:42 2015 +0000
- Revision:
- 5:66abb6adfdc5
- Parent:
- 4:47c98ad6a0c3
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jlcolemanmbed | 0:5fa2b08cb3e0 | 1 | /********************************************************************************** |
jlcolemanmbed | 0:5fa2b08cb3e0 | 2 | * This program monitors the power on state, kill state and battery voltage on |
jlcolemanmbed | 0:5fa2b08cb3e0 | 3 | * Woodstream mouse trap using the Multitech mDot and UDK2 development system. |
jlcolemanmbed | 0:5fa2b08cb3e0 | 4 | * The power on state is monitored on the PA_4(UDK2 Pin D10)and the kill state is |
jlcolemanmbed | 0:5fa2b08cb3e0 | 5 | * monitored on the PA_5 (UDK2 Pin D13) Digital Input Pins. The battery voltage |
jlcolemanmbed | 0:5fa2b08cb3e0 | 6 | * is monitored on the PB_1 (UDK2 Pin A0) Analog Input. The status of these pins |
jlcolemanmbed | 0:5fa2b08cb3e0 | 7 | * are transferred from the mDot LoRa to the Conduit LoRa gateway. The status is |
jlcolemanmbed | 0:5fa2b08cb3e0 | 8 | * also shown on the USB Debug Terminal Window. |
jlcolemanmbed | 0:5fa2b08cb3e0 | 9 | *********************************************************************************/ |
jlcolemanmbed | 0:5fa2b08cb3e0 | 10 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 11 | #include "mbed.h" |
jlcolemanmbed | 0:5fa2b08cb3e0 | 12 | #include "mDot.h" |
jlcolemanmbed | 0:5fa2b08cb3e0 | 13 | #include "MTSLog.h" |
jlcolemanmbed | 0:5fa2b08cb3e0 | 14 | #include <string> |
jlcolemanmbed | 0:5fa2b08cb3e0 | 15 | #include <vector> |
jlcolemanmbed | 0:5fa2b08cb3e0 | 16 | #include <algorithm> |
jlcolemanmbed | 0:5fa2b08cb3e0 | 17 | #include "PinDetect.h" |
jlcolemanmbed | 0:5fa2b08cb3e0 | 18 | |
tmulrooney | 1:535366982662 | 19 | #define MIN_CHANGE_BATTERY_VOLTAGE 0 |
tmulrooney | 5:66abb6adfdc5 | 20 | #define LED_TIME 1 |
tmulrooney | 2:a61b09bc91ea | 21 | #define BATTERY_TIME 2.0 |
tmulrooney | 3:34d92fdfbe06 | 22 | #define KILL_STATUS_TIME 3.0 |
tmulrooney | 3:34d92fdfbe06 | 23 | #define POWER_ON_TIME 4.0 |
tmulrooney | 1:535366982662 | 24 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 25 | mDot* dot; |
tmulrooney | 1:535366982662 | 26 | Ticker ledTimer; |
tmulrooney | 1:535366982662 | 27 | Ticker batteryTimer; |
tmulrooney | 2:a61b09bc91ea | 28 | Ticker killStatusTimer; |
tmulrooney | 2:a61b09bc91ea | 29 | Ticker powerOnTimer; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 30 | |
tmulrooney | 1:535366982662 | 31 | AnalogIn batteryVoltage(PB_1); |
tmulrooney | 2:a61b09bc91ea | 32 | DigitalIn powerOn(PA_4); |
tmulrooney | 4:47c98ad6a0c3 | 33 | DigitalIn killStatus(PA_5); |
tmulrooney | 1:535366982662 | 34 | DigitalOut transmitLED(PA_0); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 35 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 36 | // Configuration variables |
tmulrooney | 1:535366982662 | 37 | static std::string config_network_name = "LORA_NET"; |
tmulrooney | 1:535366982662 | 38 | static std::string config_network_pass = "BLUE_HEN1"; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 39 | static uint8_t config_frequency_sub_band = 7; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 40 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 41 | //Global Variables |
tmulrooney | 3:34d92fdfbe06 | 42 | bool readyToSendBatteryVoltage; |
tmulrooney | 3:34d92fdfbe06 | 43 | bool readyToSendKillStatus; |
tmulrooney | 3:34d92fdfbe06 | 44 | bool readyToSendPowerOn; |
tmulrooney | 3:34d92fdfbe06 | 45 | float lastBatteryVoltage; |
tmulrooney | 2:a61b09bc91ea | 46 | uint8_t lastKillStatus; |
tmulrooney | 2:a61b09bc91ea | 47 | uint8_t lastPowerOn; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 48 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 49 | //Function prototypes |
tmulrooney | 1:535366982662 | 50 | void ledWrite(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 51 | void periodicSendTock(); |
tmulrooney | 1:535366982662 | 52 | void batteryRead(); |
tmulrooney | 2:a61b09bc91ea | 53 | void killStatusRead(); |
tmulrooney | 2:a61b09bc91ea | 54 | void powerOnRead(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 55 | void printError(mDot* dot, int32_t returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 56 | void printVersion(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 57 | bool setFrequencySubBand(uint8_t subBand); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 58 | bool setNetworkName(const std::string name); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 59 | bool setNetworkPassphrase(const std::string passphrase); |
tmulrooney | 1:535366982662 | 60 | bool setTxDataRate(const int dataRate); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 61 | bool setPower(uint8_t power); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 62 | bool setAck(uint8_t retries); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 63 | bool joinNetwork(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 64 | bool send(const std::string text); |
tmulrooney | 1:535366982662 | 65 | char latestData[100]; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 66 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 67 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 68 | int main() |
jlcolemanmbed | 0:5fa2b08cb3e0 | 69 | { |
tmulrooney | 1:535366982662 | 70 | bool configFail = false; |
tmulrooney | 3:34d92fdfbe06 | 71 | readyToSendBatteryVoltage = false; |
tmulrooney | 3:34d92fdfbe06 | 72 | readyToSendKillStatus = false; |
tmulrooney | 3:34d92fdfbe06 | 73 | readyToSendPowerOn = false; |
tmulrooney | 5:66abb6adfdc5 | 74 | lastBatteryVoltage = 0.0; |
tmulrooney | 5:66abb6adfdc5 | 75 | lastKillStatus = killStatus; |
tmulrooney | 2:a61b09bc91ea | 76 | lastPowerOn = powerOn; |
tmulrooney | 2:a61b09bc91ea | 77 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 78 | //Start LED startup sequence |
tmulrooney | 3:34d92fdfbe06 | 79 | ledTimer.attach(&ledWrite, LED_TIME); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 80 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 81 | printf("\r\n\r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 82 | printf("=====================================\r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 83 | printf("WoodStream LoRa Mousetrap Demo \r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 84 | printf("=====================================\r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 85 | printVersion(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 86 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 87 | // get the mDot handle |
tmulrooney | 1:535366982662 | 88 | dot = mDot::getInstance(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 89 | dot->setLogLevel(mts::MTSLog::INFO_LEVEL); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 90 | |
tmulrooney | 1:535366982662 | 91 | //******************************************* |
tmulrooney | 1:535366982662 | 92 | // configuration |
tmulrooney | 1:535366982662 | 93 | //******************************************* |
jlcolemanmbed | 0:5fa2b08cb3e0 | 94 | // reset to default config so we know what state we're in |
jlcolemanmbed | 0:5fa2b08cb3e0 | 95 | dot->resetNetworkSession(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 96 | dot->resetConfig(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 97 | |
tmulrooney | 1:535366982662 | 98 | // set up the mDot with our network information: frequency sub band, network name, and network password |
tmulrooney | 1:535366982662 | 99 | // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig() |
tmulrooney | 1:535366982662 | 100 | configFail = !setFrequencySubBand(config_frequency_sub_band); |
tmulrooney | 1:535366982662 | 101 | configFail |= !setNetworkName(config_network_name); |
tmulrooney | 1:535366982662 | 102 | configFail |= !setNetworkPassphrase(config_network_pass); |
tmulrooney | 1:535366982662 | 103 | configFail |= !setTxDataRate(mDot::SF_8); |
tmulrooney | 1:535366982662 | 104 | configFail |= !setPower(20); // Reduce latency for 868 units |
tmulrooney | 1:535366982662 | 105 | configFail |= !setAck(0); // Disable ack for less latency |
tmulrooney | 1:535366982662 | 106 | |
tmulrooney | 1:535366982662 | 107 | printf("Configration %s\r\n",configFail?"Failed":"Passed"); |
tmulrooney | 1:535366982662 | 108 | |
tmulrooney | 1:535366982662 | 109 | // save this configuration to the mDot's NVM |
tmulrooney | 1:535366982662 | 110 | printf("saving config\r\n"); |
tmulrooney | 1:535366982662 | 111 | if (! dot->saveConfig()) |
tmulrooney | 1:535366982662 | 112 | { |
tmulrooney | 1:535366982662 | 113 | logError("failed to save configuration"); |
tmulrooney | 1:535366982662 | 114 | } |
tmulrooney | 1:535366982662 | 115 | //******************************************* |
tmulrooney | 1:535366982662 | 116 | // end of configuration |
tmulrooney | 1:535366982662 | 117 | //******************************************* |
tmulrooney | 1:535366982662 | 118 | |
tmulrooney | 1:535366982662 | 119 | // keep trying to join the network |
tmulrooney | 1:535366982662 | 120 | while (!joinNetwork()) |
tmulrooney | 1:535366982662 | 121 | { |
tmulrooney | 1:535366982662 | 122 | wait(200); |
tmulrooney | 1:535366982662 | 123 | dot->resetNetworkSession(); |
tmulrooney | 1:535366982662 | 124 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 125 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 126 | // Stop LED startup sequence & configure them for operation |
jlcolemanmbed | 0:5fa2b08cb3e0 | 127 | transmitLED = 1; |
tmulrooney | 3:34d92fdfbe06 | 128 | // start all paramter timers to sample analog and digital inputs |
tmulrooney | 2:a61b09bc91ea | 129 | batteryTimer.attach(batteryRead, BATTERY_TIME); |
tmulrooney | 2:a61b09bc91ea | 130 | killStatusTimer.attach(killStatusRead, KILL_STATUS_TIME); |
tmulrooney | 2:a61b09bc91ea | 131 | powerOnTimer.attach(powerOnRead, POWER_ON_TIME); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 132 | |
tmulrooney | 1:535366982662 | 133 | while (1) |
tmulrooney | 1:535366982662 | 134 | { |
tmulrooney | 1:535366982662 | 135 | // is there anything to send |
tmulrooney | 3:34d92fdfbe06 | 136 | if(readyToSendBatteryVoltage) |
tmulrooney | 3:34d92fdfbe06 | 137 | { |
tmulrooney | 3:34d92fdfbe06 | 138 | sprintf(latestData,"Voltage %2.2f",(double)lastBatteryVoltage); |
tmulrooney | 3:34d92fdfbe06 | 139 | printf("%s\r\n",latestData); |
tmulrooney | 3:34d92fdfbe06 | 140 | send(latestData); |
tmulrooney | 3:34d92fdfbe06 | 141 | readyToSendBatteryVoltage = false; |
tmulrooney | 3:34d92fdfbe06 | 142 | } |
tmulrooney | 3:34d92fdfbe06 | 143 | if(readyToSendKillStatus) |
tmulrooney | 1:535366982662 | 144 | { |
tmulrooney | 3:34d92fdfbe06 | 145 | sprintf(latestData,"KillStatus %d",lastKillStatus); |
tmulrooney | 4:47c98ad6a0c3 | 146 | printf("%s\r\n",latestData); |
tmulrooney | 4:47c98ad6a0c3 | 147 | send(latestData); |
tmulrooney | 3:34d92fdfbe06 | 148 | readyToSendKillStatus = false; |
tmulrooney | 3:34d92fdfbe06 | 149 | } |
tmulrooney | 3:34d92fdfbe06 | 150 | if(readyToSendPowerOn) |
tmulrooney | 3:34d92fdfbe06 | 151 | { |
tmulrooney | 3:34d92fdfbe06 | 152 | sprintf(latestData,"PowerOn %d",lastPowerOn); |
tmulrooney | 3:34d92fdfbe06 | 153 | printf("%s\r\n",latestData); |
tmulrooney | 3:34d92fdfbe06 | 154 | send(latestData); |
tmulrooney | 3:34d92fdfbe06 | 155 | readyToSendPowerOn = false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 156 | } |
tmulrooney | 1:535366982662 | 157 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 158 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 159 | |
tmulrooney | 1:535366982662 | 160 | void ledWrite() |
tmulrooney | 1:535366982662 | 161 | { |
tmulrooney | 1:535366982662 | 162 | transmitLED = !transmitLED; |
tmulrooney | 1:535366982662 | 163 | } |
tmulrooney | 1:535366982662 | 164 | |
tmulrooney | 1:535366982662 | 165 | void batteryRead() |
tmulrooney | 1:535366982662 | 166 | { |
tmulrooney | 3:34d92fdfbe06 | 167 | lastBatteryVoltage = batteryVoltage * (float)3.3; |
tmulrooney | 3:34d92fdfbe06 | 168 | readyToSendBatteryVoltage = true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 169 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 170 | |
tmulrooney | 2:a61b09bc91ea | 171 | void killStatusRead() |
tmulrooney | 2:a61b09bc91ea | 172 | { |
tmulrooney | 4:47c98ad6a0c3 | 173 | lastKillStatus = killStatus; |
tmulrooney | 3:34d92fdfbe06 | 174 | readyToSendKillStatus = true; |
tmulrooney | 2:a61b09bc91ea | 175 | } |
tmulrooney | 2:a61b09bc91ea | 176 | |
tmulrooney | 2:a61b09bc91ea | 177 | void powerOnRead() |
tmulrooney | 2:a61b09bc91ea | 178 | { |
tmulrooney | 3:34d92fdfbe06 | 179 | lastPowerOn = powerOn; |
tmulrooney | 3:34d92fdfbe06 | 180 | readyToSendPowerOn = true; |
tmulrooney | 3:34d92fdfbe06 | 181 | } |
tmulrooney | 2:a61b09bc91ea | 182 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 183 | void printVersion() |
jlcolemanmbed | 0:5fa2b08cb3e0 | 184 | { |
tmulrooney | 1:535366982662 | 185 | printf("%s Built on: %s %s\r\n\r\n", dot->getId().c_str(),__DATE__,__TIME__); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 186 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 187 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 188 | bool setFrequencySubBand(uint8_t subBand) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 189 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 190 | int32_t returnCode; |
tmulrooney | 1:535366982662 | 191 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 192 | printf("Setting frequency sub band to '%d'...\r\n", subBand); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 193 | if ((returnCode = dot->setFrequencySubBand(subBand)) != mDot::MDOT_OK) { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 194 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 195 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 196 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 197 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 198 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 199 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 200 | bool setNetworkName(const std::string name) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 201 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 202 | int32_t returnCode; |
tmulrooney | 1:535366982662 | 203 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 204 | printf("Setting network name to '%s'...\r\n", name.c_str()); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 205 | if ((returnCode = dot->setNetworkName(name)) != mDot::MDOT_OK) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 206 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 207 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 208 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 209 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 210 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 211 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 212 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 213 | bool setNetworkPassphrase(const std::string passphrase) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 214 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 215 | int32_t returnCode; |
tmulrooney | 1:535366982662 | 216 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 217 | printf("Setting passphrase to '%s'...\r\n", passphrase.c_str()); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 218 | if ((returnCode = dot->setNetworkPassphrase(passphrase)) != mDot::MDOT_OK) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 219 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 220 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 221 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 222 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 223 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 224 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 225 | |
tmulrooney | 1:535366982662 | 226 | bool setTxDataRate(const int dataRate) |
tmulrooney | 1:535366982662 | 227 | { |
tmulrooney | 1:535366982662 | 228 | int32_t returnCode; |
tmulrooney | 1:535366982662 | 229 | |
tmulrooney | 1:535366982662 | 230 | printf("Setting TX Spreading factor to %d...\r\n",dataRate); |
tmulrooney | 1:535366982662 | 231 | if ((returnCode = dot->setTxDataRate(dataRate)) != mDot::MDOT_OK) |
tmulrooney | 1:535366982662 | 232 | { |
tmulrooney | 1:535366982662 | 233 | logError("Failed To Set Tx Datarate %d:%s", returnCode, mDot::getReturnCodeString(returnCode).c_str()); |
tmulrooney | 1:535366982662 | 234 | printError(dot, returnCode); |
tmulrooney | 1:535366982662 | 235 | return false; |
tmulrooney | 1:535366982662 | 236 | } |
tmulrooney | 1:535366982662 | 237 | return true; |
tmulrooney | 1:535366982662 | 238 | } |
tmulrooney | 1:535366982662 | 239 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 240 | bool setPower(uint8_t power) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 241 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 242 | int32_t returnCode; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 243 | printf("Setting tx power to '%d'...\r\n", power); |
tmulrooney | 1:535366982662 | 244 | if ((returnCode = dot->setTxPower(power)) != mDot::MDOT_OK) |
tmulrooney | 1:535366982662 | 245 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 246 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 247 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 248 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 249 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 250 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 251 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 252 | bool joinNetwork() |
jlcolemanmbed | 0:5fa2b08cb3e0 | 253 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 254 | int32_t returnCode; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 255 | printf("\r\nJoining network...\r\n"); |
tmulrooney | 1:535366982662 | 256 | if ((returnCode = dot->joinNetworkOnce()) != mDot::MDOT_OK) |
tmulrooney | 1:535366982662 | 257 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 258 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 259 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 260 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 261 | printf("Network Joined!\r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 262 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 263 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 264 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 265 | bool setAck(uint8_t retries) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 266 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 267 | int32_t returnCode; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 268 | printf("Setting ack to '%d'...\r\n", retries); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 269 | if ((returnCode = dot->setAck(retries)) != mDot::MDOT_OK) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 270 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 271 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 272 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 273 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 274 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 275 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 276 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 277 | bool send(const std::string text) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 278 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 279 | int32_t returnCode; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 280 | uint32_t timeTillSend = dot->getNextTxMs(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 281 | if (timeTillSend != 0) { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 282 | printf("waiting %lu ms to send\r\n", timeTillSend); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 283 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 284 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 285 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 286 | printf("Sending data... "); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 287 | std::vector<uint8_t> data(text.begin(), text.end()); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 288 | if ((returnCode = dot->send(data, 1)) != mDot::MDOT_OK) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 289 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 290 | printError(dot, returnCode); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 291 | return false; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 292 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 293 | printf("Data sent!\r\n"); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 294 | return true; |
jlcolemanmbed | 0:5fa2b08cb3e0 | 295 | } |
jlcolemanmbed | 0:5fa2b08cb3e0 | 296 | |
jlcolemanmbed | 0:5fa2b08cb3e0 | 297 | void printError(mDot* dot, int32_t returnCode) |
jlcolemanmbed | 0:5fa2b08cb3e0 | 298 | { |
jlcolemanmbed | 0:5fa2b08cb3e0 | 299 | std::string error = mDot::getReturnCodeString(returnCode) + " - " + dot->getLastError(); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 300 | printf("%s\r\n", error.c_str()); |
jlcolemanmbed | 0:5fa2b08cb3e0 | 301 | } |