mDot project for Multitech and Explora worhshop

Dependencies:   mDot_X_NUCLEO_IKS01A1 libmDot-dev-mbed5-deprecated

Fork of mDot-IKS01A1 by Peter Ferland

Committer:
MDR
Date:
Mon Jun 26 17:22:52 2017 +0000
Revision:
12:3466445b1ac6
Parent:
10:1e3e3ab9c29c
Add support to connect to Explora server

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pferland 0:9e88a9018fc0 1 #include "mbed.h"
pferland 0:9e88a9018fc0 2 #include "mDot.h"
pferland 0:9e88a9018fc0 3 #include "x_nucleo_iks01a1.h"
pferland 0:9e88a9018fc0 4 #include "dot_util.h"
pferland 0:9e88a9018fc0 5 #include "RadioEvent.h"
pferland 9:e642e8f9ea37 6 #include <cmath>
pferland 0:9e88a9018fc0 7
MDR 12:3466445b1ac6 8 // Add support to connect to Explora server
MDR 12:3466445b1ac6 9
MDR 12:3466445b1ac6 10 DigitalOut MyLed(D7,1);
MDR 12:3466445b1ac6 11
pferland 4:142c85980a6f 12 // mDot UDK board demo with X-NUCLEO-IKS01A1 sensor card
pferland 4:142c85980a6f 13 // For more examples see the Dot-Examples project:
pferland 4:142c85980a6f 14 // https://developer.mbed.org/teams/MultiTech/code/Dot-Examples/
pferland 4:142c85980a6f 15
pferland 4:142c85980a6f 16 // This triggers an I2C issue in mbed-os 5.1.5
pferland 4:142c85980a6f 17 // Use any other revision to compile. (Tested with libmDot-dev/mbed-os 5.2.2
MDR 12:3466445b1ac6 18 //#define SENET
pferland 10:1e3e3ab9c29c 19 #ifdef ACTILITY
pferland 10:1e3e3ab9c29c 20 // Network Id for Senet public network
pferland 10:1e3e3ab9c29c 21 static uint8_t network_id[] = {0xF0, 0x3D, 0x29,0xAC,0x71,0x00,0x00, 0x00};
pferland 10:1e3e3ab9c29c 22 // Register at or Sign in to http://portal.senetco.com/ and register your NodeId to receive your AppId
pferland 10:1e3e3ab9c29c 23 // {0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B}
pferland 10:1e3e3ab9c29c 24 static uint8_t network_key[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //{0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B};
pferland 10:1e3e3ab9c29c 25 static uint8_t frequency_sub_band = 0;
pferland 10:1e3e3ab9c29c 26 static bool public_network = true;
pferland 10:1e3e3ab9c29c 27 #elif defined(SENET)
pferland 4:142c85980a6f 28 // Network Id for Senet public network
pferland 4:142c85980a6f 29 static uint8_t network_id[] = {0x00,0x25,0x0C,0x00,0x00,0x01,0x00,0x01};
pferland 4:142c85980a6f 30 // Register at or Sign in to http://portal.senetco.com/ and register your NodeId to receive your AppId
pferland 9:e642e8f9ea37 31 // {0xD3,0x5A,0x30,0x60,0xA6,0x0D,0x9E,0xEA,0xD9,0xA1,0x19,0x61,0x4F,0x29,0x9E,0x5B}
pferland 10:1e3e3ab9c29c 32 static uint8_t network_key[] = {0x5F,0x7B,0x08,0x15,0x55,0x69,0x9A,0x2E,0x3C,0x91,0xE3,0xFE,0xF0,0x2A,0x77,0x79};
pferland 4:142c85980a6f 33 // 1 For Senet, configurable on your Conduit
pferland 0:9e88a9018fc0 34 static uint8_t frequency_sub_band = 1;
pferland 4:142c85980a6f 35 // True for Senet, false for your Conduit.
pferland 4:142c85980a6f 36 static bool public_network = true;
pferland 9:e642e8f9ea37 37 #else
pferland 9:e642e8f9ea37 38 //Replace with settings on your Conduit
pferland 10:1e3e3ab9c29c 39 static std::string network_name = "EcoLabTest";
pferland 10:1e3e3ab9c29c 40 static std::string network_passphrase = "EcoLabTest";
pferland 9:e642e8f9ea37 41 // 1 For Senet, configurable on your Conduit
pferland 9:e642e8f9ea37 42 static uint8_t frequency_sub_band = 1;
pferland 9:e642e8f9ea37 43 // True for Senet, false for your Conduit.
MDR 12:3466445b1ac6 44 static bool public_network = true; // false;
pferland 9:e642e8f9ea37 45 #endif
pferland 10:1e3e3ab9c29c 46 static uint8_t ack = 0;
pferland 10:1e3e3ab9c29c 47 static uint8_t tx_datarate = mDot::SF_7;
pferland 0:9e88a9018fc0 48
pferland 4:142c85980a6f 49 // deepsleep consumes slightly less current than sleep
pferland 4:142c85980a6f 50 // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up
pferland 4:142c85980a6f 51 // in deepsleep mode, IOs float, RAM is lost, and application will start from beginning after waking up
pferland 4:142c85980a6f 52 // if deep_sleep == true, device will enter deepsleep mode
pferland 4:142c85980a6f 53 static bool deep_sleep = false;
pferland 4:142c85980a6f 54
pferland 0:9e88a9018fc0 55 mDot *dot = NULL;
pferland 0:9e88a9018fc0 56
pferland 0:9e88a9018fc0 57 int main()
pferland 0:9e88a9018fc0 58 {
pferland 4:142c85980a6f 59 Serial pc(USBTX, USBRX);
pferland 4:142c85980a6f 60
pferland 4:142c85980a6f 61 /* Instantiate the expansion board */
pferland 4:142c85980a6f 62 X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(I2C_SDA, I2C_SCL, PC_1);
pferland 4:142c85980a6f 63
pferland 4:142c85980a6f 64 /* Retrieve the composing elements of the expansion board */
pferland 4:142c85980a6f 65 GyroSensor *gyroscope = mems_expansion_board->GetGyroscope();
pferland 4:142c85980a6f 66 MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
pferland 4:142c85980a6f 67 MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
pferland 4:142c85980a6f 68 HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
pferland 4:142c85980a6f 69 PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
pferland 4:142c85980a6f 70 TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
pferland 4:142c85980a6f 71 TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
pferland 0:9e88a9018fc0 72 // Custom event handler for automatically displaying RX data
pferland 0:9e88a9018fc0 73 RadioEvent events;
pferland 0:9e88a9018fc0 74 pc.baud(115200);
pferland 0:9e88a9018fc0 75
MDR 12:3466445b1ac6 76
MDR 12:3466445b1ac6 77 #if defined(SENET) || defined(ACTILITY)
MDR 12:3466445b1ac6 78 #if defined(SENET)
MDR 12:3466445b1ac6 79 printf("Connect to SENET network\r\n");
MDR 12:3466445b1ac6 80 #else
MDR 12:3466445b1ac6 81 printf("Connect to ACTILITY network\r\n");
MDR 12:3466445b1ac6 82 #endif
MDR 12:3466445b1ac6 83 #else
MDR 12:3466445b1ac6 84 printf("Connect to MultiConnect, network_name:%s, network_passphrase:%s\r\n", network_name,network_passphrase);
MDR 12:3466445b1ac6 85 #endif
MDR 12:3466445b1ac6 86
MDR 12:3466445b1ac6 87 // LedD7 = 0;
MDR 12:3466445b1ac6 88 // printf("Led ON\r\n");
MDR 12:3466445b1ac6 89 // osDelay(2000);
MDR 12:3466445b1ac6 90 // LedD7 = 1;
MDR 12:3466445b1ac6 91 // printf("Led OFF\r\n");
MDR 12:3466445b1ac6 92 // osDelay(2000);
MDR 12:3466445b1ac6 93 // LedD7 = 0;
MDR 12:3466445b1ac6 94 // printf("Led ON\r\n");
MDR 12:3466445b1ac6 95 // osDelay(2000);
MDR 12:3466445b1ac6 96 // LedD7 = 1;
MDR 12:3466445b1ac6 97 // printf("Led OFF\r\n");
MDR 12:3466445b1ac6 98 // osDelay(2000);
MDR 12:3466445b1ac6 99 // LedD7 = 0;
MDR 12:3466445b1ac6 100 // printf("Led ON\r\n");
MDR 12:3466445b1ac6 101
pferland 0:9e88a9018fc0 102 /* Initialize mDot */
pferland 0:9e88a9018fc0 103 dot = mDot::getInstance();
pferland 8:bfbc3dd47166 104
pferland 8:bfbc3dd47166 105 //dot->setAdr(true);
pferland 4:142c85980a6f 106 mts::MTSLog::setLogLevel(mts::MTSLog::INFO_LEVEL);
pferland 0:9e88a9018fc0 107 dot->setEvents(&events);
pferland 0:9e88a9018fc0 108
pferland 0:9e88a9018fc0 109
pferland 0:9e88a9018fc0 110 if (!dot->getStandbyFlag()) {
pferland 0:9e88a9018fc0 111 logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
pferland 0:9e88a9018fc0 112 // start from a well-known state
pferland 0:9e88a9018fc0 113 logInfo("defaulting Dot configuration");
pferland 0:9e88a9018fc0 114 dot->resetConfig();
pferland 0:9e88a9018fc0 115 dot->resetNetworkSession();
pferland 0:9e88a9018fc0 116
pferland 0:9e88a9018fc0 117 // update configuration if necessary
pferland 0:9e88a9018fc0 118 // in AUTO_OTA mode the session is automatically saved, so saveNetworkSession and restoreNetworkSession are not needed
pferland 0:9e88a9018fc0 119 if (dot->getJoinMode() != mDot::AUTO_OTA) {
pferland 0:9e88a9018fc0 120 logInfo("changing network join mode to AUTO_OTA");
pferland 0:9e88a9018fc0 121 if (dot->setJoinMode(mDot::AUTO_OTA) != mDot::MDOT_OK) {
pferland 0:9e88a9018fc0 122 logError("failed to set network join mode to AUTO_OTA");
pferland 0:9e88a9018fc0 123 }
pferland 0:9e88a9018fc0 124 }
pferland 8:bfbc3dd47166 125
pferland 8:bfbc3dd47166 126 uint32_t current_tx_datarate = dot->getTxDataRate();
pferland 8:bfbc3dd47166 127 if (current_tx_datarate != tx_datarate) {
pferland 8:bfbc3dd47166 128 logInfo("changing TX datarate from %u to %u", current_tx_datarate, tx_datarate);
pferland 8:bfbc3dd47166 129 if (dot->setTxDataRate(tx_datarate) != mDot::MDOT_OK) {
pferland 8:bfbc3dd47166 130 logError("failed to set TX datarate to %u", tx_datarate);
pferland 8:bfbc3dd47166 131 }
pferland 8:bfbc3dd47166 132 }
pferland 0:9e88a9018fc0 133 // 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
pferland 0:9e88a9018fc0 134 // only one method or the other should be used!
pferland 0:9e88a9018fc0 135 // network ID = crc64(network name)
pferland 10:1e3e3ab9c29c 136 #if defined(SENET) || defined(ACTILITY)
pferland 0:9e88a9018fc0 137 // network KEY = cmac(network passphrase)
pferland 4:142c85980a6f 138 update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
pferland 9:e642e8f9ea37 139 #else
pferland 9:e642e8f9ea37 140 update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
pferland 9:e642e8f9ea37 141 #endif
pferland 0:9e88a9018fc0 142
pferland 0:9e88a9018fc0 143 // configure network link checks
pferland 0:9e88a9018fc0 144 // network link checks are a good alternative to requiring the gateway to ACK every packet and should allow a single gateway to handle more Dots
pferland 0:9e88a9018fc0 145 // check the link every count packets
pferland 0:9e88a9018fc0 146 // declare the Dot disconnected after threshold failed link checks
pferland 0:9e88a9018fc0 147 // for count = 3 and threshold = 5, the Dot will be considered disconnected after 15 missed packets in a row
pferland 0:9e88a9018fc0 148 update_network_link_check_config(3, 5);
pferland 0:9e88a9018fc0 149
pferland 0:9e88a9018fc0 150 // save changes to configuration
pferland 0:9e88a9018fc0 151 logInfo("saving configuration");
pferland 0:9e88a9018fc0 152 if (!dot->saveConfig()) {
pferland 0:9e88a9018fc0 153 logError("failed to save configuration");
pferland 0:9e88a9018fc0 154 }
pferland 0:9e88a9018fc0 155
pferland 0:9e88a9018fc0 156 // display configuration
pferland 0:9e88a9018fc0 157 display_config();
pferland 0:9e88a9018fc0 158 } else {
pferland 0:9e88a9018fc0 159 // restore the saved session if the dot woke from deepsleep mode
pferland 0:9e88a9018fc0 160 // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep
pferland 0:9e88a9018fc0 161 logInfo("restoring network session from NVM");
pferland 0:9e88a9018fc0 162 dot->restoreNetworkSession();
pferland 0:9e88a9018fc0 163 }
pferland 3:d34798ffcaf8 164
pferland 3:d34798ffcaf8 165
pferland 0:9e88a9018fc0 166
pferland 0:9e88a9018fc0 167 while (true) {
pferland 0:9e88a9018fc0 168 std::vector<uint8_t> tx_data;
pferland 0:9e88a9018fc0 169
pferland 0:9e88a9018fc0 170 // join network if not joined
pferland 0:9e88a9018fc0 171 if (!dot->getNetworkJoinStatus()) {
pferland 0:9e88a9018fc0 172 join_network();
pferland 0:9e88a9018fc0 173 }
pferland 7:d2052933ebcb 174
pferland 9:e642e8f9ea37 175 // Payload structure for mydevices cayenne:
pferland 9:e642e8f9ea37 176 // 1 byte Data1 ID
pferland 9:e642e8f9ea37 177 // 1 Byte Data1 Type
pferland 9:e642e8f9ea37 178 // N Bytes Data1
pferland 9:e642e8f9ea37 179 // 1 byte data 2 ID
pferland 9:e642e8f9ea37 180 // 1 byte data 2 type
pferland 9:e642e8f9ea37 181 // n Bytes data 2
pferland 9:e642e8f9ea37 182 // ...
pferland 9:e642e8f9ea37 183
pferland 9:e642e8f9ea37 184 // formats:
pferland 9:e642e8f9ea37 185 // Temperature sensor:
pferland 9:e642e8f9ea37 186 /*
pferland 9:e642e8f9ea37 187 * IPSO: 3303
pferland 9:e642e8f9ea37 188 * LPP 103
pferland 9:e642e8f9ea37 189 * HEX: 67
pferland 9:e642e8f9ea37 190 * Data size: 2
pferland 9:e642e8f9ea37 191 * Resolution: 0.1 degres C
pferland 9:e642e8f9ea37 192
pferland 9:e642e8f9ea37 193 * Humidity sensor
pferland 9:e642e8f9ea37 194 * IPSO: 3304
pferland 9:e642e8f9ea37 195 * LPP: 104
pferland 9:e642e8f9ea37 196 * Hex: 68
pferland 9:e642e8f9ea37 197 * Datasize: 1
pferland 9:e642e8f9ea37 198 * Resolution: 0.5% unsigned
pferland 9:e642e8f9ea37 199
pferland 9:e642e8f9ea37 200 * Barometer/pressure sensor
pferland 9:e642e8f9ea37 201 * IPSO: 3315
pferland 9:e642e8f9ea37 202 * LPP: 115
pferland 9:e642e8f9ea37 203 * Hex: 73
pferland 9:e642e8f9ea37 204 * Datasize: 2
pferland 9:e642e8f9ea37 205 * Resolution 0.1hPa unsigned MSB
pferland 9:e642e8f9ea37 206
pferland 9:e642e8f9ea37 207 * Accelerometer
pferland 9:e642e8f9ea37 208 * IPSO: 3313
pferland 9:e642e8f9ea37 209 * LPP: 113
pferland 9:e642e8f9ea37 210 * Hex: 71
pferland 9:e642e8f9ea37 211 * Data size: 6
pferland 9:e642e8f9ea37 212 * Resolution: 0.001G signed MSB per axis
pferland 9:e642e8f9ea37 213
pferland 9:e642e8f9ea37 214 * Gyrometer
pferland 9:e642e8f9ea37 215 * IPSO: 3334
pferland 9:e642e8f9ea37 216 * LPP: 134
pferland 9:e642e8f9ea37 217 * Hex: 86
pferland 9:e642e8f9ea37 218 * Data size: 6
pferland 9:e642e8f9ea37 219 * Resolution: 0.01 degrees/s signed msb per axis
pferland 9:e642e8f9ea37 220 */
pferland 9:e642e8f9ea37 221
pferland 0:9e88a9018fc0 222 //temp floats
pferland 0:9e88a9018fc0 223 float value1, value2;
pferland 4:142c85980a6f 224
pferland 0:9e88a9018fc0 225 // HTS221 Humidity sensor
pferland 0:9e88a9018fc0 226 temp_sensor1->GetTemperature(&value1);
pferland 0:9e88a9018fc0 227 humidity_sensor->GetHumidity(&value2);
pferland 4:142c85980a6f 228
pferland 0:9e88a9018fc0 229 //serialize data and append to packet
pferland 9:e642e8f9ea37 230 // Cayenne data: temperature; tag is 0x67, 2 bytes signed, 0.1 C/bit
pferland 9:e642e8f9ea37 231 tx_data.push_back(uint8_t(1)); // data id
pferland 9:e642e8f9ea37 232 tx_data.push_back(uint8_t(0x67)); // data type - temp
pferland 9:e642e8f9ea37 233 int16_t temp = floor(value1*10 + 0.5f);
MDR 12:3466445b1ac6 234 //logInfo("Temp payload: %d", temp);
pferland 9:e642e8f9ea37 235 tx_data.push_back(uint8_t( 0xFF & (temp >> 8)));
pferland 9:e642e8f9ea37 236 tx_data.push_back(uint8_t(0xFF & temp));
pferland 9:e642e8f9ea37 237
pferland 9:e642e8f9ea37 238
pferland 9:e642e8f9ea37 239 tx_data.push_back(uint8_t(2)); // data id
pferland 9:e642e8f9ea37 240 tx_data.push_back(uint8_t(0x68)); // data type - humidity
pferland 9:e642e8f9ea37 241 temp = floor(value2 * 2.0f + 0.5f);
pferland 9:e642e8f9ea37 242 tx_data.push_back(uint8_t(0xFF & temp ));
pferland 9:e642e8f9ea37 243
MDR 12:3466445b1ac6 244 logInfo("\r\n\r\nTemperature data %f", value1);
pferland 9:e642e8f9ea37 245 logInfo("Humidity data: %f", value2);
pferland 4:142c85980a6f 246
pferland 9:e642e8f9ea37 247 pressure_sensor->GetPressure(&value1);
pferland 9:e642e8f9ea37 248 logInfo("PRessure data: %f", value1);
pferland 9:e642e8f9ea37 249 // pressure is reported in mbar, cayenne wants it in 0.1 hPa
pferland 9:e642e8f9ea37 250 // 1mbar = 1 hPa
MDR 12:3466445b1ac6 251 //temp = floor(value1 * 100.0f + 0.5f);
pferland 9:e642e8f9ea37 252 tx_data.push_back(uint8_t(3)); // data id
pferland 9:e642e8f9ea37 253 tx_data.push_back(uint8_t(0x73)); // data type - pressure
pferland 9:e642e8f9ea37 254 temp = floor(value1 / 0.1f + 0.5f);
pferland 9:e642e8f9ea37 255 tx_data.push_back(uint8_t(0xFF & (temp >> 8)));
pferland 9:e642e8f9ea37 256 tx_data.push_back(uint8_t(0xFF & temp));
pferland 9:e642e8f9ea37 257
pferland 9:e642e8f9ea37 258
pferland 9:e642e8f9ea37 259 // Get accelerometer data
pferland 4:142c85980a6f 260 int32_t accel_vector[3];
pferland 9:e642e8f9ea37 261 // returns in mG
pferland 4:142c85980a6f 262 accelerometer->Get_X_Axes(accel_vector);
MDR 12:3466445b1ac6 263 logInfo("Acclerometer: %d,%d,%d", accel_vector[0], accel_vector[1], accel_vector[2]);
pferland 4:142c85980a6f 264
pferland 9:e642e8f9ea37 265 tx_data.push_back(uint8_t(4)); // data id
pferland 9:e642e8f9ea37 266 tx_data.push_back(uint8_t(0x71)); // data type - accelerometer
pferland 9:e642e8f9ea37 267 for(int i=0; i<3; i++){
MDR 12:3466445b1ac6 268 tx_data.push_back(uint8_t(0xFF & (accel_vector[i] >> 8)));
pferland 9:e642e8f9ea37 269 tx_data.push_back(uint8_t(0xFF & accel_vector[i]));
MDR 12:3466445b1ac6 270 //logInfo("Acc: %d,%d,0x%02X, 0x%02X", i, accel_vector[i], accel_vector[2]);
pferland 9:e642e8f9ea37 271 }
pferland 9:e642e8f9ea37 272
pferland 9:e642e8f9ea37 273 // Get gyro data
pferland 9:e642e8f9ea37 274 gyroscope->Get_G_Axes(accel_vector);
MDR 12:3466445b1ac6 275 logInfo("Gyroscope: %d,%d,%d", accel_vector[0], accel_vector[1], accel_vector[2]);
pferland 9:e642e8f9ea37 276 // gyro reports in milidegrees/sec, cayenne wants centidegrees/sec
pferland 9:e642e8f9ea37 277 tx_data.push_back(uint8_t(5)); //data id
pferland 9:e642e8f9ea37 278 tx_data.push_back(uint8_t(0x86)); // data type - gyrometer
pferland 9:e642e8f9ea37 279 for(int i=0; i<3; i++){
pferland 9:e642e8f9ea37 280 accel_vector[i] /= 10;
pferland 9:e642e8f9ea37 281 tx_data.push_back(uint8_t(0xFF & (accel_vector[i] >> 8)));
pferland 9:e642e8f9ea37 282 tx_data.push_back(uint8_t(0xFF & accel_vector[i]));
pferland 9:e642e8f9ea37 283 }
pferland 9:e642e8f9ea37 284
MDR 12:3466445b1ac6 285 // print Raw Data
MDR 12:3466445b1ac6 286 //logInfo("Temp raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[0], tx_data[1], tx_data[2], tx_data[3]);
MDR 12:3466445b1ac6 287 //logInfo("Hum raw: 0x%02X, 0x%02X, 0x%02X",tx_data[4], tx_data[5], tx_data[6]);
MDR 12:3466445b1ac6 288 //logInfo("Pres raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[7], tx_data[8], tx_data[9], tx_data[10]);
MDR 12:3466445b1ac6 289 //logInfo("Acc raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[11], tx_data[12], tx_data[13], tx_data[14], tx_data[15], tx_data[16], tx_data[17], tx_data[18]);
MDR 12:3466445b1ac6 290 //logInfo("Gir raw: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",tx_data[19], tx_data[20], tx_data[21], tx_data[22], tx_data[23], tx_data[24], tx_data[25], tx_data[26]);
pferland 0:9e88a9018fc0 291 send_data(tx_data);
pferland 0:9e88a9018fc0 292
pferland 10:1e3e3ab9c29c 293 if(deep_sleep){
pferland 0:9e88a9018fc0 294 // if going into deepsleep mode, save the session so we don't need to join again after waking up
pferland 0:9e88a9018fc0 295 // not necessary if going into sleep mode since RAM is retained
pferland 10:1e3e3ab9c29c 296 logInfo("saving network session to NVM");
pferland 10:1e3e3ab9c29c 297 dot->saveNetworkSession();
pferland 10:1e3e3ab9c29c 298 }
pferland 0:9e88a9018fc0 299
pferland 0:9e88a9018fc0 300
pferland 0:9e88a9018fc0 301 // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
MDR 12:3466445b1ac6 302 // mdr sleep_wake_rtc_only(deep_sleep);
pferland 0:9e88a9018fc0 303 //sleep_wake_interrupt_only(deep_sleep);
pferland 6:9e6ac13de3e9 304 //sleep_wake_rtc_or_interrupt(deep_sleep);
pferland 0:9e88a9018fc0 305
MDR 12:3466445b1ac6 306 uint32_t delay_s = dot->getNextTxMs() / 1000;
MDR 12:3466445b1ac6 307 if (delay_s < 5) {
MDR 12:3466445b1ac6 308 delay_s = 5;
MDR 12:3466445b1ac6 309 }
MDR 12:3466445b1ac6 310
MDR 12:3466445b1ac6 311 logInfo("waiting %d", delay_s);
MDR 12:3466445b1ac6 312 osDelay(delay_s*1000);
MDR 12:3466445b1ac6 313 logInfo("application resume", deepsleep ? "execute from beginning" : "resume");
MDR 12:3466445b1ac6 314
pferland 0:9e88a9018fc0 315 }
pferland 0:9e88a9018fc0 316
pferland 0:9e88a9018fc0 317 return 0;
pferland 0:9e88a9018fc0 318 }