
FF1705 support added
Dependencies: libxDot-dev-mbed5-deprecated ISL29011
Fork of Dot-Examples by
Dot-Examples rev. 31:7ec180e84cb6 have been tested with xdot-library 3.0.0-19-gb6c0ba2 and mbed-os-5.6.2
Revision 5:97ed5f2f099e, committed 2016-10-07
- Comitter:
- Mike Fiore
- Date:
- Fri Oct 07 10:38:54 2016 -0500
- Parent:
- 4:93579eb88fcd
- Child:
- 6:036c54a26c30
- Commit message:
- add support for using network ID and KEY instead of name and passphrase
Changed in this revision
--- a/examples/inc/dot_util.h Thu Oct 06 22:12:21 2016 +0000 +++ b/examples/inc/dot_util.h Fri Oct 07 10:38:54 2016 -0500 @@ -12,7 +12,9 @@ void display_config(); -void update_ota_config(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack); +void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack); + +void update_ota_config_id_key(uint8_t *network_id, uint8_t *network_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack); void join_network();
--- a/examples/src/auto_ota_example.cpp Thu Oct 06 22:12:21 2016 +0000 +++ b/examples/src/auto_ota_example.cpp Fri Oct 07 10:38:54 2016 -0500 @@ -2,13 +2,17 @@ #if ACTIVE_EXAMPLE == AUTO_OTA_EXAMPLE -/////////////////////////////////////////////////////////// -// these options must match the settings on your gateway // -// edit their values to match your configuration // -// frequency sub band is only relevant for the 915 bands // -/////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// * these options must match the settings on your gateway // +// * edit their values to match your configuration // +// * frequency sub band is only relevant for the 915 bands // +// * either the network name and passphrase can be used or // +// the network ID (8 bytes) and KEY (16 bytes) // +///////////////////////////////////////////////////////////// static std::string network_name = "MultiTech"; static std::string network_passphrase = "MultiTech"; +static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 }; +static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B }; static uint8_t frequency_sub_band = 0; static bool public_network = false; static uint8_t ack = 1; @@ -48,7 +52,12 @@ logError("failed to set network join mode to AUTO_OTA"); } } - update_ota_config(network_name, network_passphrase, frequency_sub_band, public_network, ack); + // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an EUI and KEY + // only one method or the other should be used! + // network ID = crc64(network name) + // network KEY = cmac(network passphrase) + update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack); + //update_ota_config_id_key(network_eui, network_key, frequency_sub_band, public_network, ack); // save changes to configuration // AUTO_OTA must be the saved join mode in order for the session to be properly restored after waking up from deepsleep
--- a/examples/src/dot_util.cpp Thu Oct 06 22:12:21 2016 +0000 +++ b/examples/src/dot_util.cpp Fri Oct 07 10:38:54 2016 -0500 @@ -26,7 +26,7 @@ logInfo("\tatnenna gain: %u dBm", dot->getAntennaGain()); } -void update_ota_config(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { +void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { std::string current_network_name = dot->getNetworkName(); std::string current_network_passphrase = dot->getNetworkPassphrase(); uint8_t current_frequency_sub_band = dot->getFrequencySubBand(); @@ -69,6 +69,52 @@ } } +void update_ota_config_id_key(uint8_t *network_id, uint8_t *network_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { + std::vector<uint8_t> current_network_id = dot->getNetworkId(); + std::vector<uint8_t> current_network_key = dot->getNetworkKey(); + uint8_t current_frequency_sub_band = dot->getFrequencySubBand(); + bool current_public_network = dot->getPublicNetwork(); + uint8_t current_ack = dot->getAck(); + + std::vector<uint8_t> network_id_vector(network_id, network_id + 8); + std::vector<uint8_t> network_key_vector(network_key, network_key + 16); + + if (current_network_id != network_id_vector) { + logInfo("changing network ID from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_id).c_str(), mts::Text::bin2hexString(network_id_vector).c_str()); + if (dot->setNetworkId(network_id_vector) != mDot::MDOT_OK) { + logError("failed to set network ID to \"%s\"", mts::Text::bin2hexString(network_id_vector).c_str()); + } + } + + if (current_network_key != network_key_vector) { + logInfo("changing network KEY from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_key).c_str(), mts::Text::bin2hexString(network_key_vector).c_str()); + if (dot->setNetworkKey(network_key_vector) != mDot::MDOT_OK) { + logError("failed to set network KEY to \"%s\"", mts::Text::bin2hexString(network_key_vector).c_str()); + } + } + + if (current_frequency_sub_band != frequency_sub_band) { + logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); + if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { + logError("failed to set frequency sub band to %u", frequency_sub_band); + } + } + + if (current_public_network != public_network) { + logInfo("changing public network from %s to %s", current_public_network ? "true" : "false", public_network ? "true" : "false"); + if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) { + logError("failed to set public network to %s", public_network ? "true" : "false"); + } + } + + if (current_ack != ack) { + logInfo("changing acks from %u to %u", current_ack, ack); + if (dot->setAck(ack) != mDot::MDOT_OK) { + logError("failed to set acks to %u", ack); + } + } +} + void join_network() { int32_t j_attempts = 0; int32_t ret = mDot::MDOT_ERROR;
--- a/examples/src/ota_example.cpp Thu Oct 06 22:12:21 2016 +0000 +++ b/examples/src/ota_example.cpp Fri Oct 07 10:38:54 2016 -0500 @@ -2,13 +2,17 @@ #if ACTIVE_EXAMPLE == OTA_EXAMPLE -/////////////////////////////////////////////////////////// -// these options must match the settings on your gateway // -// edit their values to match your configuration // -// frequency sub band is only relevant for the 915 bands // -/////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// * these options must match the settings on your gateway // +// * edit their values to match your configuration // +// * frequency sub band is only relevant for the 915 bands // +// * either the network name and passphrase can be used or // +// the network ID (8 bytes) and KEY (16 bytes) // +///////////////////////////////////////////////////////////// static std::string network_name = "MultiTech"; static std::string network_passphrase = "MultiTech"; +static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 }; +static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B }; static uint8_t frequency_sub_band = 0; static bool public_network = false; static uint8_t ack = 1; @@ -40,15 +44,19 @@ // make sure library logging is turned on dot->setLogLevel(mts::MTSLog::INFO_LEVEL); - // update configuration if necessary, then display it + // update configuration if necessary if (dot->getJoinMode() != mDot::OTA) { logInfo("changing network join mode to OTA"); if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) { logError("failed to set network join mode to OTA"); } } - update_ota_config(network_name, network_passphrase, frequency_sub_band, public_network, ack); - display_config(); + // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an EUI and KEY + // only one method or the other should be used! + // network ID = crc64(network name) + // network KEY = cmac(network passphrase) + update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack); + //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); // restore the saved session if the dot woke from deepsleep mode // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep @@ -57,6 +65,9 @@ dot->restoreNetworkSession(); } + // display configuration + display_config(); + while (true) { uint16_t light; std::vector<uint8_t> tx_data;