d
Dependencies: BME280 DOGS102 DS1820 MMA845x_timmeh MTS-Serial libmDot_Australia915Mhz mbed-rtos mbed
Fork of mDot_TTN_OTAA_Node by
main.cpp@17:55ea4f38710b, 2017-01-11 (annotated)
- Committer:
- 1994timmeh
- Date:
- Wed Jan 11 04:12:39 2017 +0000
- Revision:
- 17:55ea4f38710b
- Parent:
- 16:290c505e3851
Thing
Who changed what in which revision?
User | Revision | Line number | New 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 | 15:8a0ebf59b8bb | 11 | * (You need to use your own device IDs, the ones shown here are examples only) |
SomeRandomBloke | 13:5369ba22389a | 12 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 13 | *./ttnctl devices register 0080000000000000 |
1994timmeh | 17:55ea4f38710b | 14 | * INFO Generating random AppKey... |
SomeRandomBloke | 15:8a0ebf59b8bb | 15 | * INFO Registered device AppKey=000102030405060708090A0B0C0D0E0F DevEUI=0080000000000000 |
SomeRandomBloke | 13:5369ba22389a | 16 | * |
SomeRandomBloke | 13:5369ba22389a | 17 | * or to specify the same AppKey for a new device or to reregister the same device again: |
SomeRandomBloke | 13:5369ba22389a | 18 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 19 | * ./ttnctl devices register 0080000000000000 000102030405060708090A0B0C0D0E0F |
SomeRandomBloke | 13:5369ba22389a | 20 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 21 | * ./ttnctl devices info 0080000000000000 |
SomeRandomBloke | 13:5369ba22389a | 22 | * Dynamic device: |
SomeRandomBloke | 13:5369ba22389a | 23 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 24 | * AppEUI: 70B3D50000000000 |
SomeRandomBloke | 15:8a0ebf59b8bb | 25 | * {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00} |
SomeRandomBloke | 13:5369ba22389a | 26 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 27 | * DevEUI: 0080000000000000 |
SomeRandomBloke | 15:8a0ebf59b8bb | 28 | * {0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
SomeRandomBloke | 13:5369ba22389a | 29 | * |
SomeRandomBloke | 15:8a0ebf59b8bb | 30 | * AppKey: 000102030405060708090A0B0C0D0E0F |
SomeRandomBloke | 15:8a0ebf59b8bb | 31 | * {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F} |
SomeRandomBloke | 13:5369ba22389a | 32 | * |
SomeRandomBloke | 13:5369ba22389a | 33 | * |
SomeRandomBloke | 13:5369ba22389a | 34 | * Copy the AppEUI and AppKey values provided in hex array notation above to the AppEUI and AppKey parameters below. |
SomeRandomBloke | 13:5369ba22389a | 35 | * |
SomeRandomBloke | 0:5a0b43f3b143 | 36 | */ |
SomeRandomBloke | 0:5a0b43f3b143 | 37 | |
SomeRandomBloke | 0:5a0b43f3b143 | 38 | #include "mbed.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 39 | #include "DS1820.h" |
SomeRandomBloke | 13:5369ba22389a | 40 | //#include "BME280.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 41 | #include "mDot.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 42 | #include "MTSLog.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 43 | #include "MTSText.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 44 | #include <string> |
SomeRandomBloke | 0:5a0b43f3b143 | 45 | #include <vector> |
1994timmeh | 17:55ea4f38710b | 46 | #include "MMA845x.h" |
1994timmeh | 17:55ea4f38710b | 47 | #include "GPSPARSER.h" |
1994timmeh | 17:55ea4f38710b | 48 | #include "DOGS102.h" |
1994timmeh | 17:55ea4f38710b | 49 | #include "font_6x8.h" |
SomeRandomBloke | 0:5a0b43f3b143 | 50 | |
SomeRandomBloke | 0:5a0b43f3b143 | 51 | using namespace mts; |
SomeRandomBloke | 0:5a0b43f3b143 | 52 | |
SomeRandomBloke | 4:f649ab1b61d1 | 53 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
SomeRandomBloke | 4:f649ab1b61d1 | 54 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
SomeRandomBloke | 4:f649ab1b61d1 | 55 | |
1994timmeh | 17:55ea4f38710b | 56 | #define NUMSAMPLES 1000 |
1994timmeh | 17:55ea4f38710b | 57 | |
1994timmeh | 17:55ea4f38710b | 58 | |
1994timmeh | 17:55ea4f38710b | 59 | |
1994timmeh | 17:55ea4f38710b | 60 | typedef struct { |
1994timmeh | 17:55ea4f38710b | 61 | int lat_d; |
1994timmeh | 17:55ea4f38710b | 62 | int lat_m; |
1994timmeh | 17:55ea4f38710b | 63 | int lat_s; |
1994timmeh | 17:55ea4f38710b | 64 | int lng_d; |
1994timmeh | 17:55ea4f38710b | 65 | int lng_m; |
1994timmeh | 17:55ea4f38710b | 66 | int lng_s; |
1994timmeh | 17:55ea4f38710b | 67 | int x; |
1994timmeh | 17:55ea4f38710b | 68 | int y; |
1994timmeh | 17:55ea4f38710b | 69 | int z; |
1994timmeh | 17:55ea4f38710b | 70 | } Coordinate; |
1994timmeh | 17:55ea4f38710b | 71 | |
SomeRandomBloke | 13:5369ba22389a | 72 | // AppEUI |
1994timmeh | 17:55ea4f38710b | 73 | uint8_t AppEUI[8]= {0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0}; |
SomeRandomBloke | 13:5369ba22389a | 74 | // AppKey |
1994timmeh | 17:55ea4f38710b | 75 | uint8_t AppKey[16]= {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; |
SomeRandomBloke | 8:8070e9d660e4 | 76 | |
SomeRandomBloke | 8:8070e9d660e4 | 77 | // Some defines for the LoRa configuration |
SomeRandomBloke | 13:5369ba22389a | 78 | /* |
SomeRandomBloke | 13:5369ba22389a | 79 | * EU868 Datarates |
SomeRandomBloke | 13:5369ba22389a | 80 | * --------------- |
SomeRandomBloke | 13:5369ba22389a | 81 | * DR0 - SF12BW125 |
SomeRandomBloke | 13:5369ba22389a | 82 | * DR1 - SF11BW125 |
SomeRandomBloke | 13:5369ba22389a | 83 | * DR2 - SF10BW125 |
SomeRandomBloke | 13:5369ba22389a | 84 | * DR3 - SF9BW125 |
SomeRandomBloke | 13:5369ba22389a | 85 | * DR4 - SF8BW125 |
SomeRandomBloke | 13:5369ba22389a | 86 | * DR5 - SF7BW125 |
SomeRandomBloke | 13:5369ba22389a | 87 | * DR6 - SF7BW250 |
SomeRandomBloke | 13:5369ba22389a | 88 | * |
SomeRandomBloke | 13:5369ba22389a | 89 | * US915 Datarates |
SomeRandomBloke | 13:5369ba22389a | 90 | * --------------- |
SomeRandomBloke | 13:5369ba22389a | 91 | * DR0 - SF10BW125 |
SomeRandomBloke | 13:5369ba22389a | 92 | * DR1 - SF9BW125 |
SomeRandomBloke | 13:5369ba22389a | 93 | * DR2 - SF8BW125 |
SomeRandomBloke | 13:5369ba22389a | 94 | * DR3 - SF7BW125 |
SomeRandomBloke | 13:5369ba22389a | 95 | * DR4 - SF8BW500 |
SomeRandomBloke | 13:5369ba22389a | 96 | */ |
1994timmeh | 17:55ea4f38710b | 97 | #define LORA_SF mDot::DR4 |
SomeRandomBloke | 8:8070e9d660e4 | 98 | #define LORA_ACK 0 |
1994timmeh | 17:55ea4f38710b | 99 | #define LORA_TXPOWER 20 |
SomeRandomBloke | 5:48eb9245a914 | 100 | |
SomeRandomBloke | 3:367aa95f9771 | 101 | // Ignoring sub band for EU modules. |
SomeRandomBloke | 13:5369ba22389a | 102 | static uint8_t config_frequency_sub_band = 1; |
1994timmeh | 17:55ea4f38710b | 103 | volatile int stoppls = 0; |
SomeRandomBloke | 0:5a0b43f3b143 | 104 | |
1994timmeh | 17:55ea4f38710b | 105 | SPI lcd_spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); |
1994timmeh | 17:55ea4f38710b | 106 | DigitalOut lcd_spi_cs(SPI1_CS, 1); |
1994timmeh | 17:55ea4f38710b | 107 | DigitalOut lcd_cd(XBEE_ON_SLEEP, 1); |
SomeRandomBloke | 13:5369ba22389a | 108 | |
SomeRandomBloke | 3:367aa95f9771 | 109 | // Serial via USB for debugging only |
SomeRandomBloke | 0:5a0b43f3b143 | 110 | Serial pc(USBTX,USBRX); |
SomeRandomBloke | 0:5a0b43f3b143 | 111 | |
1994timmeh | 17:55ea4f38710b | 112 | MMA845x_DATA accldata; |
1994timmeh | 17:55ea4f38710b | 113 | |
1994timmeh | 17:55ea4f38710b | 114 | void gpsthread(void const *args) |
SomeRandomBloke | 0:5a0b43f3b143 | 115 | { |
1994timmeh | 17:55ea4f38710b | 116 | while(1) { |
1994timmeh | 17:55ea4f38710b | 117 | GPSPARSER *instance = (GPSPARSER*)args; |
1994timmeh | 17:55ea4f38710b | 118 | instance->readNemaSentence(); |
1994timmeh | 17:55ea4f38710b | 119 | } |
1994timmeh | 17:55ea4f38710b | 120 | } |
1994timmeh | 17:55ea4f38710b | 121 | |
1994timmeh | 17:55ea4f38710b | 122 | void acclthread(void const *args) { |
1994timmeh | 17:55ea4f38710b | 123 | |
1994timmeh | 17:55ea4f38710b | 124 | /* Create global i2c handle */ |
1994timmeh | 17:55ea4f38710b | 125 | I2C i2chandle = I2C(PC_9, PA_8); |
1994timmeh | 17:55ea4f38710b | 126 | |
1994timmeh | 17:55ea4f38710b | 127 | MMA845x instance = MMA845x(i2chandle, MMA845x::SA0_VSS); |
1994timmeh | 17:55ea4f38710b | 128 | |
1994timmeh | 17:55ea4f38710b | 129 | instance.setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF, |
1994timmeh | 17:55ea4f38710b | 130 | MMA845x::DR_50,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); |
1994timmeh | 17:55ea4f38710b | 131 | |
1994timmeh | 17:55ea4f38710b | 132 | instance.activeMode(); |
1994timmeh | 17:55ea4f38710b | 133 | |
1994timmeh | 17:55ea4f38710b | 134 | /* Accelerometer testing code */ |
1994timmeh | 17:55ea4f38710b | 135 | while(1) { |
1994timmeh | 17:55ea4f38710b | 136 | |
1994timmeh | 17:55ea4f38710b | 137 | if (!stoppls) { |
1994timmeh | 17:55ea4f38710b | 138 | int result = instance.getStatus(); |
1994timmeh | 17:55ea4f38710b | 139 | if((result & MMA845x::XYZDR) != 0 ) { |
1994timmeh | 17:55ea4f38710b | 140 | accldata = instance.getXYZ(); |
1994timmeh | 17:55ea4f38710b | 141 | |
1994timmeh | 17:55ea4f38710b | 142 | logInfo("Accl: %d %d %d\n\r", instance.getXYZ()._x, instance.getXYZ()._y, instance.getXYZ()._z); |
1994timmeh | 17:55ea4f38710b | 143 | } |
1994timmeh | 17:55ea4f38710b | 144 | } |
1994timmeh | 17:55ea4f38710b | 145 | |
1994timmeh | 17:55ea4f38710b | 146 | } |
1994timmeh | 17:55ea4f38710b | 147 | } |
1994timmeh | 17:55ea4f38710b | 148 | |
1994timmeh | 17:55ea4f38710b | 149 | int main() { |
SomeRandomBloke | 0:5a0b43f3b143 | 150 | int32_t ret; |
SomeRandomBloke | 0:5a0b43f3b143 | 151 | mDot* dot; |
SomeRandomBloke | 0:5a0b43f3b143 | 152 | std::vector<uint8_t> send_data; |
SomeRandomBloke | 0:5a0b43f3b143 | 153 | std::vector<uint8_t> recv_data; |
SomeRandomBloke | 13:5369ba22389a | 154 | std::vector<uint8_t> nwkId; |
SomeRandomBloke | 13:5369ba22389a | 155 | std::vector<uint8_t> nwkKey; |
SomeRandomBloke | 0:5a0b43f3b143 | 156 | |
1994timmeh | 17:55ea4f38710b | 157 | dot = mDot::getInstance(); |
1994timmeh | 17:55ea4f38710b | 158 | dot->setLogLevel(MTSLog::INFO_LEVEL); |
1994timmeh | 17:55ea4f38710b | 159 | logInfo("Starting...\n\r"); |
SomeRandomBloke | 1:45cec6aea002 | 160 | |
1994timmeh | 17:55ea4f38710b | 161 | GPSPARSER* gps; |
1994timmeh | 17:55ea4f38710b | 162 | MTSSerial gps_serial(XBEE_DOUT, XBEE_DIN, 256, 2048); |
1994timmeh | 17:55ea4f38710b | 163 | gps = new GPSPARSER(&gps_serial); |
1994timmeh | 17:55ea4f38710b | 164 | Thread gpst(gpsthread, gps); |
SomeRandomBloke | 1:45cec6aea002 | 165 | |
1994timmeh | 17:55ea4f38710b | 166 | Thread acclt(acclthread); |
SomeRandomBloke | 0:5a0b43f3b143 | 167 | |
1994timmeh | 17:55ea4f38710b | 168 | DOGS102* lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd); |
1994timmeh | 17:55ea4f38710b | 169 | |
1994timmeh | 17:55ea4f38710b | 170 | DigitalIn button(PA_11); |
1994timmeh | 17:55ea4f38710b | 171 | button.mode(PullUp); |
SomeRandomBloke | 0:5a0b43f3b143 | 172 | |
1994timmeh | 17:55ea4f38710b | 173 | #ifdef ENABLE_LORA |
SomeRandomBloke | 1:45cec6aea002 | 174 | logInfo("Checking Config"); |
SomeRandomBloke | 1:45cec6aea002 | 175 | |
SomeRandomBloke | 13:5369ba22389a | 176 | uint8_t *it = AppEUI; |
SomeRandomBloke | 13:5369ba22389a | 177 | for (uint8_t i = 0; i<8; i++) |
SomeRandomBloke | 13:5369ba22389a | 178 | nwkId.push_back((uint8_t) *it++); |
1994timmeh | 17:55ea4f38710b | 179 | |
SomeRandomBloke | 13:5369ba22389a | 180 | it = AppKey; |
SomeRandomBloke | 5:48eb9245a914 | 181 | for (uint8_t i = 0; i<16; i++) |
SomeRandomBloke | 13:5369ba22389a | 182 | nwkKey.push_back((uint8_t) *it++); |
SomeRandomBloke | 1:45cec6aea002 | 183 | |
SomeRandomBloke | 9:086351e54b57 | 184 | logInfo("Resetting Config"); |
SomeRandomBloke | 9:086351e54b57 | 185 | // reset to default config so we know what state we're in |
SomeRandomBloke | 9:086351e54b57 | 186 | dot->resetConfig(); |
SomeRandomBloke | 1:45cec6aea002 | 187 | |
SomeRandomBloke | 5:48eb9245a914 | 188 | // Set Spreading Factor, higher is lower data rate, smaller packets but longer range |
SomeRandomBloke | 5:48eb9245a914 | 189 | // Lower is higher data rate, larger packets and shorter range. |
SomeRandomBloke | 5:48eb9245a914 | 190 | logInfo("Set SF"); |
SomeRandomBloke | 8:8070e9d660e4 | 191 | if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) { |
SomeRandomBloke | 5:48eb9245a914 | 192 | logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 5:48eb9245a914 | 193 | } |
SomeRandomBloke | 5:48eb9245a914 | 194 | |
SomeRandomBloke | 5:48eb9245a914 | 195 | logInfo("Set TxPower"); |
SomeRandomBloke | 8:8070e9d660e4 | 196 | if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) { |
SomeRandomBloke | 5:48eb9245a914 | 197 | logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 5:48eb9245a914 | 198 | } |
SomeRandomBloke | 5:48eb9245a914 | 199 | |
SomeRandomBloke | 7:2a704d1a30e1 | 200 | logInfo("Set Public mode"); |
SomeRandomBloke | 7:2a704d1a30e1 | 201 | if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) { |
SomeRandomBloke | 7:2a704d1a30e1 | 202 | logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 7:2a704d1a30e1 | 203 | } |
SomeRandomBloke | 7:2a704d1a30e1 | 204 | |
SomeRandomBloke | 13:5369ba22389a | 205 | logInfo("Set AUTO_OTA Join mode"); |
SomeRandomBloke | 13:5369ba22389a | 206 | if((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) { |
SomeRandomBloke | 13:5369ba22389a | 207 | logError("Failed to set AUTO_OTA Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 7:2a704d1a30e1 | 208 | } |
SomeRandomBloke | 7:2a704d1a30e1 | 209 | |
SomeRandomBloke | 5:48eb9245a914 | 210 | logInfo("Set Ack"); |
SomeRandomBloke | 5:48eb9245a914 | 211 | // 1 retries on Ack, 0 to disable |
SomeRandomBloke | 8:8070e9d660e4 | 212 | if((ret = dot->setAck( LORA_ACK)) != mDot::MDOT_OK) { |
SomeRandomBloke | 5:48eb9245a914 | 213 | logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 5:48eb9245a914 | 214 | } |
SomeRandomBloke | 3:367aa95f9771 | 215 | |
SomeRandomBloke | 13:5369ba22389a | 216 | // Library ignores the frequency sub band for 868MHz in EU |
SomeRandomBloke | 13:5369ba22389a | 217 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
SomeRandomBloke | 13:5369ba22389a | 218 | logError("Failed to set frequency sub band %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 7:2a704d1a30e1 | 219 | } |
SomeRandomBloke | 7:2a704d1a30e1 | 220 | |
SomeRandomBloke | 13:5369ba22389a | 221 | logInfo("Set Network Id"); |
SomeRandomBloke | 13:5369ba22389a | 222 | if ((ret = dot->setNetworkId(nwkId)) != mDot::MDOT_OK) { |
SomeRandomBloke | 13:5369ba22389a | 223 | logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 5:48eb9245a914 | 224 | } |
SomeRandomBloke | 13:5369ba22389a | 225 | logInfo("Set Network Key"); |
SomeRandomBloke | 13:5369ba22389a | 226 | if ((ret = dot->setNetworkKey(nwkKey)) != mDot::MDOT_OK) { |
SomeRandomBloke | 13:5369ba22389a | 227 | logError("Failed to set Network Id %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 5:48eb9245a914 | 228 | } |
SomeRandomBloke | 5:48eb9245a914 | 229 | |
SomeRandomBloke | 5:48eb9245a914 | 230 | logInfo("Saving Config"); |
SomeRandomBloke | 5:48eb9245a914 | 231 | // Save config |
SomeRandomBloke | 5:48eb9245a914 | 232 | if (! dot->saveConfig()) { |
SomeRandomBloke | 5:48eb9245a914 | 233 | logError("failed to save configuration"); |
SomeRandomBloke | 0:5a0b43f3b143 | 234 | } |
SomeRandomBloke | 5:48eb9245a914 | 235 | |
SomeRandomBloke | 13:5369ba22389a | 236 | pc.printf("Device ID {"); |
SomeRandomBloke | 6:0a7760eeaba9 | 237 | std::vector<uint8_t> deviceId; |
SomeRandomBloke | 6:0a7760eeaba9 | 238 | deviceId = dot->getDeviceId(); |
SomeRandomBloke | 13:5369ba22389a | 239 | for (std::vector<uint8_t>::iterator it = deviceId.begin() ; it != deviceId.end(); ++it) { |
SomeRandomBloke | 13:5369ba22389a | 240 | pc.printf("0x%2.2X",*it ); |
SomeRandomBloke | 13:5369ba22389a | 241 | pc.printf("%s", it != (deviceId.end() -1 ) ? ", " : " " ); |
SomeRandomBloke | 13:5369ba22389a | 242 | } |
SomeRandomBloke | 13:5369ba22389a | 243 | pc.printf("}\r\n"); |
SomeRandomBloke | 9:086351e54b57 | 244 | |
SomeRandomBloke | 13:5369ba22389a | 245 | std::vector<uint8_t> netId; |
SomeRandomBloke | 13:5369ba22389a | 246 | pc.printf("Network Id/App EUI {"); |
SomeRandomBloke | 13:5369ba22389a | 247 | netId = dot->getNetworkId(); |
SomeRandomBloke | 13:5369ba22389a | 248 | for (std::vector<uint8_t>::iterator it = netId.begin() ; it != netId.end(); ++it) { |
SomeRandomBloke | 13:5369ba22389a | 249 | pc.printf("0x%2.2X", *it ); |
SomeRandomBloke | 13:5369ba22389a | 250 | pc.printf("%s", it != (netId.end() -1 ) ? ", " : " " ); |
SomeRandomBloke | 13:5369ba22389a | 251 | } |
SomeRandomBloke | 13:5369ba22389a | 252 | pc.printf("}\r\n"); |
SomeRandomBloke | 5:48eb9245a914 | 253 | |
SomeRandomBloke | 13:5369ba22389a | 254 | std::vector<uint8_t> netKey; |
SomeRandomBloke | 13:5369ba22389a | 255 | pc.printf("Network Key/App Key {"); |
SomeRandomBloke | 13:5369ba22389a | 256 | netKey = dot->getNetworkKey(); |
SomeRandomBloke | 13:5369ba22389a | 257 | for (std::vector<uint8_t>::iterator it = netKey.begin() ; it != netKey.end(); ++it) { |
SomeRandomBloke | 13:5369ba22389a | 258 | pc.printf("0x%2.2X", *it ); |
SomeRandomBloke | 13:5369ba22389a | 259 | pc.printf("%s", it != (netKey.end() -1 ) ? ", " : " " ); |
SomeRandomBloke | 13:5369ba22389a | 260 | } |
SomeRandomBloke | 13:5369ba22389a | 261 | pc.printf("}\r\n"); |
SomeRandomBloke | 5:48eb9245a914 | 262 | |
SomeRandomBloke | 5:48eb9245a914 | 263 | // Display LoRa parameters |
SomeRandomBloke | 5:48eb9245a914 | 264 | // Display label and values in different colours, show pretty values not numeric values where applicable |
1994timmeh | 17:55ea4f38710b | 265 | /* |
1994timmeh | 17:55ea4f38710b | 266 | pc.printf("Public Network: %s\r\n", (char*)(dot->getPublicNetwork() ? "Yes" : "No") ); |
1994timmeh | 17:55ea4f38710b | 267 | pc.printf("Frequency: %s\r\n", (char*)mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str() ); |
1994timmeh | 17:55ea4f38710b | 268 | pc.printf("Sub Band: %s\r\n", (char*)mDot::FrequencySubBandStr(dot->getFrequencySubBand()).c_str() ); |
1994timmeh | 17:55ea4f38710b | 269 | pc.printf("Join Mode: %s\r\n", (char*)mDot::JoinModeStr(dot->getJoinMode()).c_str() ); |
1994timmeh | 17:55ea4f38710b | 270 | pc.printf("Join Retries: %d\r\n", dot->getJoinRetries() ); |
1994timmeh | 17:55ea4f38710b | 271 | pc.printf("Join Byte Order: %s\r\n", (char*)(dot->getJoinByteOrder() == 0 ? "LSB" : "MSB") ); |
1994timmeh | 17:55ea4f38710b | 272 | pc.printf("Link Check Count: %d\r\n", dot->getLinkCheckCount() ); |
1994timmeh | 17:55ea4f38710b | 273 | pc.printf("Link Check Thold: %d\r\n", dot->getLinkCheckThreshold() ); |
1994timmeh | 17:55ea4f38710b | 274 | pc.printf("Tx Data Rate: %s\r\n", (char*)mDot::DataRateStr(dot->getTxDataRate()).c_str() ); |
1994timmeh | 17:55ea4f38710b | 275 | pc.printf("Tx Power: %d\r\n", dot->getTxPower() ); |
1994timmeh | 17:55ea4f38710b | 276 | pc.printf("TxWait: %s, ", (dot->getTxWait() ? "Y" : "N" )); |
1994timmeh | 17:55ea4f38710b | 277 | pc.printf("CRC: %s, ", (dot->getCrc() ? "Y" : "N") ); |
1994timmeh | 17:55ea4f38710b | 278 | pc.printf("Ack: %s\r\n", (dot->getAck() ? "Y" : "N") ); |
1994timmeh | 17:55ea4f38710b | 279 | */ |
SomeRandomBloke | 9:086351e54b57 | 280 | logInfo("Joining Network"); |
SomeRandomBloke | 6:0a7760eeaba9 | 281 | |
SomeRandomBloke | 9:086351e54b57 | 282 | while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
SomeRandomBloke | 9:086351e54b57 | 283 | logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
SomeRandomBloke | 9:086351e54b57 | 284 | wait_ms(dot->getNextTxMs() + 1); |
SomeRandomBloke | 9:086351e54b57 | 285 | } |
SomeRandomBloke | 6:0a7760eeaba9 | 286 | |
SomeRandomBloke | 9:086351e54b57 | 287 | logInfo("Joined Network"); |
SomeRandomBloke | 6:0a7760eeaba9 | 288 | |
SomeRandomBloke | 13:5369ba22389a | 289 | // Display Network session key and data session key from Join command |
1994timmeh | 17:55ea4f38710b | 290 | /* |
1994timmeh | 17:55ea4f38710b | 291 | std::vector<uint8_t> tmp = dot->getNetworkSessionKey(); |
1994timmeh | 17:55ea4f38710b | 292 | pc.printf("Network Session Key: "); |
1994timmeh | 17:55ea4f38710b | 293 | pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str()); |
SomeRandomBloke | 13:5369ba22389a | 294 | |
1994timmeh | 17:55ea4f38710b | 295 | tmp = dot->getDataSessionKey(); |
1994timmeh | 17:55ea4f38710b | 296 | pc.printf("Data Session Key: "); |
1994timmeh | 17:55ea4f38710b | 297 | pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str()); |
1994timmeh | 17:55ea4f38710b | 298 | */ |
1994timmeh | 17:55ea4f38710b | 299 | #endif /* ENABLE_LORA */ |
SomeRandomBloke | 0:5a0b43f3b143 | 300 | |
SomeRandomBloke | 0:5a0b43f3b143 | 301 | char dataBuf[50]; |
1994timmeh | 17:55ea4f38710b | 302 | uint16_t count = 0; |
1994timmeh | 17:55ea4f38710b | 303 | Coordinate points[NUMSAMPLES]; |
1994timmeh | 17:55ea4f38710b | 304 | int mode = 0; |
SomeRandomBloke | 0:5a0b43f3b143 | 305 | while( 1 ) { |
1994timmeh | 17:55ea4f38710b | 306 | |
1994timmeh | 17:55ea4f38710b | 307 | lcd->writeText(0, 0, font_6x8, "Not saving", 10); |
1994timmeh | 17:55ea4f38710b | 308 | |
1994timmeh | 17:55ea4f38710b | 309 | if (!button.read()) { |
1994timmeh | 17:55ea4f38710b | 310 | count = 0; |
1994timmeh | 17:55ea4f38710b | 311 | mode = 1; |
1994timmeh | 17:55ea4f38710b | 312 | } |
1994timmeh | 17:55ea4f38710b | 313 | |
1994timmeh | 17:55ea4f38710b | 314 | if (mode) { |
1994timmeh | 17:55ea4f38710b | 315 | |
1994timmeh | 17:55ea4f38710b | 316 | lcd->writeText(0, 0, font_6x8, "Saving ", 10); |
1994timmeh | 17:55ea4f38710b | 317 | |
1994timmeh | 17:55ea4f38710b | 318 | Coordinate a = { gps->getLongitude().degrees, gps->getLongitude().minutes, gps->getLongitude().seconds, gps->getLatitude().degrees, gps->getLatitude().minutes, gps->getLatitude().seconds , accldata._x, accldata._y, accldata._z}; |
1994timmeh | 17:55ea4f38710b | 319 | points[count] = a; |
1994timmeh | 17:55ea4f38710b | 320 | count++; |
1994timmeh | 17:55ea4f38710b | 321 | } |
1994timmeh | 17:55ea4f38710b | 322 | |
1994timmeh | 17:55ea4f38710b | 323 | lcd->writeText(0, 1, font_6x8, (gps->getLockStatus() ? "GPS Locked " : "No GPS Lock"), 11); |
1994timmeh | 17:55ea4f38710b | 324 | |
1994timmeh | 17:55ea4f38710b | 325 | if (gps->getLockStatus()) { |
1994timmeh | 17:55ea4f38710b | 326 | |
1994timmeh | 17:55ea4f38710b | 327 | sprintf(dataBuf, "Lat: %d,%d,%d", gps->getLatitude().degrees, gps->getLatitude().minutes, gps->getLatitude().seconds); |
1994timmeh | 17:55ea4f38710b | 328 | lcd->writeText(0, 2, font_6x8, dataBuf, strlen(dataBuf)); |
1994timmeh | 17:55ea4f38710b | 329 | |
1994timmeh | 17:55ea4f38710b | 330 | sprintf(dataBuf, "Long: %d,%d,%d", gps->getLongitude().degrees, gps->getLongitude().minutes, gps->getLongitude().seconds); |
1994timmeh | 17:55ea4f38710b | 331 | lcd->writeText(0, 3, font_6x8, dataBuf, strlen(dataBuf)); |
1994timmeh | 17:55ea4f38710b | 332 | |
1994timmeh | 17:55ea4f38710b | 333 | sprintf(dataBuf, "Sat: %d", gps->getNumSatellites()); |
1994timmeh | 17:55ea4f38710b | 334 | lcd->writeText(0, 4, font_6x8, dataBuf, strlen(dataBuf)); |
1994timmeh | 17:55ea4f38710b | 335 | |
1994timmeh | 17:55ea4f38710b | 336 | } |
1994timmeh | 17:55ea4f38710b | 337 | |
1994timmeh | 17:55ea4f38710b | 338 | sprintf(dataBuf, "%04d,%04d,%04d ", accldata._x, accldata._y, accldata._z); |
1994timmeh | 17:55ea4f38710b | 339 | lcd->writeText(0, 5, font_6x8, dataBuf, strlen(dataBuf)); |
1994timmeh | 17:55ea4f38710b | 340 | |
1994timmeh | 17:55ea4f38710b | 341 | sprintf(dataBuf, "Time: %02d", gps->getTimestamp().tm_sec); |
1994timmeh | 17:55ea4f38710b | 342 | lcd->writeText(0, 6, font_6x8, dataBuf, strlen(dataBuf)); |
SomeRandomBloke | 13:5369ba22389a | 343 | |
1994timmeh | 17:55ea4f38710b | 344 | |
1994timmeh | 17:55ea4f38710b | 345 | #ifdef ENABLE_LORA |
1994timmeh | 17:55ea4f38710b | 346 | send_data.clear(); |
1994timmeh | 17:55ea4f38710b | 347 | // probably not the most efficent way to do this |
1994timmeh | 17:55ea4f38710b | 348 | for( int i=0; i< strlen(dataBuf); i++ ) { |
1994timmeh | 17:55ea4f38710b | 349 | send_data.push_back( dataBuf[i] ); |
1994timmeh | 17:55ea4f38710b | 350 | } |
1994timmeh | 17:55ea4f38710b | 351 | |
1994timmeh | 17:55ea4f38710b | 352 | if ((ret = dot->send(send_data)) != mDot::MDOT_OK) { |
1994timmeh | 17:55ea4f38710b | 353 | logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); |
1994timmeh | 17:55ea4f38710b | 354 | } else { |
1994timmeh | 17:55ea4f38710b | 355 | logInfo("send data: %s", Text::bin2hexString(send_data).c_str()); |
1994timmeh | 17:55ea4f38710b | 356 | } |
1994timmeh | 17:55ea4f38710b | 357 | #endif /* ENABLE_LORA */ |
1994timmeh | 17:55ea4f38710b | 358 | |
1994timmeh | 17:55ea4f38710b | 359 | sprintf(dataBuf, "C: %03d B: %d", count, button.read()); |
1994timmeh | 17:55ea4f38710b | 360 | lcd->writeText(0, 7, font_6x8, dataBuf, strlen(dataBuf)); |
SomeRandomBloke | 0:5a0b43f3b143 | 361 | |
1994timmeh | 17:55ea4f38710b | 362 | osDelay(1000/50); |
1994timmeh | 17:55ea4f38710b | 363 | |
1994timmeh | 17:55ea4f38710b | 364 | if (count == NUMSAMPLES && mode) { |
1994timmeh | 17:55ea4f38710b | 365 | // Stop sampling |
1994timmeh | 17:55ea4f38710b | 366 | stoppls = 1; |
1994timmeh | 17:55ea4f38710b | 367 | while (1) { |
1994timmeh | 17:55ea4f38710b | 368 | sprintf(dataBuf, "C: %03d B: %d", count, button.read()); |
1994timmeh | 17:55ea4f38710b | 369 | lcd->writeText(0, 7, font_6x8, dataBuf, strlen(dataBuf)); |
1994timmeh | 17:55ea4f38710b | 370 | |
1994timmeh | 17:55ea4f38710b | 371 | if (!button.read()) { |
1994timmeh | 17:55ea4f38710b | 372 | logInfo("Starting..."); |
1994timmeh | 17:55ea4f38710b | 373 | for (int i = 0; i < NUMSAMPLES; i++) { |
1994timmeh | 17:55ea4f38710b | 374 | logInfo("%d,%d,%d,%d,%d,%d,%d,%d,%d", points[i].lat_d, points[i].lat_m, points[i].lat_s, points[i].lng_d, points[i].lng_m, points[i].lng_s, points[i].x, points[i].y, points[i].z); |
1994timmeh | 17:55ea4f38710b | 375 | osDelay(1); |
1994timmeh | 17:55ea4f38710b | 376 | } |
1994timmeh | 17:55ea4f38710b | 377 | logInfo("DONE"); |
1994timmeh | 17:55ea4f38710b | 378 | } |
1994timmeh | 17:55ea4f38710b | 379 | |
1994timmeh | 17:55ea4f38710b | 380 | osDelay(100); |
1994timmeh | 17:55ea4f38710b | 381 | } |
1994timmeh | 17:55ea4f38710b | 382 | } |
SomeRandomBloke | 0:5a0b43f3b143 | 383 | } |
SomeRandomBloke | 0:5a0b43f3b143 | 384 | } |