Fledge
An open source edge computing platform for industrial users
piwebapi.h
1 #ifndef _PIWEBAPI_H
2 #define _PIWEBAPI_H
3 /*
4  * Fledge OSIsoft PI Web API integration.
5  *
6  * Copyright (c) 2020-2022 Dianomic Systems
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Stefano Simonelli
11  */
12 
13 #include <string>
14 
15 using namespace std;
16 
17 #define TIMEOUT_CONNECT 10
18 #define TIMEOUT_REQUEST 10
19 #define RETRY_SLEEP_TIME 1
20 #define MAX_RETRY 3
21 
22 #define URL_GET_VERSION "/piwebapi/system"
23 
27 class PIWebAPI
28 {
29  public:
30  PIWebAPI();
31 
32 
33  // Destructor
34  ~PIWebAPI();
35 
36  void setAuthMethod (std::string& authMethod) {m_authMethod = authMethod; }
37  void setAuthBasicCredentials(std::string& authBasicCredentials) {m_authBasicCredentials = authBasicCredentials; }
38 
39  int GetVersion(const string& host, string &version, bool logMessage = true);
40  string errorMessageHandler(const string& msg);
41 
42  private:
43  string ExtractVersion(const string& response);
44  string extractSection(const string& msg, const string& toSearch);
45  string extractMessageFromJSon(const string& json);
46 
47  string m_authMethod; // Authentication method to be used
48  string m_authBasicCredentials; // Credentials is the base64 encoding of id and password joined by a single colon (:)
49 
50  // Substitute a message with a different one
51  const vector<pair<string, string>> PIWEB_ERRORS = {
52  // original message New one
53  {"Noroutetohost", "The PI Web API server is not reachable, verify the network reachability"},
54  {"No route to host", "The PI Web API server is not reachable, verify the network reachability"},
55  };
56 
57 
58 };
59 #endif
Definition: asset_tracking.h:108
The PIWebAPI class.
Definition: piwebapi.h:27