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

Committer:
danielelopez
Date:
Wed May 30 18:04:26 2018 +0000
Revision:
16:3b0bdbfa48ff
Parent:
15:32ada27d82b4
Child:
18:c6c9cce5d990
Added flag for turning printouts on or off

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