This reads a thermistor bead using mDot module
Dependencies: DHT GPS MTS-Serial mbed-rtos mbed
Fork of mDot_LoRa_Connect_Example by
main.cpp@5:11863539202f, 2016-06-10 (annotated)
- Committer:
- Mehrad
- Date:
- Fri Jun 10 00:21:48 2016 +0000
- Revision:
- 5:11863539202f
- Parent:
- 4:36e214ebfa56
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:09250cd371d2 | 1 | #include "mbed.h" |
mfiore | 0:09250cd371d2 | 2 | #include "mDot.h" |
mfiore | 4:36e214ebfa56 | 3 | #include "MTSLog.h" |
Mehrad | 5:11863539202f | 4 | #include "MTSSerial.h" |
mfiore | 0:09250cd371d2 | 5 | #include <string> |
mfiore | 0:09250cd371d2 | 6 | #include <vector> |
mfiore | 4:36e214ebfa56 | 7 | #include <algorithm> |
Mehrad | 5:11863539202f | 8 | #include <sstream> |
Mehrad | 5:11863539202f | 9 | #include <iomanip> |
Mehrad | 5:11863539202f | 10 | //#include "PulseCounter.h" |
mfiore | 0:09250cd371d2 | 11 | |
mfiore | 2:6e2c378339d9 | 12 | // these options must match the settings on your Conduit |
mfiore | 2:6e2c378339d9 | 13 | // uncomment the following lines and edit their values to match your configuration |
Mehrad | 5:11863539202f | 14 | static std::string config_network_name = "campbellsci"; |
Mehrad | 5:11863539202f | 15 | static std::string config_network_pass = "campbellsci"; |
Mehrad | 5:11863539202f | 16 | static uint8_t config_frequency_sub_band = 1; |
Mehrad | 5:11863539202f | 17 | |
Mehrad | 5:11863539202f | 18 | DigitalOut greenLed(PA_11); // To turn the join LED on/off |
Mehrad | 5:11863539202f | 19 | |
Mehrad | 5:11863539202f | 20 | std::string VectorInt8_To_StrHex (const vector<uint8_t>& v) |
Mehrad | 5:11863539202f | 21 | { |
Mehrad | 5:11863539202f | 22 | stringstream ss; |
Mehrad | 5:11863539202f | 23 | ss << std::hex << std::setfill('0'); |
Mehrad | 5:11863539202f | 24 | vector<uint8_t>::const_iterator it; |
Mehrad | 5:11863539202f | 25 | |
Mehrad | 5:11863539202f | 26 | for (it = v.begin(); it != v.end(); it++) { |
Mehrad | 5:11863539202f | 27 | ss << ":" << std::setw(2) << static_cast<unsigned>(*it); |
Mehrad | 5:11863539202f | 28 | } |
Mehrad | 5:11863539202f | 29 | return ss.str(); |
Mehrad | 5:11863539202f | 30 | } |
Mehrad | 5:11863539202f | 31 | |
Mehrad | 5:11863539202f | 32 | std::string VectorInt32_To_StrDec (const vector<uint32_t>& v) |
Mehrad | 5:11863539202f | 33 | { |
Mehrad | 5:11863539202f | 34 | // Serial output for debugging |
Mehrad | 5:11863539202f | 35 | //mts::MTSSerial serial(XBEE_DOUT, XBEE_DIN, 512, 512); |
Mehrad | 5:11863539202f | 36 | //serial.baud(115200); |
Mehrad | 5:11863539202f | 37 | //mts::MTSSerial& _serial(serial); |
Mehrad | 5:11863539202f | 38 | stringstream ss; |
Mehrad | 5:11863539202f | 39 | // Body |
Mehrad | 5:11863539202f | 40 | ss << std::dec << std::setfill('0'); |
Mehrad | 5:11863539202f | 41 | vector<uint32_t>::const_iterator it; |
mfiore | 0:09250cd371d2 | 42 | |
Mehrad | 5:11863539202f | 43 | for (it = v.begin(); it != v.end(); it++) { |
Mehrad | 5:11863539202f | 44 | ss << ":" << std::setw(3) << static_cast<unsigned>(*it); |
Mehrad | 5:11863539202f | 45 | //_serial.writef(static_cast<unsigned>(*it)); |
Mehrad | 5:11863539202f | 46 | } |
Mehrad | 5:11863539202f | 47 | return ss.str(); |
Mehrad | 5:11863539202f | 48 | } |
Mehrad | 5:11863539202f | 49 | |
Mehrad | 5:11863539202f | 50 | std::string VectorMdotFile_To_List (const vector<mDot::mdot_file>& v) |
Mehrad | 5:11863539202f | 51 | { |
Mehrad | 5:11863539202f | 52 | // Serial output for debugging |
Mehrad | 5:11863539202f | 53 | mts::MTSSerial serial(XBEE_DOUT, XBEE_DIN, 512, 512); |
Mehrad | 5:11863539202f | 54 | serial.baud(115200); |
Mehrad | 5:11863539202f | 55 | mts::MTSSerial& _serial(serial); |
Mehrad | 5:11863539202f | 56 | |
Mehrad | 5:11863539202f | 57 | stringstream ss; |
Mehrad | 5:11863539202f | 58 | vector<mDot::mdot_file>::const_iterator it; |
Mehrad | 5:11863539202f | 59 | |
Mehrad | 5:11863539202f | 60 | _serial.writef(" DEBUG: Vector size for user files list %d\r\n" , v.size()); |
Mehrad | 5:11863539202f | 61 | |
Mehrad | 5:11863539202f | 62 | for (it = v.begin(); it != v.end(); it++) { |
Mehrad | 5:11863539202f | 63 | ss << (*it).name << " " ; |
Mehrad | 5:11863539202f | 64 | } |
Mehrad | 5:11863539202f | 65 | return ss.str(); |
Mehrad | 5:11863539202f | 66 | } |
Mehrad | 5:11863539202f | 67 | |
Mehrad | 5:11863539202f | 68 | int main() |
Mehrad | 5:11863539202f | 69 | { |
Mehrad | 5:11863539202f | 70 | greenLed = 0; |
Mehrad | 5:11863539202f | 71 | AnalogIn in(PB_1); // Read Analog |
Mehrad | 5:11863539202f | 72 | |
mfiore | 0:09250cd371d2 | 73 | int32_t ret; |
mfiore | 0:09250cd371d2 | 74 | mDot* dot; |
mfiore | 0:09250cd371d2 | 75 | std::vector<uint8_t> data; |
Mehrad | 5:11863539202f | 76 | //std::string data_str = "hello!"; |
mfiore | 2:6e2c378339d9 | 77 | |
Mehrad | 5:11863539202f | 78 | std::ostringstream ss; |
Mehrad | 5:11863539202f | 79 | std::string data_str = "Hello"; |
Mehrad | 5:11863539202f | 80 | //ss << in.read_u16(); |
Mehrad | 5:11863539202f | 81 | //data_str = ss.str(); |
Mehrad | 5:11863539202f | 82 | |
mfiore | 0:09250cd371d2 | 83 | // get a mDot handle |
mfiore | 0:09250cd371d2 | 84 | dot = mDot::getInstance(); |
Mehrad | 5:11863539202f | 85 | |
Mehrad | 5:11863539202f | 86 | // This section is to enable the debuging info over serial (rs232) |
Mehrad | 5:11863539202f | 87 | mts::MTSSerial serial(XBEE_DOUT, XBEE_DIN, 512, 512); |
Mehrad | 5:11863539202f | 88 | serial.baud(115200); |
Mehrad | 5:11863539202f | 89 | mts::MTSSerial& _serial(serial); |
Mehrad | 5:11863539202f | 90 | // Hello world |
Mehrad | 5:11863539202f | 91 | _serial.writef("\r\n\r\n\r\n\r\n"); |
Mehrad | 5:11863539202f | 92 | _serial.writef("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n"); |
Mehrad | 5:11863539202f | 93 | _serial.writef("+ Hello mDot + \r\n"); |
Mehrad | 5:11863539202f | 94 | _serial.writef("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n"); |
Mehrad | 5:11863539202f | 95 | |
Mehrad | 5:11863539202f | 96 | |
Mehrad | 5:11863539202f | 97 | |
mfiore | 2:6e2c378339d9 | 98 | // print library version information |
Mehrad | 5:11863539202f | 99 | _serial.writef("INFO: version: %s\r\n", dot->getId().c_str()); |
mfiore | 0:09250cd371d2 | 100 | |
mfiore | 2:6e2c378339d9 | 101 | //******************************************* |
mfiore | 2:6e2c378339d9 | 102 | // configuration |
mfiore | 2:6e2c378339d9 | 103 | //******************************************* |
mfiore | 0:09250cd371d2 | 104 | // reset to default config so we know what state we're in |
mfiore | 0:09250cd371d2 | 105 | dot->resetConfig(); |
Mehrad | 5:11863539202f | 106 | |
mfiore | 4:36e214ebfa56 | 107 | dot->setLogLevel(mts::MTSLog::INFO_LEVEL); |
mfiore | 0:09250cd371d2 | 108 | |
mfiore | 2:6e2c378339d9 | 109 | // set up the mDot with our network information: frequency sub band, network name, and network password |
mfiore | 2:6e2c378339d9 | 110 | // these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig() |
Mehrad | 5:11863539202f | 111 | |
mfiore | 4:36e214ebfa56 | 112 | // frequency sub band is only applicable in the 915 (US) frequency band |
mfiore | 4:36e214ebfa56 | 113 | // if using a MultiTech Conduit gateway, use the same sub band as your Conduit (1-8) - the mDot will use the 8 channels in that sub band |
mfiore | 4:36e214ebfa56 | 114 | // if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels |
Mehrad | 5:11863539202f | 115 | _serial.writef("INFO: setting frequency sub band: %d\r\n", config_frequency_sub_band); |
mfiore | 0:09250cd371d2 | 116 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 117 | _serial.writef("ERROR: failed to set frequency sub band %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 118 | } |
Mehrad | 5:11863539202f | 119 | |
Mehrad | 5:11863539202f | 120 | /* Dont' need network name when setting it network EUI |
Mehrad | 5:11863539202f | 121 | _serial.writef("INFO: setting network name: %s\r\n", config_network_name.c_str()); |
Mehrad | 5:11863539202f | 122 | if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 123 | _serial.writef("ERROR: failed to set network name %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 124 | } |
Mehrad | 5:11863539202f | 125 | */ |
Mehrad | 5:11863539202f | 126 | // Initializing a vecotr in C++ |
Mehrad | 5:11863539202f | 127 | // This compiler doesn't accept -> static std::vector<uint8_t> config_network_key {00,00,00,00,00,00,00,01}; |
Mehrad | 5:11863539202f | 128 | static std::uint8_t netId[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}; |
Mehrad | 5:11863539202f | 129 | static std::vector<uint8_t> netIdV(&netId[0], &netId[0] + 8); // It is +8 since 8 members. You need start and end of the array. |
Mehrad | 5:11863539202f | 130 | _serial.writef("INFO: setting network ID (EUI): %s\r\n", VectorInt8_To_StrHex(netIdV)); |
Mehrad | 5:11863539202f | 131 | if ((ret = dot->setNetworkId(netIdV)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 132 | _serial.writef("ERROR: failed to set network ID %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 2:6e2c378339d9 | 133 | } |
Mehrad | 5:11863539202f | 134 | /* |
Mehrad | 5:11863539202f | 135 | _serial.writef("INFO: setting network password: %s\r\n", config_network_pass.c_str()); |
Mehrad | 5:11863539202f | 136 | if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 137 | _serial.writef("ERROR: failed to set network password %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 138 | } |
Mehrad | 5:11863539202f | 139 | */ |
Mehrad | 5:11863539202f | 140 | // Initializing a vecotr in C++ |
Mehrad | 5:11863539202f | 141 | static std::uint8_t netKey[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}; |
Mehrad | 5:11863539202f | 142 | static std::vector<uint8_t> netKeyV(&netKey[0], &netKey[0] + 16); // It is +16 since 16 members. You need start and end of the array. |
Mehrad | 5:11863539202f | 143 | _serial.writef("INFO: setting network key: %s\r\n", VectorInt8_To_StrHex(netKeyV)); |
Mehrad | 5:11863539202f | 144 | if ((ret = dot->setNetworkKey(netKeyV)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 145 | _serial.writef("ERROR: failed to set network key %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:09250cd371d2 | 146 | } |
Mehrad | 5:11863539202f | 147 | |
Mehrad | 5:11863539202f | 148 | bool adrStatus = false; |
Mehrad | 5:11863539202f | 149 | _serial.writef("ADR Status is %d\r\n", (*dot).getAdr()); |
Mehrad | 5:11863539202f | 150 | _serial.writef("INFO: setting Adr %d: \r\n", adrStatus); |
Mehrad | 5:11863539202f | 151 | if ((ret = dot->setAdr(adrStatus)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 152 | _serial.writef("ERROR: failed to set ADR %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 153 | } else { |
Mehrad | 5:11863539202f | 154 | _serial.writef("Data Rate: %d\r\n", (*dot).getTxDataRate()); |
Mehrad | 5:11863539202f | 155 | _serial.writef("ADR Status is %d\r\n", (*dot).getAdr()); |
Mehrad | 5:11863539202f | 156 | |
mfiore | 0:09250cd371d2 | 157 | } |
Mehrad | 5:11863539202f | 158 | |
Mehrad | 5:11863539202f | 159 | /* |
mfiore | 4:36e214ebfa56 | 160 | // a higher spreading factor allows for longer range but lower throughput |
mfiore | 4:36e214ebfa56 | 161 | // in the 915 (US) frequency band, spreading factors 7 - 10 are available |
mfiore | 4:36e214ebfa56 | 162 | // in the 868 (EU) frequency band, spreading factors 7 - 12 are available |
Mehrad | 5:11863539202f | 163 | _serial.writef("INFO: setting TX data rate: "); |
Mehrad | 5:11863539202f | 164 | if ((ret = dot->setTxDataRate(mDot::DR2)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 165 | _serial.writef("ERROR: failed to set TX datarate %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 166 | } else |
Mehrad | 5:11863539202f | 167 | _serial.writef("%d\r\n", (*dot).getTxDataRate()); |
Mehrad | 5:11863539202f | 168 | |
Mehrad | 5:11863539202f | 169 | */ |
Mehrad | 5:11863539202f | 170 | |
Mehrad | 5:11863539202f | 171 | |
mfiore | 4:36e214ebfa56 | 172 | // request receive confirmation of packets from the gateway |
Mehrad | 5:11863539202f | 173 | _serial.writef("INFO: enabling ACKs\r\n"); |
mfiore | 4:36e214ebfa56 | 174 | if ((ret = dot->setAck(1)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 175 | _serial.writef("ERROR: failed to enable ACKs %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 176 | } |
Mehrad | 5:11863539202f | 177 | |
Mehrad | 5:11863539202f | 178 | // Public Network Mode |
Mehrad | 5:11863539202f | 179 | _serial.writef("INFO: Public network state: %d\r\n", (*dot).getPublicNetwork()); |
Mehrad | 5:11863539202f | 180 | _serial.writef("INFO: enabling Public network mode\r\n"); |
Mehrad | 5:11863539202f | 181 | if ((ret = dot->setPublicNetwork(1)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 182 | _serial.writef("ERROR: failed to enable Public Mode %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 4:36e214ebfa56 | 183 | } |
Mehrad | 5:11863539202f | 184 | _serial.writef("INFO: Public network state: %d\r\n", (*dot).getPublicNetwork()); |
Mehrad | 5:11863539202f | 185 | |
Mehrad | 5:11863539202f | 186 | |
Mehrad | 5:11863539202f | 187 | _serial.writef("INFO: frequency band: %s\r\n", mDot::FrequencyBandStr((*dot).getFrequencyBand()).c_str()); |
Mehrad | 5:11863539202f | 188 | _serial.writef("INFO: frequency band: %d\r\n", (*dot).getFrequencyBand()); |
Mehrad | 5:11863539202f | 189 | |
Mehrad | 5:11863539202f | 190 | |
Mehrad | 5:11863539202f | 191 | const uint8_t _freqBand = 2; |
Mehrad | 5:11863539202f | 192 | _serial.writef("INFO: Setting frequency band to: %s\r\n", mDot::FrequencyBandStr(_freqBand).c_str()); |
Mehrad | 5:11863539202f | 193 | if ((ret = dot->setFrequencyBand(_freqBand)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 194 | _serial.writef("ERROR: failed to enable Public Mode %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 195 | } |
Mehrad | 5:11863539202f | 196 | |
Mehrad | 5:11863539202f | 197 | // Workaround to lock the TX frequencies to a single Aussie one while working with the incorrect library. |
Mehrad | 5:11863539202f | 198 | // The latest library has the fixed 8 Aussie libraries and it makes the following lines irrelevent. |
Mehrad | 5:11863539202f | 199 | //_serial.writef("INFO: Setting TX frequency to: %s\r\n", mDot::FrequencyBandStr(_freqBand).c_str()); |
Mehrad | 5:11863539202f | 200 | //if ((ret = dot->setTxFrequency(915200000)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 201 | // _serial.writef("ERROR: failed to Set TX frequency %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
Mehrad | 5:11863539202f | 202 | //} |
Mehrad | 5:11863539202f | 203 | //_serial.writef("INFO: TX frequency: %d\r\n", (*dot).getTxFrequency()); |
Mehrad | 5:11863539202f | 204 | |
Mehrad | 5:11863539202f | 205 | |
mfiore | 4:36e214ebfa56 | 206 | // save this configuration to the mDot's NVM |
Mehrad | 5:11863539202f | 207 | _serial.writef("INFO: saving config\r\n"); |
mfiore | 2:6e2c378339d9 | 208 | if (! dot->saveConfig()) { |
Mehrad | 5:11863539202f | 209 | _serial.writef("ERROR: failed to save configuration\r\n"); |
mfiore | 0:09250cd371d2 | 210 | } |
Mehrad | 5:11863539202f | 211 | |
mfiore | 2:6e2c378339d9 | 212 | //******************************************* |
mfiore | 2:6e2c378339d9 | 213 | // end of configuration |
mfiore | 2:6e2c378339d9 | 214 | //******************************************* |
mfiore | 0:09250cd371d2 | 215 | |
Mehrad | 5:11863539202f | 216 | _serial.writef("INFO: frequency band: %s\r\n", mDot::FrequencyBandStr((*dot).getFrequencyBand()).c_str()); |
Mehrad | 5:11863539202f | 217 | |
Mehrad | 5:11863539202f | 218 | _serial.writef("INFO: Device ID%s\r\n", VectorInt8_To_StrHex((*dot).getDeviceId()).c_str()); |
Mehrad | 5:11863539202f | 219 | |
Mehrad | 5:11863539202f | 220 | _serial.writef("INFO: Network ID%s\r\n", VectorInt8_To_StrHex((*dot).getNetworkId()).c_str()); |
Mehrad | 5:11863539202f | 221 | _serial.writef("INFO: Network Key%s\r\n", VectorInt8_To_StrHex((*dot).getNetworkKey()).c_str()); |
Mehrad | 5:11863539202f | 222 | |
Mehrad | 5:11863539202f | 223 | _serial.writef("INFO: Join mode: %s\r\n", mDot::JoinModeStr((*dot).getJoinMode()).c_str()); |
Mehrad | 5:11863539202f | 224 | |
Mehrad | 5:11863539202f | 225 | _serial.writef("INFO: List of channel frequencies currently in use%s\r\n", VectorInt32_To_StrDec((*dot).getChannels()).c_str()); |
Mehrad | 5:11863539202f | 226 | // TODO: These data rate lists don't make sense. |
Mehrad | 5:11863539202f | 227 | _serial.writef("INFO: List of channel datarate ranges currently in use%s\r\n", VectorInt8_To_StrHex((*dot).getChannelRanges()).c_str()); |
Mehrad | 5:11863539202f | 228 | //_serial.writef("INFO: List of channel frequencies in config file to be used as session defaults%s\r\n", VectorInt32_To_StrDec((*dot).getConfigChannels())); |
Mehrad | 5:11863539202f | 229 | //_serial.writef("INFO: List of channel frequencies currently in use%s\r\n", VectorInt32_To_StrDec((*dot).getChannels())); |
Mehrad | 5:11863539202f | 230 | |
Mehrad | 5:11863539202f | 231 | |
Mehrad | 5:11863539202f | 232 | |
Mehrad | 5:11863539202f | 233 | //_serial.writef("INFO: List user files stored in flash%s\r\n", VectorMdotFile_To_List((*dot).listUserFiles())); |
Mehrad | 5:11863539202f | 234 | |
Mehrad | 5:11863539202f | 235 | |
Mehrad | 5:11863539202f | 236 | //******************************************* |
Mehrad | 5:11863539202f | 237 | // end of debuging info |
Mehrad | 5:11863539202f | 238 | //******************************************* |
Mehrad | 5:11863539202f | 239 | |
Mehrad | 5:11863539202f | 240 | |
Mehrad | 5:11863539202f | 241 | // attempt to join the network |
Mehrad | 5:11863539202f | 242 | _serial.writef("INFO: joining network...\r\n"); |
Mehrad | 5:11863539202f | 243 | while ((ret = dot->joinNetworkOnce()) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 244 | _serial.writef("ERROR: failed to join network %d:%s\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 4:36e214ebfa56 | 245 | // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again |
mfiore | 4:36e214ebfa56 | 246 | osDelay(std::max((uint32_t)1000, (uint32_t)dot->getNextTxMs())); |
mfiore | 0:09250cd371d2 | 247 | } |
Mehrad | 5:11863539202f | 248 | greenLed = 1; // Joined Successfuly |
mfiore | 0:09250cd371d2 | 249 | |
Mehrad | 5:11863539202f | 250 | mDot::rssi_stats _rssiStats; |
Mehrad | 5:11863539202f | 251 | |
Mehrad | 5:11863539202f | 252 | int err; |
Mehrad | 5:11863539202f | 253 | while (true) { |
mfiore | 0:09250cd371d2 | 254 | |
Mehrad | 5:11863539202f | 255 | //format data for sending to the gateway |
Mehrad | 5:11863539202f | 256 | for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) { |
Mehrad | 5:11863539202f | 257 | data.push_back((uint8_t) *it); |
Mehrad | 5:11863539202f | 258 | } |
Mehrad | 5:11863539202f | 259 | |
mfiore | 4:36e214ebfa56 | 260 | // send the data to the gateway |
mfiore | 0:09250cd371d2 | 261 | if ((ret = dot->send(data)) != mDot::MDOT_OK) { |
Mehrad | 5:11863539202f | 262 | _serial.writef("ERROR: failed to send\r\n", ret, mDot::getReturnCodeString(ret).c_str()); |
mfiore | 0:09250cd371d2 | 263 | } else { |
Mehrad | 5:11863539202f | 264 | _serial.writef("INFO: successfully sent data to gateway "); |
Mehrad | 5:11863539202f | 265 | |
Mehrad | 5:11863539202f | 266 | _rssiStats = dot->getRssiStats(); |
Mehrad | 5:11863539202f | 267 | _serial.writef("+ RSSI values( last:%d min:%d max:%d avg:%d ) \r\n", _rssiStats.last, _rssiStats.min, _rssiStats.max, _rssiStats.avg); |
mfiore | 0:09250cd371d2 | 268 | } |
mfiore | 0:09250cd371d2 | 269 | |
mfiore | 4:36e214ebfa56 | 270 | // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again |
Mehrad | 5:11863539202f | 271 | //osDelay(std::max((uint32_t)50, (uint32_t)dot->getNextTxMs())); |
Mehrad | 5:11863539202f | 272 | //osDelay(std::max((uint32_t)2000, (uint32_t)dot->getNextTxMs())); |
Mehrad | 5:11863539202f | 273 | wait(1); |
Mehrad | 5:11863539202f | 274 | |
Mehrad | 5:11863539202f | 275 | ss.str(""); |
Mehrad | 5:11863539202f | 276 | |
Mehrad | 5:11863539202f | 277 | /* |
Mehrad | 5:11863539202f | 278 | //int temp = dht11->readTemperature(); |
Mehrad | 5:11863539202f | 279 | if (err == 0) { |
Mehrad | 5:11863539202f | 280 | float temp = dht.ReadTemperature(CELCIUS); |
Mehrad | 5:11863539202f | 281 | float rh = dht.ReadHumidity(); |
Mehrad | 5:11863539202f | 282 | _serial.writef(" Temp: %f Rh: %f \r\n", temp, rh); |
Mehrad | 5:11863539202f | 283 | ss << (temp); |
Mehrad | 5:11863539202f | 284 | ss << ','; |
Mehrad | 5:11863539202f | 285 | ss << rh; |
Mehrad | 5:11863539202f | 286 | } else { |
Mehrad | 5:11863539202f | 287 | ss.str(" :err "); |
Mehrad | 5:11863539202f | 288 | ss << err; |
Mehrad | 5:11863539202f | 289 | } |
Mehrad | 5:11863539202f | 290 | */ |
Mehrad | 5:11863539202f | 291 | |
Mehrad | 5:11863539202f | 292 | //double temp = ((in.read_u16() * 3.3) - 0.424) / 0.00625; |
Mehrad | 5:11863539202f | 293 | double adc = in.read_u16(); |
Mehrad | 5:11863539202f | 294 | /* |
Mehrad | 5:11863539202f | 295 | double a = 1E-12; |
Mehrad | 5:11863539202f | 296 | double b = 9E-8; |
Mehrad | 5:11863539202f | 297 | double temp; |
Mehrad | 5:11863539202f | 298 | temp = (a*adc*adc*adc)-(b*adc*adc)+0.0041*adc-43.313; |
Mehrad | 5:11863539202f | 299 | */ |
Mehrad | 5:11863539202f | 300 | double temp = 1.33536E-3*adc-2.2914E1; |
Mehrad | 5:11863539202f | 301 | ss << (temp); |
Mehrad | 5:11863539202f | 302 | |
Mehrad | 5:11863539202f | 303 | data.clear(); |
Mehrad | 5:11863539202f | 304 | // Converting int to string in C++ using <sstream> |
Mehrad | 5:11863539202f | 305 | data_str = ss.str(); |
mfiore | 0:09250cd371d2 | 306 | } |
mfiore | 0:09250cd371d2 | 307 | |
mfiore | 0:09250cd371d2 | 308 | return 0; |
mfiore | 0:09250cd371d2 | 309 | } |