Separate library that holds helper functions for the main OMF code.

Committer:
danielelopez
Date:
Mon Jun 25 21:09:08 2018 +0000
Revision:
18:c6c9cce5d990
Parent:
16:3b0bdbfa48ff
Used #def statements to remove if statements from code; edited NTP timestamp and timestamp functions in the OMF lib to optimize code; added SSL cert for the new AWS VM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danielelopez 14:6ed67a160616 1 //Copyright 2018 OSIsoft, LLC
danielelopez 0:6156b29d3c91 2 //
danielelopez 0:6156b29d3c91 3 //Licensed under the Apache License, Version 2.0 (the "License");
danielelopez 0:6156b29d3c91 4 //you may not use this file except in compliance with the License.
danielelopez 0:6156b29d3c91 5 //You may obtain a copy of the License at
danielelopez 0:6156b29d3c91 6 //
danielelopez 0:6156b29d3c91 7 //<http://www.apache.org/licenses/LICENSE-2.0>
danielelopez 0:6156b29d3c91 8 //
danielelopez 0:6156b29d3c91 9 //Unless required by applicable law or agreed to in writing, software
danielelopez 0:6156b29d3c91 10 //distributed under the License is distributed on an "AS IS" BASIS,
danielelopez 0:6156b29d3c91 11 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
danielelopez 0:6156b29d3c91 12 //See the License for the specific language governing permissions and
danielelopez 0:6156b29d3c91 13 //limitations under the License.
danielelopez 0:6156b29d3c91 14
danielelopez 0:6156b29d3c91 15 #ifndef OSISOFT_OMF_H
danielelopez 0:6156b29d3c91 16 #define OSISOFT_OMF_H
danielelopez 0:6156b29d3c91 17
danielelopez 0:6156b29d3c91 18 #include "mbed.h"
danielelopez 0:6156b29d3c91 19 #include "https_request.h"
danielelopez 8:e5fe40b77f8f 20 #include "config.deviceID.h"
danielelopez 0:6156b29d3c91 21
danielelopez 16:3b0bdbfa48ff 22 // ************************************************************************
danielelopez 18:c6c9cce5d990 23 // Constants used to disable printing
danielelopez 18:c6c9cce5d990 24 #define DO_NOT_ENABLE_PRINTOUTS 0
danielelopez 18:c6c9cce5d990 25 #define YES_ENABLE_PRINTOUTS 1
danielelopez 18:c6c9cce5d990 26
danielelopez 18:c6c9cce5d990 27 // Select one of the above options
danielelopez 18:c6c9cce5d990 28 #define ENABLE_PRINTOUTS YES_ENABLE_PRINTOUTS
danielelopez 16:3b0bdbfa48ff 29 // ************************************************************************
danielelopez 16:3b0bdbfa48ff 30
danielelopez 10:844e209f1d79 31 // Automatically generated OMF-SPECIFIC CONSTANTS
danielelopez 10:844e209f1d79 32 // Similarly, specify the name of for the data values type; this should likewise be unique
danielelopez 10:844e209f1d79 33 // for each general class of IoT device--for example, if you were running this script on two different devices,
danielelopez 10:844e209f1d79 34 // each with different numbers and kinds of sensors, you would specify a different data values message type name
danielelopez 10:844e209f1d79 35 // when running the script on each device. If both devices were the same, you could use the same data_values_message_type_name
danielelopez 10:844e209f1d79 36 const string DATA_VALUES_MESSAGE_TYPE_NAME = DEVICE_TYPE + "_data_values_type";
danielelopez 10:844e209f1d79 37
danielelopez 10:844e209f1d79 38 // The unique device name will also be used as part of the container id used to send live data values
danielelopez 10:844e209f1d79 39 const string DATA_VALUES_CONTAINER_ID = DEVICE_NAME + "_data_values_container";
danielelopez 10:844e209f1d79 40
danielelopez 10:844e209f1d79 41 // The device type will also be used for the asset type constant as well
danielelopez 10:844e209f1d79 42 const string ASSETS_MESSAGE_TYPE_NAME = DEVICE_TYPE + "_asset_type";
danielelopez 10:844e209f1d79 43
danielelopez 10:844e209f1d79 44 // Constants used for setting headers when sending OMF messages
danielelopez 10:844e209f1d79 45 const string OMF_VERSION = "1.0";
danielelopez 10:844e209f1d79 46 const string OMF_MESSAGE_FORMAT = "JSON";
danielelopez 10:844e209f1d79 47 const string CONTENT_TYPE = "application/json";
danielelopez 10:844e209f1d79 48
danielelopez 0:6156b29d3c91 49 // ************************************************************************
danielelopez 0:6156b29d3c91 50 // Helper function that casts floats into strings
danielelopez 0:6156b29d3c91 51 // ************************************************************************
danielelopez 0:6156b29d3c91 52
danielelopez 0:6156b29d3c91 53 string OMFLib_float_to_string(float f);
danielelopez 0:6156b29d3c91 54
danielelopez 0:6156b29d3c91 55 // ************************************************************************
danielelopez 0:6156b29d3c91 56 // Helper function that sends an actual web request
danielelopez 0:6156b29d3c91 57 // ************************************************************************
danielelopez 0:6156b29d3c91 58
danielelopez 0:6156b29d3c91 59 void OMFLib_sendMessageToEndpoint(TLSSocket* socket, const char* action, const char* message_type, const char* body);
danielelopez 0:6156b29d3c91 60
danielelopez 0:6156b29d3c91 61 // ************************************************************************
danielelopez 1:1c31b413ba0c 62 // Helper function that sends an actual web request; does not reuse sockets
danielelopez 1:1c31b413ba0c 63 // ************************************************************************
danielelopez 1:1c31b413ba0c 64
danielelopez 1:1c31b413ba0c 65 void OMFLib_sendMessageToEndpoint_NoSocketReuse(NetworkInterface* network, const char* action, const char* message_type, const char* body);
danielelopez 1:1c31b413ba0c 66
danielelopez 1:1c31b413ba0c 67 // ************************************************************************
danielelopez 1:1c31b413ba0c 68 // Helper function: prints out an HTTP response
danielelopez 1:1c31b413ba0c 69 // ************************************************************************
danielelopez 1:1c31b413ba0c 70
danielelopez 1:1c31b413ba0c 71 void OMFLib_dump_response(HttpResponse* res);
danielelopez 1:1c31b413ba0c 72
danielelopez 1:1c31b413ba0c 73 // ************************************************************************
danielelopez 0:6156b29d3c91 74 // Gets the current time in the appropriate OMF format
danielelopez 0:6156b29d3c91 75 // ************************************************************************
danielelopez 0:6156b29d3c91 76
danielelopez 0:6156b29d3c91 77 string OMFLib_getCurrentTimeString();
danielelopez 0:6156b29d3c91 78
danielelopez 0:6156b29d3c91 79 // ************************************************************************
danielelopez 0:6156b29d3c91 80 // Sets the clock via NTP via the nwtwork
danielelopez 0:6156b29d3c91 81 // ************************************************************************
danielelopez 0:6156b29d3c91 82
danielelopez 0:6156b29d3c91 83 void OMFLib_syncClockViaNTP(NetworkInterface* network);
danielelopez 15:32ada27d82b4 84
danielelopez 15:32ada27d82b4 85 // ************************************************************************
danielelopez 15:32ada27d82b4 86 // Sends the dynamic types, static types, assets, and links messages
danielelopez 15:32ada27d82b4 87 // Uses the SEND_ASSETS_AND_LINKS flag found in config.egressSettings and
danielelopez 15:32ada27d82b4 88 // Uses the custom OMF JSON found in config.customOMFJSONStructures.h
danielelopez 15:32ada27d82b4 89 // ************************************************************************
danielelopez 15:32ada27d82b4 90
danielelopez 15:32ada27d82b4 91 void OMFLib_sendInitialOMFMessages(NetworkInterface* __network_interface);
danielelopez 10:844e209f1d79 92
danielelopez 10:844e209f1d79 93 #endif