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 fc308b2..1e8e09b 100644 --- a/src/storage/storage_inventory.cpp +++ b/src/storage/storage_inventory.cpp @@ -86,7 +86,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); @@ -188,6 +189,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 bcdc81b..2442c10 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);