Skip to content

Commit

Permalink
Merge pull request #97 from kinarasystems/wifi_13519_fix_venue_propag…
Browse files Browse the repository at this point in the history
…ation

WIFI-13519 Fix: propagation of venue
  • Loading branch information
stephb9959 authored Mar 20, 2024
2 parents da015b2 + a619c0d commit 8fc7ce7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/AutoDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -83,6 +85,7 @@ namespace OpenWifi {
Poco::JSON::Parser Parser;
auto Object = Parser.parse(Msg->Payload()).extract<Poco::JSON::Object::Ptr>();
bool Connected=true;
bool isConnection=false;

if (Object->has(uCentralProtocol::PAYLOAD)) {
auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD);
Expand All @@ -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
Expand All @@ -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) {
Expand Down
25 changes: 24 additions & 1 deletion src/storage/storage_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/storage/storage_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8fc7ce7

Please sign in to comment.