From a619c0dbe11fd19c5f0d706b822450c3de644248 Mon Sep 17 00:00:00 2001 From: Adam Capparelli Date: Mon, 11 Mar 2024 16:49:35 -0400 Subject: [PATCH] Fix bug where process capabilities does not update serial number, bug where venue is not updated in GW for pre-provisioned device on capability event. (#8) Signed-off-by: Adam Capparelli Co-authored-by: Adam Capparelli --- src/AutoDiscovery.cpp | 6 +++++- src/storage/storage_inventory.cpp | 25 ++++++++++++++++++++++++- src/storage/storage_inventory.h | 3 ++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/AutoDiscovery.cpp b/src/AutoDiscovery.cpp index be9e6bc..b6ec3f8 100644 --- a/src/AutoDiscovery.cpp +++ b/src/AutoDiscovery.cpp @@ -54,6 +54,8 @@ namespace OpenWifi { FW = P->get(uCentralProtocol::FIRMWARE).toString(); if (P->has(uCentralProtocol::SERIALNUMBER)) SN = P->get(uCentralProtocol::SERIALNUMBER).toString(); + else if (P->has(uCentralProtocol::SERIAL)) + SN = P->get(uCentralProtocol::SERIAL).toString(); if (P->has("locale")) { locale = P->get("locale").toString(); } @@ -83,6 +85,7 @@ namespace OpenWifi { Poco::JSON::Parser Parser; auto Object = Parser.parse(Msg->Payload()).extract(); bool Connected=true; + bool isConnection=false; if (Object->has(uCentralProtocol::PAYLOAD)) { auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD); @@ -91,6 +94,7 @@ namespace OpenWifi { auto PingObj = PayloadObj->getObject("ping"); ProcessPing(PingObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); } else if(PayloadObj->has("capabilities")) { + isConnection=true; ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); } else if(PayloadObj->has("disconnection")) { // we ignore disconnection in provisioning @@ -102,7 +106,7 @@ namespace OpenWifi { if (!SerialNumber.empty() && Connected) { StorageService()->InventoryDB().CreateFromConnection( - SerialNumber, ConnectedIP, Compatible, Locale); + SerialNumber, ConnectedIP, Compatible, Locale, isConnection); } } } catch (const Poco::Exception &E) { diff --git a/src/storage/storage_inventory.cpp b/src/storage/storage_inventory.cpp index b9bfd09..80a4509 100644 --- a/src/storage/storage_inventory.cpp +++ b/src/storage/storage_inventory.cpp @@ -80,7 +80,8 @@ namespace OpenWifi { bool InventoryDB::CreateFromConnection(const std::string &SerialNumberRaw, const std::string &ConnectionInfo, const std::string &DeviceType, - const std::string &Locale) { + const std::string &Locale, + const bool isConnection) { ProvObjects::InventoryTag ExistingDevice; auto SerialNumber = Poco::toLower(SerialNumberRaw); @@ -179,6 +180,28 @@ namespace OpenWifi { StorageService()->InventoryDB().UpdateRecord("id", ExistingDevice.info.id, ExistingDevice); } + + // Push entity and venue down to GW but only on connect (not ping) + if (isConnection && !ExistingDevice.venue.empty()) { + if (SDK::GW::Device::SetVenue(nullptr, ExistingDevice.serialNumber, ExistingDevice.venue)) { + Logger().information(Poco::format("%s: GW set venue property.", + ExistingDevice.serialNumber)); + } else { + Logger().information(Poco::format( + "%s: could not set GW venue property.", ExistingDevice.serialNumber)); + } + } + + if (isConnection && !ExistingDevice.entity.empty()) { + if (SDK::GW::Device::SetEntity(nullptr, ExistingDevice.serialNumber, ExistingDevice.entity)) { + Logger().information(Poco::format("%s: GW set entity property.", + ExistingDevice.serialNumber)); + } else { + Logger().information(Poco::format( + "%s: could not set GW entity property.", ExistingDevice.serialNumber)); + } + } + } return false; } diff --git a/src/storage/storage_inventory.h b/src/storage/storage_inventory.h index e5750c0..6ed536d 100644 --- a/src/storage/storage_inventory.h +++ b/src/storage/storage_inventory.h @@ -25,7 +25,8 @@ namespace OpenWifi { virtual ~InventoryDB(){}; bool CreateFromConnection(const std::string &SerialNumber, const std::string &ConnectionInfo, const std::string &DeviceType, - const std::string &Locale); + const std::string &Locale, + const bool isConnection); void InitializeSerialCache(); bool GetRRMDeviceList(Types::UUIDvec_t &DeviceList);