Fixing discovery.

This commit is contained in:
stephb9959
2021-09-29 09:03:43 -07:00
parent 5e5e35f6c9
commit e8c2d3ad37
3 changed files with 11 additions and 4 deletions

2
build
View File

@@ -1 +1 @@
224
226

View File

@@ -6,6 +6,8 @@
#include "uCentralProtocol.h"
#include "KafkaManager.h"
#include "Kafka_topics.h"
#include "storage_inventory.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -49,14 +51,15 @@ namespace OpenWifi {
if( PingMessage->has(uCentralProtocol::FIRMWARE) &&
PingMessage->has(uCentralProtocol::SERIALNUMBER) &&
PingMessage->has(uCentralProtocol::COMPATIBLE)) {
if(PayloadObj->has(uCentralProtocol::CONNECTIONIP) )
ConnectedIP = PayloadObj->get(uCentralProtocol::CONNECTIONIP).toString();
if(PingMessage->has(uCentralProtocol::CONNECTIONIP) )
ConnectedIP = PingMessage->get(uCentralProtocol::CONNECTIONIP).toString();
SerialNumber = PingMessage->get( uCentralProtocol::SERIALNUMBER).toString();
DeviceType = PingMessage->get( uCentralProtocol::COMPATIBLE).toString();
}
}
if(!SerialNumber.empty()) {
std::cout << "SerialNUmber: " << SerialNumber << " CID: " << ConnectedIP << " DeviceType: " << DeviceType << std::endl;
Storage()->InventoryDB().CreateFromInventory(SerialNumber,ConnectedIP,DeviceType);
}
}
} catch (const Poco::Exception &E) {

View File

@@ -61,6 +61,10 @@ namespace OpenWifi {
uint64_t Now = std::time(nullptr);
auto Tokens = Poco::StringTokenizer(ConnectionInfo,"@:");
std::string IP;
if(Tokens.count()==3) {
IP = Tokens[1];
}
NewDevice.info.id = Daemon()->CreateUUID();
NewDevice.info.name = SerialNumber;
@@ -70,7 +74,7 @@ namespace OpenWifi {
NewDevice.deviceType = DeviceType;
if(CreateRecord(NewDevice)) {
std::cout << "Added " << SerialNumber << " to DB with IP=" << Tokens[1] << std::endl;
std::cout << "Added " << SerialNumber << " to DB with IP=" << IP << std::endl;
Logger().information(Poco::format("Adding %s to inventory.",SerialNumber));
return true;
} else {