LoomInternetPlat class

Abstract internet communication module.

All internet modules inherit from this class.

Base classes

class LoomModule
Abstract root of Loom component modules inheritance hierarchy.

Derived classes

class Loom_Ethernet
InternetPlat built off of SSLClient running over an Ethernet Featherwing.
class Loom_LTE
LTE InternetPlat.
class Loom_WiFi
WiFi InternetPlat.

Public types

struct ClientCleanup
Simply close the socket when the client dissapears, we don't want to delete the object because the client needs to cache sessions.
struct UDPDeletor
Close the socket and delete the UDP object when the unique ptr dissapears.

Protected functions

void write_http_request(Stream& client, const char* domain, const char* url, const char* body, const char* verb)
Utility function to write an http reqest based on parameters specified by LoomInternetPlat::http_request to a Client class.
auto get_client() -> SSLClient& pure virtual
Get the underlying SSLClient implementation, which we will use for all of the other requests.

TYPES

using UDPPtr = std::unique_ptr<UDP, UDPDeletor>
Cleaner name for UDP smart pointer.
using ClientSession = std::unique_ptr<Client, ClientCleanup>
Cleaner name for Client smart pointer.

CONSTRUCTORS / DESTRUCTOR

LoomInternetPlat(LoomManager* manager, const char* module_name, const LoomModule::Type module_type)
Loom Internet Platform module constructor.
~LoomInternetPlat() defaulted virtual
Destructor.

OPERATION

void package(JsonObject json) override
No package necessary for internet platforms.
auto http_request(const char* domain, const char* url, const char* body, const char* verb) -> ClientSession virtual
Make HTTP request.
auto http_get_request(const char* domain, const char* url, const char* body = nullptr) -> ClientSession
Make HTTP GET request.
auto http_post_request(const char* domain, const char* url, const char* body = nullptr) -> ClientSession
Make HTTP POST request.
auto connect_to_domain(const char* domain) -> ClientSession virtual
Connect to a domain, but don't write any HTTP stuff, Let the module figure that out.
auto connect_to_ip(const IPAddress& ip, const uint16_t port) -> ClientSession virtual
Connect to a domain, but don't write any HTTP stuff, Let the module figure that out.
auto open_socket(const uint port) -> UDPPtr pure virtual
Open a UDP socket for sending and recieving incoming data.
auto get_time() -> uint32_t
make NTP request to get UTC time, using the UDP function above

Function documentation

void LoomInternetPlat::write_http_request(Stream& client, const char* domain, const char* url, const char* body, const char* verb) protected

Utility function to write an http reqest based on parameters specified by LoomInternetPlat::http_request to a Client class.

See http_request() for parameter details.

LoomInternetPlat::LoomInternetPlat(LoomManager* manager, const char* module_name, const LoomModule::Type module_type)

Loom Internet Platform module constructor.

Parameters
manager
module_name in String | <"Internet-Plat"> | null | Internet Platform module name
module_type

void LoomInternetPlat::package(JsonObject json) override

No package necessary for internet platforms.

implement with empty body.

ClientSession LoomInternetPlat::http_request(const char* domain, const char* url, const char* body, const char* verb) virtual

Make HTTP request.

Parameters
domain in The domain to connect to (e.g "www.google.com")
url in The URL string to send with the http request, not including the domain (ex. "/arduino?thing=otherthing").
body in The body string to use for the rest of the request, including additional headers. Will be appended directly to the request (right after the last header appended by the library) and will need newlines at the top or between additional headers and body. Example: "some-header: thing\r\nsome-other-header:29\r\n\r\n{\"my-json-body":"nice"}" adds two headers (some-header and some-other-header) and has a simple JSON body. Can be nullptr for none.
verb in HTTP verb ("PUT", "GET", etc.) to use with this request.
Returns A client session pointer, or a nullptr if the connection failed. When this pointer is destroyed the client will automatically close the connection.

ClientSession LoomInternetPlat::http_get_request(const char* domain, const char* url, const char* body = nullptr)

Make HTTP GET request.

See http_request() for parameter and return details.

ClientSession LoomInternetPlat::http_post_request(const char* domain, const char* url, const char* body = nullptr)

Make HTTP POST request.

See http_request() for parameter and return details.

ClientSession LoomInternetPlat::connect_to_domain(const char* domain) virtual

Connect to a domain, but don't write any HTTP stuff, Let the module figure that out.

Parameters
domain in The domain to connect to "www.google.com"
Returns A client reference. The client::connected method will return true if the connection succeeded, and false otherwise.

ClientSession LoomInternetPlat::connect_to_ip(const IPAddress& ip, const uint16_t port) virtual

Connect to a domain, but don't write any HTTP stuff, Let the module figure that out.

Parameters
ip in The IPAddress to connect to
port in The port to connect to
Returns A client reference. The client::connected method will return true if the connection succeeded, and false otherwise.

UDPPtr LoomInternetPlat::open_socket(const uint port) pure virtual

Open a UDP socket for sending and recieving incoming data.

Returns A UDP socket for transmitting and recieving, or a nullptr if opening the socket failed. The socket will automatically close when the pointer is destructed.

uint32_t LoomInternetPlat::get_time()

make NTP request to get UTC time, using the UDP function above

Returns a unix timestamp if success, or 0 if failure.