Demo of DHT11->mDot->TTN

Dependencies:   DHT11 libmDot mbed-rtos mbed

Committer:
SomeRandomBloke
Date:
Tue Oct 20 14:48:11 2015 +0000
Revision:
5:48eb9245a914
Parent:
4:f649ab1b61d1
Child:
6:0a7760eeaba9
First checkin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 5:48eb9245a914 1 /** mDot_TTN_DS18B20 - Simple mDot temperature sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor.
SomeRandomBloke 4:f649ab1b61d1 2 * It used the OTA_AUTO join mode using saved parameters. If the config is to be reset then pin A2 on the
SomeRandomBloke 3:367aa95f9771 3 * dev board must be held low during a reset or power up.
SomeRandomBloke 2:9db840d12557 4 *
SomeRandomBloke 0:5a0b43f3b143 5 * Uses MultiTech mDot developer board http://www.multitech.com/models/94558010LF
SomeRandomBloke 0:5a0b43f3b143 6 * Requires a MultiTech MultiConnect Conduit http://www.multitech.com/models/94557203LF
SomeRandomBloke 5:48eb9245a914 7 * http://www.multitech.net/developer/software/lora/conduit-mlinux-convert-to-basic-packet-forwarder/
SomeRandomBloke 5:48eb9245a914 8 * http://forum.thethingsnetwork.org/t/setting-up-multitech-conduit-gateway-for-ttn/216/35
SomeRandomBloke 0:5a0b43f3b143 9 *
SomeRandomBloke 0:5a0b43f3b143 10 */
SomeRandomBloke 0:5a0b43f3b143 11
SomeRandomBloke 0:5a0b43f3b143 12 #include "mbed.h"
SomeRandomBloke 0:5a0b43f3b143 13 #include "DS1820.h"
SomeRandomBloke 0:5a0b43f3b143 14 #include "mDot.h"
SomeRandomBloke 0:5a0b43f3b143 15 #include "MTSLog.h"
SomeRandomBloke 0:5a0b43f3b143 16 #include "MTSText.h"
SomeRandomBloke 0:5a0b43f3b143 17 #include <string>
SomeRandomBloke 0:5a0b43f3b143 18 #include <vector>
SomeRandomBloke 0:5a0b43f3b143 19
SomeRandomBloke 0:5a0b43f3b143 20 using namespace mts;
SomeRandomBloke 0:5a0b43f3b143 21
SomeRandomBloke 4:f649ab1b61d1 22 #define MIN(a,b) (((a)<(b))?(a):(b))
SomeRandomBloke 4:f649ab1b61d1 23 #define MAX(a,b) (((a)>(b))?(a):(b))
SomeRandomBloke 4:f649ab1b61d1 24
SomeRandomBloke 0:5a0b43f3b143 25 // these options must match the settings on your Conduit in
SomeRandomBloke 0:5a0b43f3b143 26 // /var/config/lora/lora-network-server.conf
SomeRandomBloke 5:48eb9245a914 27 //static std::string config_network_name = "ThingInnovations";
SomeRandomBloke 5:48eb9245a914 28 //static std::string config_network_pass = "donkey123";
SomeRandomBloke 5:48eb9245a914 29 //
SomeRandomBloke 5:48eb9245a914 30 //const uint8_t AppKey[16]={0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
SomeRandomBloke 5:48eb9245a914 31 // Application session key
SomeRandomBloke 5:48eb9245a914 32 uint8_t AppSKey[16]= {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
SomeRandomBloke 5:48eb9245a914 33 // Network session key
SomeRandomBloke 5:48eb9245a914 34 uint8_t NwkSKey[16]= {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
SomeRandomBloke 5:48eb9245a914 35 // Dev addr
SomeRandomBloke 5:48eb9245a914 36 uint8_t NodeAddr[4]= {0x23,0x05,0x19,0x67};
SomeRandomBloke 5:48eb9245a914 37
SomeRandomBloke 3:367aa95f9771 38 // Ignoring sub band for EU modules.
SomeRandomBloke 1:45cec6aea002 39 //static uint8_t config_frequency_sub_band = 1;
SomeRandomBloke 0:5a0b43f3b143 40
SomeRandomBloke 0:5a0b43f3b143 41 // mDot/dev board activity LED
SomeRandomBloke 1:45cec6aea002 42 //#define ACTIVITY_LED PA_0
SomeRandomBloke 2:9db840d12557 43
SomeRandomBloke 2:9db840d12557 44 // DS18B20 OneWire pin
SomeRandomBloke 3:367aa95f9771 45 // D13 on Dev Board, pin 18 on mDot
SomeRandomBloke 1:45cec6aea002 46 #define DATA_PIN PA_5
SomeRandomBloke 3:367aa95f9771 47 // A0 on Dev Board, pin 20 on mDot
SomeRandomBloke 1:45cec6aea002 48 //#define DATA_PIN PB_1
SomeRandomBloke 0:5a0b43f3b143 49
SomeRandomBloke 3:367aa95f9771 50 // A2 - input to reset LoRaWAN config. Pin 15 om mDot.
SomeRandomBloke 3:367aa95f9771 51 #define CONFIG_RESET PC_1
SomeRandomBloke 3:367aa95f9771 52
SomeRandomBloke 3:367aa95f9771 53 // Config Reset intput
SomeRandomBloke 3:367aa95f9771 54 DigitalIn configReset(CONFIG_RESET);
SomeRandomBloke 3:367aa95f9771 55
SomeRandomBloke 3:367aa95f9771 56 // Temperature sensor object
SomeRandomBloke 0:5a0b43f3b143 57 DS1820 probe(DATA_PIN);
SomeRandomBloke 0:5a0b43f3b143 58
SomeRandomBloke 3:367aa95f9771 59 // Serial via USB for debugging only
SomeRandomBloke 0:5a0b43f3b143 60 Serial pc(USBTX,USBRX);
SomeRandomBloke 0:5a0b43f3b143 61
SomeRandomBloke 0:5a0b43f3b143 62
SomeRandomBloke 0:5a0b43f3b143 63 int main()
SomeRandomBloke 0:5a0b43f3b143 64 {
SomeRandomBloke 0:5a0b43f3b143 65 int32_t ret;
SomeRandomBloke 0:5a0b43f3b143 66 mDot* dot;
SomeRandomBloke 0:5a0b43f3b143 67 std::vector<uint8_t> send_data;
SomeRandomBloke 0:5a0b43f3b143 68 std::vector<uint8_t> recv_data;
SomeRandomBloke 5:48eb9245a914 69 std::vector<uint8_t> nwkSKey;
SomeRandomBloke 5:48eb9245a914 70 std::vector<uint8_t> nodeAddr;
SomeRandomBloke 0:5a0b43f3b143 71
SomeRandomBloke 0:5a0b43f3b143 72 float temperature = 0.0;
SomeRandomBloke 1:45cec6aea002 73
SomeRandomBloke 3:367aa95f9771 74 // Enable internal pullup on input pin
SomeRandomBloke 3:367aa95f9771 75 configReset.mode(PullUp);
SomeRandomBloke 3:367aa95f9771 76
SomeRandomBloke 0:5a0b43f3b143 77 pc.baud(115200);
SomeRandomBloke 5:48eb9245a914 78 pc.printf("TTN mDot LoRa Temperature sensor\n\r");
SomeRandomBloke 1:45cec6aea002 79
SomeRandomBloke 0:5a0b43f3b143 80 // get a mDot handle
SomeRandomBloke 0:5a0b43f3b143 81 dot = mDot::getInstance();
SomeRandomBloke 0:5a0b43f3b143 82
SomeRandomBloke 4:f649ab1b61d1 83 // dot->setLogLevel(MTSLog::WARNING_LEVEL);
SomeRandomBloke 4:f649ab1b61d1 84 dot->setLogLevel(MTSLog::TRACE_LEVEL);
SomeRandomBloke 0:5a0b43f3b143 85
SomeRandomBloke 1:45cec6aea002 86 logInfo("Checking Config");
SomeRandomBloke 1:45cec6aea002 87
SomeRandomBloke 1:45cec6aea002 88 // Test if we've already saved the config
SomeRandomBloke 1:45cec6aea002 89 std::string configNetworkName = dot->getNetworkName();
SomeRandomBloke 5:48eb9245a914 90 // config_network_name = std::string(NwkSKey,16);
SomeRandomBloke 5:48eb9245a914 91 // config_network_pass = std::string(NwkSKey,16);
SomeRandomBloke 5:48eb9245a914 92
SomeRandomBloke 5:48eb9245a914 93 // pc.printf("Name: %s\r\n",config_network_name.c_str());
SomeRandomBloke 5:48eb9245a914 94 uint8_t *it = NwkSKey;
SomeRandomBloke 5:48eb9245a914 95 for (uint8_t i = 0; i<16; i++)
SomeRandomBloke 5:48eb9245a914 96 nwkSKey.push_back((uint8_t) *it++);
SomeRandomBloke 5:48eb9245a914 97
SomeRandomBloke 5:48eb9245a914 98 it = NodeAddr;
SomeRandomBloke 5:48eb9245a914 99 for (uint8_t i = 0; i<4; i++)
SomeRandomBloke 5:48eb9245a914 100 nodeAddr.push_back((uint8_t) *it++);
SomeRandomBloke 1:45cec6aea002 101
SomeRandomBloke 3:367aa95f9771 102 // Reset config if network name is different or pin is low then reset config.
SomeRandomBloke 5:48eb9245a914 103 // if( config_network_name.compare(configNetworkName) != 0 || !configReset ) {
SomeRandomBloke 5:48eb9245a914 104 if( !configReset ) {
SomeRandomBloke 5:48eb9245a914 105 // Config Reset link present
SomeRandomBloke 5:48eb9245a914 106 logInfo("Resetting Config");
SomeRandomBloke 1:45cec6aea002 107 // reset to default config so we know what state we're in
SomeRandomBloke 1:45cec6aea002 108 dot->resetConfig();
SomeRandomBloke 5:48eb9245a914 109 }
SomeRandomBloke 1:45cec6aea002 110
SomeRandomBloke 5:48eb9245a914 111 // Set byte order - AEP less than 1.0.30
SomeRandomBloke 1:45cec6aea002 112 // dot->setJoinByteOrder(mDot::MSB);
SomeRandomBloke 5:48eb9245a914 113 dot->setJoinByteOrder(mDot::LSB);
SomeRandomBloke 0:5a0b43f3b143 114
SomeRandomBloke 5:48eb9245a914 115 logInfo("Set Public mode");
SomeRandomBloke 5:48eb9245a914 116 if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 117 logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 118 }
SomeRandomBloke 1:45cec6aea002 119
SomeRandomBloke 5:48eb9245a914 120 logInfo("Set MANUAL Join mode");
SomeRandomBloke 5:48eb9245a914 121 // if ((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 122 if((ret = dot->setJoinMode(mDot::MANUAL)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 123 logError("Failed to set MANUAL Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 124 }
SomeRandomBloke 5:48eb9245a914 125
SomeRandomBloke 5:48eb9245a914 126 // If on developer board then you can enable activity LED
SomeRandomBloke 5:48eb9245a914 127 // Currently no spare pins that LEDs are connected too.
SomeRandomBloke 0:5a0b43f3b143 128 // dot->setActivityLedPin( ACTIVITY_LED );
SomeRandomBloke 0:5a0b43f3b143 129 // dot->setActivityLedEnable(false);
SomeRandomBloke 0:5a0b43f3b143 130
SomeRandomBloke 5:48eb9245a914 131 // Have a decent nubmer of retries in connecting to LoRaWAN
SomeRandomBloke 5:48eb9245a914 132 logInfo("Set Join retries");
SomeRandomBloke 5:48eb9245a914 133 if((ret = dot->setJoinRetries( 3 )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 134 logError("Failed to set Join retries %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 135 }
SomeRandomBloke 2:9db840d12557 136
SomeRandomBloke 5:48eb9245a914 137 // Set Spreading Factor, higher is lower data rate, smaller packets but longer range
SomeRandomBloke 5:48eb9245a914 138 // Lower is higher data rate, larger packets and shorter range.
SomeRandomBloke 5:48eb9245a914 139 logInfo("Set SF");
SomeRandomBloke 5:48eb9245a914 140 // if((ret = dot->setTxDataRate( mDot::SF_9 )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 141 if((ret = dot->setTxDataRate( mDot::SF_12 )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 142 logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 143 }
SomeRandomBloke 5:48eb9245a914 144
SomeRandomBloke 5:48eb9245a914 145 logInfo("Set TxPower");
SomeRandomBloke 5:48eb9245a914 146 if((ret = dot->setTxPower( 14 )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 147 logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 148 }
SomeRandomBloke 5:48eb9245a914 149
SomeRandomBloke 5:48eb9245a914 150 logInfo("Set Ack");
SomeRandomBloke 5:48eb9245a914 151 // 1 retries on Ack, 0 to disable
SomeRandomBloke 5:48eb9245a914 152 if((ret = dot->setAck( 1 )) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 153 logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 154 }
SomeRandomBloke 3:367aa95f9771 155
SomeRandomBloke 1:45cec6aea002 156 // Not applicable for 868MHz in EU
SomeRandomBloke 1:45cec6aea002 157 // if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
SomeRandomBloke 1:45cec6aea002 158 // initStatus = false;
SomeRandomBloke 0:5a0b43f3b143 159 // logError(dot, "failed to set frequency sub band", ret);
SomeRandomBloke 1:45cec6aea002 160 // }
SomeRandomBloke 1:45cec6aea002 161
SomeRandomBloke 5:48eb9245a914 162 logInfo("Set Network Key");
SomeRandomBloke 5:48eb9245a914 163 if ((ret = dot->setNetworkKey(nwkSKey)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 164 logError("Failed to set Network Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 165 }
SomeRandomBloke 0:5a0b43f3b143 166
SomeRandomBloke 5:48eb9245a914 167 logInfo("Set Network Session Key");
SomeRandomBloke 5:48eb9245a914 168 if ((ret = dot->setNetworkSessionKey(nwkSKey)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 169 logError("Failed to set Network Session Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 170 }
SomeRandomBloke 5:48eb9245a914 171
SomeRandomBloke 5:48eb9245a914 172 logInfo("Set Data Session Key");
SomeRandomBloke 5:48eb9245a914 173 if ((ret = dot->setDataSessionKey(nwkSKey)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 174 logError("Failed to set Data Session Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 175 }
SomeRandomBloke 5:48eb9245a914 176
SomeRandomBloke 5:48eb9245a914 177 // if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 178 // logError("failed to set network name %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 179 // }
SomeRandomBloke 1:45cec6aea002 180
SomeRandomBloke 5:48eb9245a914 181 // if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
SomeRandomBloke 5:48eb9245a914 182 // logError("failed to set network password %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 5:48eb9245a914 183 // }
SomeRandomBloke 1:45cec6aea002 184
SomeRandomBloke 5:48eb9245a914 185 logInfo("Saving Config");
SomeRandomBloke 5:48eb9245a914 186 // Save config
SomeRandomBloke 5:48eb9245a914 187 if (! dot->saveConfig()) {
SomeRandomBloke 5:48eb9245a914 188 logError("failed to save configuration");
SomeRandomBloke 0:5a0b43f3b143 189 }
SomeRandomBloke 5:48eb9245a914 190 // } else {
SomeRandomBloke 5:48eb9245a914 191 // logInfo("Using existing Config");
SomeRandomBloke 5:48eb9245a914 192 // }
SomeRandomBloke 5:48eb9245a914 193
SomeRandomBloke 5:48eb9245a914 194 // Display what is set
SomeRandomBloke 5:48eb9245a914 195 std::vector<uint8_t> tmp = dot->getNetworkSessionKey();
SomeRandomBloke 5:48eb9245a914 196 pc.printf("Network Session Key: ");
SomeRandomBloke 5:48eb9245a914 197 pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str());
SomeRandomBloke 5:48eb9245a914 198
SomeRandomBloke 5:48eb9245a914 199 tmp = dot->getDataSessionKey();
SomeRandomBloke 5:48eb9245a914 200 pc.printf("Data Session Key: ");
SomeRandomBloke 5:48eb9245a914 201 pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str());
SomeRandomBloke 0:5a0b43f3b143 202
SomeRandomBloke 4:f649ab1b61d1 203 logInfo("Joining Network");
SomeRandomBloke 4:f649ab1b61d1 204
SomeRandomBloke 0:5a0b43f3b143 205 while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
SomeRandomBloke 0:5a0b43f3b143 206 logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 0:5a0b43f3b143 207 wait_ms(dot->getNextTxMs() + 1);
SomeRandomBloke 0:5a0b43f3b143 208 }
SomeRandomBloke 1:45cec6aea002 209
SomeRandomBloke 4:f649ab1b61d1 210 logInfo("Joined Network");
SomeRandomBloke 4:f649ab1b61d1 211
SomeRandomBloke 5:48eb9245a914 212
SomeRandomBloke 5:48eb9245a914 213 pc.printf("Net ID ");
SomeRandomBloke 5:48eb9245a914 214 std::vector<uint8_t> nodeAddress;
SomeRandomBloke 5:48eb9245a914 215 nodeAddress = dot->getNetworkId();
SomeRandomBloke 5:48eb9245a914 216 for (std::vector<uint8_t>::iterator it = nodeAddress.begin() ; it != nodeAddress.end(); ++it)
SomeRandomBloke 5:48eb9245a914 217 pc.printf("%2.2x",*it );
SomeRandomBloke 5:48eb9245a914 218
SomeRandomBloke 5:48eb9245a914 219 pc.printf("\r\n");
SomeRandomBloke 5:48eb9245a914 220 pc.printf("Node ID ");
SomeRandomBloke 5:48eb9245a914 221 nodeAddress = dot->getNetworkAddress();
SomeRandomBloke 5:48eb9245a914 222 for (std::vector<uint8_t>::iterator it = nodeAddress.begin() ; it != nodeAddress.end(); ++it)
SomeRandomBloke 5:48eb9245a914 223 pc.printf("%2.2x",*it );
SomeRandomBloke 5:48eb9245a914 224
SomeRandomBloke 5:48eb9245a914 225 pc.printf("\r\n");
SomeRandomBloke 5:48eb9245a914 226
SomeRandomBloke 5:48eb9245a914 227 // Display LoRa parameters
SomeRandomBloke 5:48eb9245a914 228 // Display label and values in different colours, show pretty values not numeric values where applicable
SomeRandomBloke 5:48eb9245a914 229 pc.printf("Public Network: %s\r\n", (char*)(dot->getPublicNetwork() ? "Yes" : "No") );
SomeRandomBloke 5:48eb9245a914 230 pc.printf("Frequency: %s\r\n", (char*)mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str() );
SomeRandomBloke 5:48eb9245a914 231 pc.printf("Sub Band: %s\r\n", (char*)mDot::FrequencySubBandStr(dot->getFrequencySubBand()).c_str() );
SomeRandomBloke 5:48eb9245a914 232 pc.printf("Join Mode: %s\r\n", (char*)mDot::JoinModeStr(dot->getJoinMode()).c_str() );
SomeRandomBloke 5:48eb9245a914 233 pc.printf("Join Retries: %d\r\n", (char*)(dot->getJoinByteOrder() == 0 ? "LSB" : "MSB") );
SomeRandomBloke 5:48eb9245a914 234 pc.printf("Link Check Count: %d\r\n", dot->getLinkCheckCount() );
SomeRandomBloke 5:48eb9245a914 235 pc.printf("Link Check Thold: %s\r\n", dot->getLinkCheckThreshold() );
SomeRandomBloke 5:48eb9245a914 236 pc.printf("Tx Data Rate: %s\r\n", (char*)mDot::DataRateStr(dot->getTxDataRate()).c_str() );
SomeRandomBloke 5:48eb9245a914 237 pc.printf("Tx Power: %d\r\n", dot->getTxPower() );
SomeRandomBloke 5:48eb9245a914 238 pc.printf("TxWait: %s, ", (dot->getTxWait() ? "Y" : "N" );
SomeRandomBloke 5:48eb9245a914 239 pc.printf("CRC: %s, ", (dot->getCrc() ? "Y" : "N") );
SomeRandomBloke 5:48eb9245a914 240 pc.printf("Ack: %s\r\n", (dot->getAck() ? "Y" : "N") );
SomeRandomBloke 5:48eb9245a914 241
SomeRandomBloke 0:5a0b43f3b143 242 probe.setResolution(9);
SomeRandomBloke 0:5a0b43f3b143 243
SomeRandomBloke 0:5a0b43f3b143 244 char dataBuf[50];
SomeRandomBloke 0:5a0b43f3b143 245 while( 1 ) {
SomeRandomBloke 0:5a0b43f3b143 246 // This takes upto 750mS, way too long. Change to 9 bit resolution if not already used.
SomeRandomBloke 1:45cec6aea002 247
SomeRandomBloke 0:5a0b43f3b143 248 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
SomeRandomBloke 0:5a0b43f3b143 249 // printf("It is %3.1fC\r\n", probe.temperature());
SomeRandomBloke 3:367aa95f9771 250 // Output data as JSON e.g. {"tmp":21.3}
SomeRandomBloke 0:5a0b43f3b143 251 temperature = probe.temperature();
SomeRandomBloke 1:45cec6aea002 252 sprintf(dataBuf, "{\"tmp\":%3.1f}", temperature );
SomeRandomBloke 0:5a0b43f3b143 253 send_data.clear();
SomeRandomBloke 0:5a0b43f3b143 254 // probably not the most efficent way to do this
SomeRandomBloke 0:5a0b43f3b143 255 for( int i=0; i< strlen(dataBuf); i++ )
SomeRandomBloke 0:5a0b43f3b143 256 send_data.push_back( dataBuf[i] );
SomeRandomBloke 0:5a0b43f3b143 257
SomeRandomBloke 0:5a0b43f3b143 258 if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
SomeRandomBloke 0:5a0b43f3b143 259 logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
SomeRandomBloke 0:5a0b43f3b143 260 } else {
SomeRandomBloke 0:5a0b43f3b143 261 logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
SomeRandomBloke 0:5a0b43f3b143 262 }
SomeRandomBloke 0:5a0b43f3b143 263
SomeRandomBloke 1:45cec6aea002 264 // Should sleep here and wakeup after a set interval.
SomeRandomBloke 4:f649ab1b61d1 265 uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), 60);
SomeRandomBloke 2:9db840d12557 266 logInfo("going to sleep for %d seconds", sleep_time);
SomeRandomBloke 0:5a0b43f3b143 267
SomeRandomBloke 1:45cec6aea002 268 // go to sleep and wake up automatically sleep_time seconds later
SomeRandomBloke 5:48eb9245a914 269 // dot->sleep(sleep_time, mDot::RTC_ALARM);
SomeRandomBloke 2:9db840d12557 270
SomeRandomBloke 5:48eb9245a914 271 wait_ms(sleep_time * 1000);
SomeRandomBloke 0:5a0b43f3b143 272 }
SomeRandomBloke 2:9db840d12557 273
SomeRandomBloke 0:5a0b43f3b143 274 return 0;
SomeRandomBloke 0:5a0b43f3b143 275 }