Separate library that holds helper functions for the main OMF code.
osisoft-omf.h@15:32ada27d82b4, 2018-05-30 (annotated)
- Committer:
- danielelopez
- Date:
- Wed May 30 15:24:45 2018 +0000
- Revision:
- 15:32ada27d82b4
- Parent:
- 14:6ed67a160616
- Child:
- 16:3b0bdbfa48ff
Added function that sends along all initial OMF messages (static and dynamic types, assets, and links) as a single function
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:844e209f1d79 | 22 | // Automatically generated OMF-SPECIFIC CONSTANTS |
danielelopez | 10:844e209f1d79 | 23 | // Similarly, specify the name of for the data values type; this should likewise be unique |
danielelopez | 10:844e209f1d79 | 24 | // for each general class of IoT device--for example, if you were running this script on two different devices, |
danielelopez | 10:844e209f1d79 | 25 | // each with different numbers and kinds of sensors, you would specify a different data values message type name |
danielelopez | 10:844e209f1d79 | 26 | // 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 | 27 | const string DATA_VALUES_MESSAGE_TYPE_NAME = DEVICE_TYPE + "_data_values_type"; |
danielelopez | 10:844e209f1d79 | 28 | |
danielelopez | 10:844e209f1d79 | 29 | // The unique device name will also be used as part of the container id used to send live data values |
danielelopez | 10:844e209f1d79 | 30 | const string DATA_VALUES_CONTAINER_ID = DEVICE_NAME + "_data_values_container"; |
danielelopez | 10:844e209f1d79 | 31 | |
danielelopez | 10:844e209f1d79 | 32 | // The device type will also be used for the asset type constant as well |
danielelopez | 10:844e209f1d79 | 33 | const string ASSETS_MESSAGE_TYPE_NAME = DEVICE_TYPE + "_asset_type"; |
danielelopez | 10:844e209f1d79 | 34 | |
danielelopez | 10:844e209f1d79 | 35 | // Constants used for setting headers when sending OMF messages |
danielelopez | 10:844e209f1d79 | 36 | const string OMF_VERSION = "1.0"; |
danielelopez | 10:844e209f1d79 | 37 | const string OMF_MESSAGE_FORMAT = "JSON"; |
danielelopez | 10:844e209f1d79 | 38 | const string CONTENT_TYPE = "application/json"; |
danielelopez | 10:844e209f1d79 | 39 | |
danielelopez | 0:6156b29d3c91 | 40 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 41 | // Helper function that casts floats into strings |
danielelopez | 0:6156b29d3c91 | 42 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 43 | |
danielelopez | 0:6156b29d3c91 | 44 | string OMFLib_float_to_string(float f); |
danielelopez | 0:6156b29d3c91 | 45 | |
danielelopez | 0:6156b29d3c91 | 46 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 47 | // Helper function that sends an actual web request |
danielelopez | 0:6156b29d3c91 | 48 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 49 | |
danielelopez | 0:6156b29d3c91 | 50 | void OMFLib_sendMessageToEndpoint(TLSSocket* socket, const char* action, const char* message_type, const char* body); |
danielelopez | 0:6156b29d3c91 | 51 | |
danielelopez | 0:6156b29d3c91 | 52 | // ************************************************************************ |
danielelopez | 1:1c31b413ba0c | 53 | // Helper function that sends an actual web request; does not reuse sockets |
danielelopez | 1:1c31b413ba0c | 54 | // ************************************************************************ |
danielelopez | 1:1c31b413ba0c | 55 | |
danielelopez | 1:1c31b413ba0c | 56 | void OMFLib_sendMessageToEndpoint_NoSocketReuse(NetworkInterface* network, const char* action, const char* message_type, const char* body); |
danielelopez | 1:1c31b413ba0c | 57 | |
danielelopez | 1:1c31b413ba0c | 58 | // ************************************************************************ |
danielelopez | 1:1c31b413ba0c | 59 | // Helper function: prints out an HTTP response |
danielelopez | 1:1c31b413ba0c | 60 | // ************************************************************************ |
danielelopez | 1:1c31b413ba0c | 61 | |
danielelopez | 1:1c31b413ba0c | 62 | void OMFLib_dump_response(HttpResponse* res); |
danielelopez | 1:1c31b413ba0c | 63 | |
danielelopez | 1:1c31b413ba0c | 64 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 65 | // Gets the current time in the appropriate OMF format |
danielelopez | 0:6156b29d3c91 | 66 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 67 | |
danielelopez | 0:6156b29d3c91 | 68 | string OMFLib_getCurrentTimeString(); |
danielelopez | 0:6156b29d3c91 | 69 | |
danielelopez | 0:6156b29d3c91 | 70 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 71 | // Sets the clock via NTP via the nwtwork |
danielelopez | 0:6156b29d3c91 | 72 | // ************************************************************************ |
danielelopez | 0:6156b29d3c91 | 73 | |
danielelopez | 0:6156b29d3c91 | 74 | void OMFLib_syncClockViaNTP(NetworkInterface* network); |
danielelopez | 15:32ada27d82b4 | 75 | |
danielelopez | 15:32ada27d82b4 | 76 | // ************************************************************************ |
danielelopez | 15:32ada27d82b4 | 77 | // Sends the dynamic types, static types, assets, and links messages |
danielelopez | 15:32ada27d82b4 | 78 | // Uses the SEND_ASSETS_AND_LINKS flag found in config.egressSettings and |
danielelopez | 15:32ada27d82b4 | 79 | // Uses the custom OMF JSON found in config.customOMFJSONStructures.h |
danielelopez | 15:32ada27d82b4 | 80 | // ************************************************************************ |
danielelopez | 15:32ada27d82b4 | 81 | |
danielelopez | 15:32ada27d82b4 | 82 | void OMFLib_sendInitialOMFMessages(NetworkInterface* __network_interface); |
danielelopez | 10:844e209f1d79 | 83 | |
danielelopez | 10:844e209f1d79 | 84 | #endif |