mDot_TTN_OTAA_Node_send_data_as_string

Dependencies:   mbed mbed-rtos BME280 DS1820

Committer:
ScheepersJ
Date:
Sun Nov 01 16:04:48 2020 +0000
Revision:
16:4aa655bf72ba
Parent:
15:8a0ebf59b8bb
mDot_TTN_OTAA_Node_send_data_as_string

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ScheepersJ 16:4aa655bf72ba 1 /** mDot_TTN_Node - Simple mDot temperature and soil moisture sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor and Capacitive Soil Moisture Sensor V1.2.
SomeRandomBloke 13:5369ba22389a 2 * It used the AUTO_OTA join mode with parameters for The Things Network.
SomeRandomBloke 11:38ce10209eff 3 *
SomeRandomBloke 2:9db840d12557 4 *
SomeRandomBloke 0:5a0b43f3b143 5 * Uses MultiTech mDot developer board http://www.multitech.com/models/94558010LF
ScheepersJ 16:4aa655bf72ba 6 * Requires a TTN gateway to sensd data
SomeRandomBloke 5:48eb9245a914 7 * http://www.multitech.net/developer/software/lora/conduit-mlinux-convert-to-basic-packet-forwarder/
SomeRandomBloke 0:5a0b43f3b143 8 *
SomeRandomBloke 13:5369ba22389a 9 * Register a device and generate a random AppKey for the currently used application Id:
SomeRandomBloke 15:8a0ebf59b8bb 10 * (You need to use your own device IDs, the ones shown here are examples only)
SomeRandomBloke 13:5369ba22389a 11 *
SomeRandomBloke 15:8a0ebf59b8bb 12 *./ttnctl devices register 0080000000000000
SomeRandomBloke 13:5369ba22389a 13 * INFO Generating random AppKey...
SomeRandomBloke 15:8a0ebf59b8bb 14 * INFO Registered device AppKey=000102030405060708090A0B0C0D0E0F DevEUI=0080000000000000
SomeRandomBloke 13:5369ba22389a 15 *
SomeRandomBloke 13:5369ba22389a 16 * or to specify the same AppKey for a new device or to reregister the same device again:
SomeRandomBloke 13:5369ba22389a 17 *
SomeRandomBloke 15:8a0ebf59b8bb 18 * ./ttnctl devices register 0080000000000000 000102030405060708090A0B0C0D0E0F
SomeRandomBloke 13:5369ba22389a 19 *
SomeRandomBloke 15:8a0ebf59b8bb 20 * ./ttnctl devices info 0080000000000000
SomeRandomBloke 13:5369ba22389a 21 * Dynamic device:
SomeRandomBloke 13:5369ba22389a 22 *
SomeRandomBloke 15:8a0ebf59b8bb 23 * AppEUI: 70B3D50000000000
SomeRandomBloke 15:8a0ebf59b8bb 24 * {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00}
SomeRandomBloke 13:5369ba22389a 25 *
SomeRandomBloke 15:8a0ebf59b8bb 26 * DevEUI: 0080000000000000
SomeRandomBloke 15:8a0ebf59b8bb 27 * {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
SomeRandomBloke 13:5369ba22389a 28 *
SomeRandomBloke 15:8a0ebf59b8bb 29 * AppKey: 000102030405060708090A0B0C0D0E0F
SomeRandomBloke 15:8a0ebf59b8bb 30 * {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}
SomeRandomBloke 13:5369ba22389a 31 *
SomeRandomBloke 13:5369ba22389a 32 *
SomeRandomBloke 13:5369ba22389a 33 * Copy the AppEUI and AppKey values provided in hex array notation above to the AppEUI and AppKey parameters below.
SomeRandomBloke 13:5369ba22389a 34 *
SomeRandomBloke 0:5a0b43f3b143 35 */
SomeRandomBloke 0:5a0b43f3b143 36
SomeRandomBloke 0:5a0b43f3b143 37 #include "mbed.h"
SomeRandomBloke 0:5a0b43f3b143 38 #include "DS1820.h"
SomeRandomBloke 0:5a0b43f3b143 39 #include "mDot.h"
SomeRandomBloke 0:5a0b43f3b143 40 #include "MTSLog.h"
SomeRandomBloke 0:5a0b43f3b143 41 #include "MTSText.h"
SomeRandomBloke 0:5a0b43f3b143 42 #include <string>
SomeRandomBloke 0:5a0b43f3b143 43 #include <vector>
SomeRandomBloke 0:5a0b43f3b143 44
SomeRandomBloke 0:5a0b43f3b143 45 using namespace mts;
SomeRandomBloke 0:5a0b43f3b143 46
SomeRandomBloke 4:f649ab1b61d1 47 #define MIN(a,b) (((a)<(b))?(a):(b))
SomeRandomBloke 4:f649ab1b61d1 48 #define MAX(a,b) (((a)>(b))?(a):(b))
SomeRandomBloke 4:f649ab1b61d1 49
SomeRandomBloke 13:5369ba22389a 50 // AppEUI
ScheepersJ 16:4aa655bf72ba 51 uint8_t AppEUI[8]={ 0x70, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x6F };
SomeRandomBloke 13:5369ba22389a 52 // AppKey
ScheepersJ 16:4aa655bf72ba 53 uint8_t AppKey[16]={ 0x18, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x9E };
SomeRandomBloke 8:8070e9d660e4 54
SomeRandomBloke 8:8070e9d660e4 55 // Some defines for the LoRa configuration
SomeRandomBloke 13:5369ba22389a 56 /*
SomeRandomBloke 13:5369ba22389a 57 * EU868 Datarates
SomeRandomBloke 13:5369ba22389a 58 * ---------------
SomeRandomBloke 13:5369ba22389a 59 * DR0 - SF12BW125
SomeRandomBloke 13:5369ba22389a 60 * DR1 - SF11BW125
SomeRandomBloke 13:5369ba22389a 61 * DR2 - SF10BW125
SomeRandomBloke 13:5369ba22389a 62 * DR3 - SF9BW125
SomeRandomBloke 13:5369ba22389a 63 * DR4 - SF8BW125
SomeRandomBloke 13:5369ba22389a 64 * DR5 - SF7BW125
SomeRandomBloke 13:5369ba22389a 65 * DR6 - SF7BW250
SomeRandomBloke 13:5369ba22389a 66 */
ScheepersJ 16:4aa655bf72ba 67
SomeRandomBloke 13:5369ba22389a 68 #define LORA_SF mDot::DR5
SomeRandomBloke 8:8070e9d660e4 69 #define LORA_ACK 0
SomeRandomBloke 8:8070e9d660e4 70 #define LORA_TXPOWER 14
SomeRandomBloke 5:48eb9245a914 71
SomeRandomBloke 3:367aa95f9771 72 // Ignoring sub band for EU modules.
SomeRandomBloke 13:5369ba22389a 73 static uint8_t config_frequency_sub_band = 1;
SomeRandomBloke 0:5a0b43f3b143 74
SomeRandomBloke 2:9db840d12557 75 // DS18B20 OneWire pin
ScheepersJ 16:4aa655bf72ba 76 // D2 on Dev Board, pin 13 on mDot
SomeRandomBloke 13:5369ba22389a 77 #define DATA_PIN PC_13
SomeRandomBloke 0:5a0b43f3b143 78
SomeRandomBloke 3:367aa95f9771 79 // Temperature sensor object
ScheepersJ 16:4aa655bf72ba 80 DS1820 probe(DATA_PIN); //Temprature in
SomeRandomBloke 0:5a0b43f3b143 81
ScheepersJ 16:4aa655bf72ba 82 //Capacitive Soil Moisture Sensor V1.2 No1
ScheepersJ 16:4aa655bf72ba 83 // A0 on Dev Board, pin 20 on mDot
ScheepersJ 16:4aa655bf72ba 84 AnalogIn A1(PB_1); //Analog 1 in for Soil Moisture
ScheepersJ 16:4aa655bf72ba 85
ScheepersJ 16:4aa655bf72ba 86 //Capacitive Soil Moisture Sensor V1.2 No2
ScheepersJ 16:4aa655bf72ba 87 // A1 on Dev Board, pin 19 on mDot
ScheepersJ 16:4aa655bf72ba 88 AnalogIn A2(PB_0); //Analog 2 in for Soil Moisture
SomeRandomBloke 13:5369ba22389a 89
SomeRandomBloke 3:367aa95f9771 90 // Serial via USB for debugging only
SomeRandomBloke 0:5a0b43f3b143 91 Serial pc(USBTX,USBRX);
SomeRandomBloke 0:5a0b43f3b143 92
SomeRandomBloke 0:5a0b43f3b143 93 int main()
SomeRandomBloke 0:5a0b43f3b143 94 {
SomeRandomBloke 0:5a0b43f3b143 95 int32_t ret;
SomeRandomBloke 0:5a0b43f3b143 96 mDot* dot;
SomeRandomBloke 0:5a0b43f3b143 97 std::vector<uint8_t> send_data;
SomeRandomBloke 0:5a0b43f3b143 98 std::vector<uint8_t> recv_data;
SomeRandomBloke 13:5369ba22389a 99 std::vector<uint8_t> nwkId;
SomeRandomBloke 13:5369ba22389a 100 std::vector<uint8_t> nwkKey;
SomeRandomBloke 0:5a0b43f3b143 101
SomeRandomBloke 0:5a0b43f3b143 102 float temperature = 0.0;
SomeRandomBloke 1:45cec6aea002 103
SomeRandomBloke 0:5a0b43f3b143 104 pc.baud(115200);
SomeRandomBloke 13:5369ba22389a 105 pc.printf("TTN OTAA mDot LoRa Temperature sensor\n\r");
SomeRandomBloke 1:45cec6aea002 106
SomeRandomBloke 0:5a0b43f3b143 107 // get a mDot handle
SomeRandomBloke 0:5a0b43f3b143 108 dot = mDot::getInstance();
SomeRandomBloke 0:5a0b43f3b143 109
SomeRandomBloke 13:5369ba22389a 110 // dot->setLogLevel(MTSLog::WARNING_LEVEL);
SomeRandomBloke 13:5369ba22389a 111 dot->setLogLevel(MTSLog::TRACE_LEVEL);
SomeRandomBloke 0:5a0b43f3b143 112
SomeRandomBloke 1:45cec6aea002 113 logInfo("Checking Config");
SomeRandomBloke 1:45cec6aea002 114
SomeRandomBloke 13:5369ba22389a 115 uint8_t *it = AppEUI;
SomeRandomBloke 13:5369ba22389a 116 for (uint8_t i = 0; i<8; i++)
SomeRandomBloke 13:5369ba22389a 117 nwkId.push_back((uint8_t) *it++);
SomeRandomBloke 13:5369ba22389a 118
SomeRandomBloke 13:5369ba22389a 119 it = AppKey;
SomeRandomBloke 5:48eb9245a914 120 for (uint8_t i = 0; i<16; i++)
SomeRandomBloke 13:5369ba22389a 121 nwkKey.push_back((uint8_t) *it++);
SomeRandomBloke 1:45cec6aea002 122
SomeRandomBloke 9:086351e54b57 123 logInfo("Resetting Config");
SomeRandomBloke 9:086351e54b57 124 // reset to default config so we know what state we're in
SomeRandomBloke 9:086351e54b57 125 dot->resetConfig();
SomeRandomBloke 1:45cec6aea002 126
SomeRandomBloke 5:48eb9245a914 127 // Set Spreading Factor, higher is lower data rate, smaller packets but longer range
SomeRandomBloke 5:48eb9245a914 128 // Lower is higher data rate, larger packets and shorter range.
SomeRandomBloke 5:48eb9245a914 129 logInfo("Set SF");
SomeRandomBloke 8:8070e9d660e4 130 if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 131 logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 132 }
SomeRandomBloke 5:48eb9245a914 133
SomeRandomBloke 5:48eb9245a914 134 logInfo("Set TxPower");
SomeRandomBloke 8:8070e9d660e4 135 if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 136 logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 137 }
SomeRandomBloke 5:48eb9245a914 138
SomeRandomBloke 7:2a704d1a30e1 139 logInfo("Set Public mode");
SomeRandomBloke 7:2a704d1a30e1 140 if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
SomeRandomBloke 7:2a704d1a30e1 141 logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 7:2a704d1a30e1 142 }
SomeRandomBloke 7:2a704d1a30e1 143
SomeRandomBloke 13:5369ba22389a 144 logInfo("Set AUTO_OTA Join mode");
SomeRandomBloke 13:5369ba22389a 145 if((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
SomeRandomBloke 13:5369ba22389a 146 logError("Failed to set AUTO_OTA Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 7:2a704d1a30e1 147 }
SomeRandomBloke 7:2a704d1a30e1 148
SomeRandomBloke 5:48eb9245a914 149 logInfo("Set Ack");
SomeRandomBloke 5:48eb9245a914 150 // 1 retries on Ack, 0 to disable
SomeRandomBloke 8:8070e9d660e4 151 if((ret = dot->setAck( LORA_ACK)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 152 logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 153 }
SomeRandomBloke 3:367aa95f9771 154
SomeRandomBloke 13:5369ba22389a 155 // Library ignores the frequency sub band for 868MHz in EU
SomeRandomBloke 13:5369ba22389a 156 if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
SomeRandomBloke 13:5369ba22389a 157 logError("Failed to set frequency sub band %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 7:2a704d1a30e1 158 }
SomeRandomBloke 7:2a704d1a30e1 159
SomeRandomBloke 13:5369ba22389a 160 logInfo("Set Network Id");
SomeRandomBloke 13:5369ba22389a 161 if ((ret = dot->setNetworkId(nwkId)) != mDot::MDOT_OK) {
SomeRandomBloke 13:5369ba22389a 162 logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 163 }
SomeRandomBloke 13:5369ba22389a 164 logInfo("Set Network Key");
SomeRandomBloke 13:5369ba22389a 165 if ((ret = dot->setNetworkKey(nwkKey)) != mDot::MDOT_OK) {
SomeRandomBloke 13:5369ba22389a 166 logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 167 }
SomeRandomBloke 5:48eb9245a914 168
SomeRandomBloke 5:48eb9245a914 169 logInfo("Saving Config");
SomeRandomBloke 5:48eb9245a914 170 // Save config
SomeRandomBloke 5:48eb9245a914 171 if (! dot->saveConfig()) {
SomeRandomBloke 5:48eb9245a914 172 logError("failed to save configuration");
SomeRandomBloke 0:5a0b43f3b143 173 }
SomeRandomBloke 5:48eb9245a914 174
SomeRandomBloke 13:5369ba22389a 175 pc.printf("Device ID {");
SomeRandomBloke 6:0a7760eeaba9 176 std::vector<uint8_t> deviceId;
SomeRandomBloke 6:0a7760eeaba9 177 deviceId = dot->getDeviceId();
SomeRandomBloke 13:5369ba22389a 178 for (std::vector<uint8_t>::iterator it = deviceId.begin() ; it != deviceId.end(); ++it) {
SomeRandomBloke 13:5369ba22389a 179 pc.printf("0x%2.2X",*it );
SomeRandomBloke 13:5369ba22389a 180 pc.printf("%s", it != (deviceId.end() -1 ) ? ", " : " " );
SomeRandomBloke 13:5369ba22389a 181 }
SomeRandomBloke 13:5369ba22389a 182 pc.printf("}\r\n");
SomeRandomBloke 9:086351e54b57 183
SomeRandomBloke 13:5369ba22389a 184 std::vector<uint8_t> netId;
SomeRandomBloke 13:5369ba22389a 185 pc.printf("Network Id/App EUI {");
SomeRandomBloke 13:5369ba22389a 186 netId = dot->getNetworkId();
SomeRandomBloke 13:5369ba22389a 187 for (std::vector<uint8_t>::iterator it = netId.begin() ; it != netId.end(); ++it) {
SomeRandomBloke 13:5369ba22389a 188 pc.printf("0x%2.2X", *it );
SomeRandomBloke 13:5369ba22389a 189 pc.printf("%s", it != (netId.end() -1 ) ? ", " : " " );
SomeRandomBloke 13:5369ba22389a 190 }
SomeRandomBloke 13:5369ba22389a 191 pc.printf("}\r\n");
SomeRandomBloke 5:48eb9245a914 192
SomeRandomBloke 13:5369ba22389a 193 std::vector<uint8_t> netKey;
SomeRandomBloke 13:5369ba22389a 194 pc.printf("Network Key/App Key {");
SomeRandomBloke 13:5369ba22389a 195 netKey = dot->getNetworkKey();
SomeRandomBloke 13:5369ba22389a 196 for (std::vector<uint8_t>::iterator it = netKey.begin() ; it != netKey.end(); ++it) {
SomeRandomBloke 13:5369ba22389a 197 pc.printf("0x%2.2X", *it );
SomeRandomBloke 13:5369ba22389a 198 pc.printf("%s", it != (netKey.end() -1 ) ? ", " : " " );
SomeRandomBloke 13:5369ba22389a 199 }
SomeRandomBloke 13:5369ba22389a 200 pc.printf("}\r\n");
SomeRandomBloke 5:48eb9245a914 201
SomeRandomBloke 5:48eb9245a914 202 // Display LoRa parameters
SomeRandomBloke 5:48eb9245a914 203 // Display label and values in different colours, show pretty values not numeric values where applicable
SomeRandomBloke 13:5369ba22389a 204 /*
SomeRandomBloke 5:48eb9245a914 205 pc.printf("Public Network: %s\r\n", (char*)(dot->getPublicNetwork() ? "Yes" : "No") );
SomeRandomBloke 5:48eb9245a914 206 pc.printf("Frequency: %s\r\n", (char*)mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str() );
SomeRandomBloke 5:48eb9245a914 207 pc.printf("Sub Band: %s\r\n", (char*)mDot::FrequencySubBandStr(dot->getFrequencySubBand()).c_str() );
SomeRandomBloke 5:48eb9245a914 208 pc.printf("Join Mode: %s\r\n", (char*)mDot::JoinModeStr(dot->getJoinMode()).c_str() );
SomeRandomBloke 6:0a7760eeaba9 209 pc.printf("Join Retries: %d\r\n", dot->getJoinRetries() );
SomeRandomBloke 6:0a7760eeaba9 210 pc.printf("Join Byte Order: %s\r\n", (char*)(dot->getJoinByteOrder() == 0 ? "LSB" : "MSB") );
SomeRandomBloke 5:48eb9245a914 211 pc.printf("Link Check Count: %d\r\n", dot->getLinkCheckCount() );
SomeRandomBloke 7:2a704d1a30e1 212 pc.printf("Link Check Thold: %d\r\n", dot->getLinkCheckThreshold() );
SomeRandomBloke 5:48eb9245a914 213 pc.printf("Tx Data Rate: %s\r\n", (char*)mDot::DataRateStr(dot->getTxDataRate()).c_str() );
SomeRandomBloke 5:48eb9245a914 214 pc.printf("Tx Power: %d\r\n", dot->getTxPower() );
SomeRandomBloke 6:0a7760eeaba9 215 pc.printf("TxWait: %s, ", (dot->getTxWait() ? "Y" : "N" ));
SomeRandomBloke 5:48eb9245a914 216 pc.printf("CRC: %s, ", (dot->getCrc() ? "Y" : "N") );
SomeRandomBloke 5:48eb9245a914 217 pc.printf("Ack: %s\r\n", (dot->getAck() ? "Y" : "N") );
SomeRandomBloke 13:5369ba22389a 218 */
SomeRandomBloke 9:086351e54b57 219 logInfo("Joining Network");
SomeRandomBloke 6:0a7760eeaba9 220
SomeRandomBloke 9:086351e54b57 221 while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
SomeRandomBloke 9:086351e54b57 222 logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 9:086351e54b57 223 wait_ms(dot->getNextTxMs() + 1);
SomeRandomBloke 9:086351e54b57 224 }
SomeRandomBloke 6:0a7760eeaba9 225
SomeRandomBloke 9:086351e54b57 226 logInfo("Joined Network");
SomeRandomBloke 6:0a7760eeaba9 227
SomeRandomBloke 13:5369ba22389a 228 // Display Network session key and data session key from Join command
SomeRandomBloke 13:5369ba22389a 229 /*
SomeRandomBloke 13:5369ba22389a 230 std::vector<uint8_t> tmp = dot->getNetworkSessionKey();
SomeRandomBloke 13:5369ba22389a 231 pc.printf("Network Session Key: ");
SomeRandomBloke 13:5369ba22389a 232 pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str());
SomeRandomBloke 13:5369ba22389a 233
SomeRandomBloke 13:5369ba22389a 234 tmp = dot->getDataSessionKey();
SomeRandomBloke 13:5369ba22389a 235 pc.printf("Data Session Key: ");
SomeRandomBloke 13:5369ba22389a 236 pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str());
SomeRandomBloke 13:5369ba22389a 237 */
SomeRandomBloke 9:086351e54b57 238 // Set the Temperature sesnor resolution, 9 bits is enough and makes it faster to provide a reading.
SomeRandomBloke 0:5a0b43f3b143 239 probe.setResolution(9);
SomeRandomBloke 0:5a0b43f3b143 240
SomeRandomBloke 0:5a0b43f3b143 241 char dataBuf[50];
SomeRandomBloke 0:5a0b43f3b143 242 while( 1 ) {
ScheepersJ 16:4aa655bf72ba 243
ScheepersJ 16:4aa655bf72ba 244 float analog1; //Analog 1 in for Soil Moisture No.1
ScheepersJ 16:4aa655bf72ba 245 analog1 = A1.read() * 3.3;
ScheepersJ 16:4aa655bf72ba 246
ScheepersJ 16:4aa655bf72ba 247 float analog2; //Analog 2 in for Soil Moisture No.2
ScheepersJ 16:4aa655bf72ba 248 analog2 = A2.read() * 3.3;
SomeRandomBloke 13:5369ba22389a 249
SomeRandomBloke 13:5369ba22389a 250 //Start temperature conversion, wait until ready
SomeRandomBloke 9:086351e54b57 251 probe.convertTemperature(true, DS1820::all_devices);
SomeRandomBloke 13:5369ba22389a 252 // Output data as JSON e.g. {"t":21.3}
SomeRandomBloke 0:5a0b43f3b143 253 temperature = probe.temperature();
ScheepersJ 16:4aa655bf72ba 254
ScheepersJ 16:4aa655bf72ba 255 //sprintf(dataBuf, "%3.1f", temperature );
ScheepersJ 16:4aa655bf72ba 256 sprintf(dataBuf, "%3.1f,%3.1f,%04.2f", temperature , analog1 , analog2 );
SomeRandomBloke 13:5369ba22389a 257 pc.printf("%s\n",dataBuf);
SomeRandomBloke 13:5369ba22389a 258 send_data.clear();
SomeRandomBloke 13:5369ba22389a 259 // probably not the most efficent way to do this
SomeRandomBloke 13:5369ba22389a 260 for( int i=0; i< strlen(dataBuf); i++ )
SomeRandomBloke 13:5369ba22389a 261 send_data.push_back( dataBuf[i] );
SomeRandomBloke 0:5a0b43f3b143 262
SomeRandomBloke 13:5369ba22389a 263 if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
SomeRandomBloke 13:5369ba22389a 264 logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 13:5369ba22389a 265 } else {
SomeRandomBloke 13:5369ba22389a 266 logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
SomeRandomBloke 13:5369ba22389a 267 }
SomeRandomBloke 0:5a0b43f3b143 268
SomeRandomBloke 13:5369ba22389a 269 // Should sleep here and wakeup after a set 5 minute interval.
SomeRandomBloke 13:5369ba22389a 270 // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
ScheepersJ 16:4aa655bf72ba 271 uint32_t sleep_time = std::max((uint32_t)600000, (uint32_t)dot->getNextTxMs()) / 1000;
ScheepersJ 16:4aa655bf72ba 272
SomeRandomBloke 13:5369ba22389a 273 // go to sleep and wake up automatically sleep_time seconds later
SomeRandomBloke 13:5369ba22389a 274 dot->sleep(sleep_time, mDot::RTC_ALARM);
SomeRandomBloke 0:5a0b43f3b143 275 }
SomeRandomBloke 2:9db840d12557 276
SomeRandomBloke 0:5a0b43f3b143 277 }