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