Demo of DHT11->mDot->TTN

Dependencies:   DHT22 DS18B20_1wire SHTx TSL2561_I2C libmDot mbed-rtos mbed

Fork of mDot_TTN_DHT11 by Chris Merck

Committer:
SomeRandomBloke
Date:
Tue Nov 10 21:46:38 2015 +0000
Revision:
8:8070e9d660e4
Parent:
7:2a704d1a30e1
Child:
9:086351e54b57
increased time interval to 10 mins

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