d

Dependencies:   BME280 DOGS102 DS1820 MMA845x_timmeh MTS-Serial libmDot_Australia915Mhz mbed-rtos mbed

Fork of mDot_TTN_OTAA_Node by Thing Innovations

Committer:
SomeRandomBloke
Date:
Wed May 11 06:18:15 2016 +0000
Revision:
13:5369ba22389a
Parent:
12:e82913ee9c61
Child:
15:8a0ebf59b8bb
testing DS18B20

Who changed what in which revision?

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