diff --git a/README.md b/README.md index 48b1085..57199a7 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ In order to disable the reconfiguration procedure, use this function in the sket ## Configurator Agents -The library provides a set of *Configurator Agents* that added as plug-in to the sketch handle the communication between the Arduino Network Configurator and an external client ([*Arduino IoT App*](https://cloud.arduino.cc/iot-remote-app/) and Arduino IoT Cloud) for configuring the board. +The library provides a set of *Configurator Agents* that added as plug-in to the sketch handle the communication between the Arduino Network Configurator and an external client ([*Arduino IoT App*](https://cloud.arduino.cc/iot-remote-app/), Arduino IoT Cloud, [*Arduino Cloud CLI from v0.3.4*](https://github.com/arduino/arduino-cloud-cli)) for configuring the board. Out-of-the box there are 2 Configurator Agents * `BLEAgent`: manage the BLE interface diff --git a/extras/test/src/test_provisioning_command_encode.cpp b/extras/test/src/test_provisioning_command_encode.cpp index 64872fc..529df0c 100644 --- a/extras/test/src/test_provisioning_command_encode.cpp +++ b/extras/test/src/test_provisioning_command_encode.cpp @@ -209,33 +209,6 @@ } } - WHEN("Encode a message with provisioning wifi fw version ") - { - WiFiFWVersionProvisioningMessage command; - command.c.id = ProvisioningMessageId::WiFiFWVersionProvisioningMessageId; - command.wifiFwVersion = "1.6.0"; - uint8_t buffer[512]; - size_t bytes_encoded = sizeof(buffer); - - CBORMessageEncoder encoder; - MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded); - - uint8_t expected_result[] = { - 0xda, 0x00, 0x01, 0x20, 0x14, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30 - }; - - // Test the encoding is - //DA 00012014 # tag(73748) - // 81 # array(1) - // 65 # text(5) - // 312E362E30 # "1.6.0" - THEN("The encoding is successful") { - REQUIRE(err == MessageEncoder::Status::Complete); - REQUIRE(bytes_encoded == sizeof(expected_result)); - REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0); - } - } - WHEN("Encode a message with provisioning sketch version ") { ProvSketchVersionProvisioningMessage command; diff --git a/library.properties b/library.properties index 14cbfa0..89fcfba 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_NetworkConfigurator -version=0.2.0 +version=0.2.1 author=Arduino maintainer=Arduino sentence=This library allows to configure and update the network settings of a ConnectionHandler instance. diff --git a/src/ANetworkConfigurator_Config.h b/src/ANetworkConfigurator_Config.h index 465659f..6fb9ec0 100644 --- a/src/ANetworkConfigurator_Config.h +++ b/src/ANetworkConfigurator_Config.h @@ -7,7 +7,7 @@ */ #pragma once -#define ANetworkConfigurator_LIB_VERSION "0.2.0" +#define ANetworkConfigurator_LIB_VERSION "0.2.1" #if defined(ARDUINO_SAMD_MKRWIFI1010) #define NETWORK_CONFIGURATOR_COMPATIBLE 1 diff --git a/src/configuratorAgents/AgentsManager.cpp b/src/configuratorAgents/AgentsManager.cpp index 71f8f34..bff98ee 100644 --- a/src/configuratorAgents/AgentsManager.cpp +++ b/src/configuratorAgents/AgentsManager.cpp @@ -239,7 +239,15 @@ AgentsManagerStates AgentsManagerClass::handleInit() { (*agent)->end(); } } - LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::PEER_CONNECTED); + + if(_selectedAgent->getAgentType() == ConfiguratorAgent::AgentTypes::BLE) { + LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::PEER_CONNECTED_BLE); + } else if(_selectedAgent->getAgentType() == ConfiguratorAgent::AgentTypes::USB_SERIAL) { + LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::PEER_CONNECTED_SERIAL); + } else { + LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::PEER_CONNECTED); + } + } return nextState; } diff --git a/src/configuratorAgents/agents/boardConfigurationProtocol/CBORAdapter.cpp b/src/configuratorAgents/agents/boardConfigurationProtocol/CBORAdapter.cpp index 96fcbf5..5442932 100644 --- a/src/configuratorAgents/agents/boardConfigurationProtocol/CBORAdapter.cpp +++ b/src/configuratorAgents/agents/boardConfigurationProtocol/CBORAdapter.cpp @@ -87,9 +87,9 @@ bool CBORAdapter::wifiFWVersionToCBOR(const char *wifiFWVersion, uint8_t *data, if(*len < CBOR_MIN_WIFI_FW_VERSION_LEN + strlen(wifiFWVersion)) { return false; } - WiFiFWVersionProvisioningMessage wifiFWVersionMsg; - wifiFWVersionMsg.c.id = ProvisioningMessageId::WiFiFWVersionProvisioningMessageId; - wifiFWVersionMsg.wifiFwVersion = wifiFWVersion; + VersionMessage wifiFWVersionMsg; + wifiFWVersionMsg.c.id = StandardMessageId::WiFiFWVersionMessageId; + wifiFWVersionMsg.params.version = wifiFWVersion; MessageEncoder::Status status = encoder.encode((Message *)&wifiFWVersionMsg, data, *len); diff --git a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/CBORInstances.h b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/CBORInstances.h index b726e0f..dbca315 100644 --- a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/CBORInstances.h +++ b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/CBORInstances.h @@ -8,7 +8,6 @@ static ListWifiNetworksProvisioningMessageEncoder listWifiNetworksProvisioning static UniqueHardwareIdProvisioningMessageEncoder uniqueHardwareIdProvisioningMessageEncoder; static JWTProvisioningMessageEncoder jWTProvisioningMessageEncoder; static BLEMacAddressProvisioningMessageEncoder bLEMacAddressProvisioningMessageEncoder; -static WiFiFWVersionProvisioningMessageEncoder wiFiFWVersionProvisioningMessageEncoder; static ProvSketchVersionProvisioningMessageEncoder provSketchVersionProvisioningMessageEncoder; static NetConfigLibVersProvisioningMessageEncoder netConfigLibVersProvisioningMessageEncoder; diff --git a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.cpp b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.cpp index fd0bb07..6c501f9 100644 --- a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.cpp +++ b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.cpp @@ -116,25 +116,6 @@ MessageEncoder::Status BLEMacAddressProvisioningMessageEncoder::encode(CborEncod return MessageEncoder::Status::Complete; } -MessageEncoder::Status WiFiFWVersionProvisioningMessageEncoder::encode(CborEncoder* encoder, Message *msg) { - WiFiFWVersionProvisioningMessage * provisioningWiFiFWVersion = (WiFiFWVersionProvisioningMessage*) msg; - CborEncoder array_encoder; - - if(cbor_encoder_create_array(encoder, &array_encoder, 1) != CborNoError) { - return MessageEncoder::Status::Error; - } - - if(cbor_encode_text_stringz(&array_encoder, provisioningWiFiFWVersion->wifiFwVersion) != CborNoError) { - return MessageEncoder::Status::Error; - } - - if(cbor_encoder_close_container(encoder, &array_encoder) != CborNoError) { - return MessageEncoder::Status::Error; - } - - return MessageEncoder::Status::Complete; -} - MessageEncoder::Status ProvSketchVersionProvisioningMessageEncoder::encode(CborEncoder* encoder, Message *msg) { ProvSketchVersionProvisioningMessage * provisioningSketchVersion = (ProvSketchVersionProvisioningMessage*) msg; CborEncoder array_encoder; diff --git a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.h b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.h index fd02dfa..25934f4 100644 --- a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.h +++ b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/Encoder.h @@ -52,14 +52,6 @@ class BLEMacAddressProvisioningMessageEncoder: public CBORMessageEncoderInterfac MessageEncoder::Status encode(CborEncoder* encoder, Message *msg) override; }; -class WiFiFWVersionProvisioningMessageEncoder: public CBORMessageEncoderInterface { -public: - WiFiFWVersionProvisioningMessageEncoder() - : CBORMessageEncoderInterface(CBORWiFiFWVersionProvisioningMessage, WiFiFWVersionProvisioningMessageId) {} -protected: - MessageEncoder::Status encode(CborEncoder* encoder, Message *msg) override; -}; - class ProvSketchVersionProvisioningMessageEncoder: public CBORMessageEncoderInterface { public: ProvSketchVersionProvisioningMessageEncoder() diff --git a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/ProvisioningMessage.h b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/ProvisioningMessage.h index 240a7b5..d48800d 100644 --- a/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/ProvisioningMessage.h +++ b/src/configuratorAgents/agents/boardConfigurationProtocol/cbor/ProvisioningMessage.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,6 @@ enum CBORProvisioningMessageTag: CBORTag { CBORUniqueHardwareIdProvisioningMessage = 0x012010, CBORJWTProvisioningMessage = 0x012011, CBORBLEMacAddressProvisioningMessage = 0x012013, - CBORWiFiFWVersionProvisioningMessage = 0x012014, CBORProvSketchVersionProvisioningMessage = 0x012015, CBORNetConfigLibVersProvisioningMessage = 0x012016, }; @@ -58,7 +58,6 @@ enum ProvisioningMessageId: MessageId { ListWifiNetworksProvisioningMessageId, UniqueHardwareIdProvisioningMessageId, BLEMacAddressProvisioningMessageId, - WiFiFWVersionProvisioningMessageId, ProvSketchVersionProvisioningMessageId, NetConfigLibVersProvisioningMessageId, JWTProvisioningMessageId, @@ -116,13 +115,6 @@ struct BLEMacAddressProvisioningMessage { }; }; -struct WiFiFWVersionProvisioningMessage { - ProvisioningMessage c; - struct { - const char *wifiFwVersion; //The payload is a string. - }; -}; - struct ProvSketchVersionProvisioningMessage { ProvisioningMessage c; struct { diff --git a/src/utility/LEDFeedback.cpp b/src/utility/LEDFeedback.cpp index 10abfe7..2ae9dc7 100644 --- a/src/utility/LEDFeedback.cpp +++ b/src/utility/LEDFeedback.cpp @@ -19,6 +19,14 @@ #include "Arduino_LED_Matrix.h" ArduinoLEDMatrix ledMatrixAnimationHandler; + +const uint32_t usb_image[3] = { + 0x3c, + 0x267fe0, + 0x160e0000, + +}; + const uint32_t bluetooth[3] = { 0x401600d, @@ -28,22 +36,16 @@ const uint32_t bluetooth[3] = { const uint32_t cloud[][4] = { { - 0xc013, - 0x82644424, - 0x24023fc, - 66 - }, - { - 0xc013, - 0x82644424, - 0x24023fc, - 66 + 0x1c023, + 0x4484044, + 0x43f8000, + 500 }, { - 0xc013, - 0x82644824, - 0x24023fc, - 66 + 0xe011, + 0x82242022, + 0x21fc000, + 500 } }; @@ -204,17 +206,25 @@ void LEDFeedbackClass::setMode(LEDFeedbackMode mode) { break; case LEDFeedbackMode::PEER_CONNECTED: { - #ifdef BOARD_HAS_RGB - turnOFF(); - _ledPin = BLUE_LED; - #else - _ledPin = GREEN_LED; - #endif + configurePeerConnectedMode(); + } + break; + case LEDFeedbackMode::PEER_CONNECTED_BLE: + { + configurePeerConnectedMode(); #ifdef BOARD_HAS_LED_MATRIX ledMatrixAnimationHandler.loadFrame(bluetooth); _framePtr = (uint32_t*)bluetooth; #endif - _ledChangeInterval = ALWAYS_ON_INTERVAL; + } + break; + case LEDFeedbackMode::PEER_CONNECTED_SERIAL: + { + configurePeerConnectedMode(); + #ifdef BOARD_HAS_LED_MATRIX + ledMatrixAnimationHandler.loadFrame(usb_image); + _framePtr = (uint32_t*)usb_image; + #endif } break; case LEDFeedbackMode::CONNECTING_TO_NETWORK: @@ -348,4 +358,14 @@ void LEDFeedbackClass::turnON() { _ledState = true; } +void LEDFeedbackClass::configurePeerConnectedMode() { + #ifdef BOARD_HAS_RGB + turnOFF(); + _ledPin = BLUE_LED; + #else + _ledPin = GREEN_LED; + #endif + _ledChangeInterval = ALWAYS_ON_INTERVAL; +} + #endif // NETWORK_CONFIGURATOR_COMPATIBLE diff --git a/src/utility/LEDFeedback.h b/src/utility/LEDFeedback.h index 2360e04..46d08ba 100644 --- a/src/utility/LEDFeedback.h +++ b/src/utility/LEDFeedback.h @@ -16,6 +16,8 @@ class LEDFeedbackClass { NONE, BLE_AVAILABLE, PEER_CONNECTED, + PEER_CONNECTED_BLE, + PEER_CONNECTED_SERIAL, CONNECTING_TO_NETWORK, CONNECTED_TO_CLOUD, ERROR @@ -30,6 +32,7 @@ class LEDFeedbackClass { LEDFeedbackClass() {}; void turnON(); void turnOFF(); + void configurePeerConnectedMode(); LEDFeedbackMode _mode = LEDFeedbackMode::NONE; uint32_t _lastUpdate = 0; uint32_t _count = 0;