This sample shows how to read server items via the connection API over a BAOS secure TCP connection
This connection is supported by devices with protcol version >= 2.2. e.g. BAOS 774.1 or BAOS 777.1.
NOTE: The password is passed as second positional command line argument.
#include "Helper.h"
#include <wzcpp/features/utils.h>
#include <iostream>
using namespace wz::baos::ip;
namespace
{
std::string decodeServerItem_string(const ServerItem& serverItem)
{
return std::string(serverItem.data.begin(), serverItem.data.end());
}
}
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "BaosSecureTcpConnection sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
CommandLineOptions options;
options.setSecureSampleOptionSupported(true);
options.parse(argc, argv);
if (options.wasHelpdisplayed())
{
return 0;
}
const std::string ipAddress = options.getIpAddress();
std::cout << " Connection requested for " << ipAddress << std::endl;
const std::string password = options.getPassword();
const auto passwordHash = BaosSecureTcpConnection::calculatePasswordHash(password);
BaosSecureTcpConnection connection;
connection.open(ipAddress, passwordHash);
auto serverItem = connection.getServerItem(ServerItemId::DeviceFriendlyName);
if (serverItem.has_value())
{
std::cout << "Device friendly name: " << decodeServerItem_string(*serverItem) << std::endl;
}
else
{
std::cerr << "Unable to get serveritem ServerItemId::DeviceFriendlyName" << std::endl;
}
for (std::uint32_t index = 0; index < 100; ++index)
{
std::cout << "Reading datapoint value id 2:" << std::endl;
auto valueState = connection.getDpValue(2);
if (valueState.has_value())
{
std::cout << "Id: 2, value: ";
std::cout << std::endl;
}
}
}
catch (const std::exception& e)
{
std::cerr << "Failed: " << e.what() << std::endl;
return -1;
}
return 0;
}
Specialization for a TCP IP v4 BAOSConnection.
Global BAOS protocol defines and types.
Global BAOS SDK function and options.
Groups BAOS binary protocol specific types , defines and classes for Indications, Responses etc.
Definition: Defines.h:33
Global BAOS sdk namespace.
Definition: config.h:69
BAOSLIB_EXPORT void setBaosLogLevel(wz::baos::LogLevel level)