Loom
Classes | Protected Member Functions | List of all members
LoomInternetPlat Class Referenceabstract

Abstract internet communication module. More...

#include <InternetPlat.h>

Inheritance diagram for LoomInternetPlat:
Inheritance graph
[legend]

Classes

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. More...
 
struct  UDPDeletor
 Close the socket and delete the UDP object when the unique ptr dissapears. More...
 

Public Types

TYPES
using UDPPtr = std::unique_ptr< UDP, UDPDeletor >
 Cleaner name for UDP smart pointer. More...
 
using ClientSession = std::unique_ptr< Client, ClientCleanup >
 Cleaner name for Client smart pointer. More...
 
- Public Types inherited from LoomModule
enum  Type {
  Type::Unknown = 0, Type::Other =1000, Type::Interrupt_Manager, Type::Sleep_Manager,
  Type::Multiplexer, Type::NTP, Type::TempSync, Type::WarmUp_Manager,
  Type::Sensor =2000, Type::Analog, Type::Digital, Type::I2C =2100,
  Type::ADS1115, Type::AS7262, Type::AS7263, Type::AS7265X,
  Type::FXAS21002, Type::FXOS8700, Type::LIS3DH, Type::MB1232,
  Type::MMA8451, Type::MPU6050, Type::MS5803, Type::SHT31D,
  Type::TMP007, Type::TSL2561, Type::TSL2591, Type::ZXGesture,
  Type::STEMMA, Type::SDI12 =2200, Type::Decagon5TM, Type::DecagonGS3,
  Type::SPI =2300, Type::MAX31855, Type::MAX31856, Type::L_SERIAL =2400,
  Type::K30, Type::L_RTC =3000, Type::DS3231, Type::PCF8523,
  Type::Actuator =4000, Type::Neopixel, Type::Relay, Type::Servo,
  Type::Stepper, Type::LogPlat =5000, Type::OLED, Type::SDCARD,
  Type::BATCHSD, Type::CommPlat =6000, Type::LoRa, Type::nRF,
  Type::Bluetooth, Type::InternetPlat =7000, Type::Ethernet, Type::WiFi,
  Type::LTE, Type::PublishPlat =8000, Type::GoogleSheets, Type::MaxPub,
  Type::SpoolPub, Type::SubscribePlats =9000, Type::MaxSub
}
 Enum to check against to when finding individual component managed by a LoomManager. More...
 
enum  Category {
  Category::Unknown =0, Category::Other =1, Category::Sensor =2, Category::L_RTC =3,
  Category::Actuator =4, Category::LogPlat =5, Category::CommPlat =6, Category::InternetPlat =7,
  Category::PublishPlat =8, Category::SubscribePlat =9
}
 Enum to classify modules. More...
 

Public Member Functions

CONSTRUCTORS / DESTRUCTOR
 LoomInternetPlat (LoomManager *manager, const char *module_name, const LoomModule::Type module_type)
 Loom Internet Platform module constructor. More...
 
virtual ~LoomInternetPlat ()=default
 Destructor. More...
 
- Public Member Functions inherited from LoomModule
 LoomModule (LoomManager *manager, const char *module_name="Unknown", const Type module_type=Type::Unknown)
 Constructor. More...
 
virtual ~LoomModule ()=default
 Destructor. More...
 
virtual void second_stage_ctor ()
 Second stage construction. More...
 
virtual bool dispatch (JsonObject json)
 Route command to driver. More...
 
virtual void power_down ()
 Turn off any hardware. More...
 
virtual void power_up ()
 Turn on any hardware. More...
 
virtual void add_config (JsonObject json)
 Add configuration information to JsonObject. More...
 
Type get_module_type () const
 Get module type. More...
 
LoomManagerget_device_manager () const
 Get the device manager class if linked. More...
 
void get_module_name (char *buf) const
 Copy module name into buffer. More...
 
const char * get_module_name () const
 Get module name. More...
 
Verbosity get_print_verbosity () const
 Get print verbosity. More...
 
Verbosity get_package_verbosity () const
 Get package verbosity. More...
 
bool get_active () const
 Get whether or not the module should be treated as active. More...
 
Category category () const
 Get the category of the module. More...
 
virtual void link_device_manager (LoomManager *LM)
 Add pointer back to device manager. More...
 
void set_print_verbosity (const Verbosity v)
 Set print verbosity Controlls level of detail included in debug prints. More...
 
void set_package_verbosity (const Verbosity v)
 Set package verbosity. More...
 
void set_active (const bool enable)
 Set whether or not the module should be treated as active. More...
 
virtual void print_config () const
 Display the configuration settings of the module. More...
 
virtual void print_state () const
 Display current state of the module. More...
 

Protected Member 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. More...
 
virtual SSLClient & get_client ()=0
 Get the underlying SSLClient implementation, which we will use for all of the other requests. More...
 
virtual const SSLClient & get_client () const =0
 
- Protected Member Functions inherited from LoomModule
void print_module_label () const
 Print the module name as a label. More...
 

OPERATION

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

Additional Inherited Members

- Static Public Member Functions inherited from LoomModule
static const char * enum_verbosity_string (const Verbosity v)
 Get string of name associated with verbosity enum. More...
 
static const char * enum_category_string (const Category c)
 Get string of the category associated with a Category. More...
 
- Protected Attributes inherited from LoomModule
const Type module_type
 Module type. More...
 
LoomManagerdevice_manager
 Pointer to manager. More...
 
const String module_name_base
 The name of the module (Should have a DEFAULT but can be overriden if provided to constructor) More...
 
const char * module_name
 
bool active
 Whether or not the module should be treated as active. More...
 
Verbosity print_verbosity
 Print verbosity. More...
 
Verbosity package_verbosity
 Package verbosity. More...
 

Detailed Description

Abstract internet communication module.

All internet modules inherit from this class.

Resources

Member Typedef Documentation

using LoomInternetPlat::ClientSession = std::unique_ptr<Client, ClientCleanup>

Cleaner name for Client smart pointer.

using LoomInternetPlat::UDPPtr = std::unique_ptr<UDP, UDPDeletor>

Cleaner name for UDP smart pointer.

Constructor & Destructor Documentation

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

Loom Internet Platform module constructor.

Parameters
[in]module_nameString | <"Internet-Plat"> | null | Internet Platform module name
virtual LoomInternetPlat::~LoomInternetPlat ( )
virtualdefault

Destructor.

Member Function Documentation

virtual void LoomInternetPlat::connect ( )
pure virtual

Implemented in Loom_LTE, Loom_Ethernet, and Loom_WiFi.

LoomInternetPlat::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.

Attention
Remember to close the socket!
Parameters
[in]domainThe 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.
LoomInternetPlat::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.

Attention
Remember to close the socket!
Parameters
[in]ipThe IPAddress to connect to
[in]portThe port to connect to
Returns
A client reference. The client::connected method will return true if the connection succeeded, and false otherwise.
virtual void LoomInternetPlat::disconnect ( )
inlinevirtual

Reimplemented in Loom_LTE, and Loom_WiFi.

virtual SSLClient& LoomInternetPlat::get_client ( )
protectedpure virtual

Get the underlying SSLClient implementation, which we will use for all of the other requests.

Implemented in Loom_LTE, Loom_Ethernet, and Loom_WiFi.

virtual const SSLClient& LoomInternetPlat::get_client ( ) const
protectedpure virtual

Implemented in Loom_LTE, Loom_Ethernet, and Loom_WiFi.

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.
ClientSession LoomInternetPlat::http_get_request ( const char *  domain,
const char *  url,
const char *  body = nullptr 
)
inline

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 
)
inline

Make HTTP POST request.

See http_request() for parameter and return details.

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

Make HTTP request.

Parameters
[in]domainThe domain to connect to (e.g "www.google.com")
[in]urlThe URL string to send with the http request, not including the domain (ex. "/arduino?thing=otherthing").
[in]bodyThe 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.
[in]result_sizeSize of the buffer pointed to by result, in bytes. If the size of the buffer is exceeded, this function will return false.
[out]resultPointer to the buffer to put data returned from the request in. Can be nullptr if result data is to be discarded.
[in]verbHTTP 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.
virtual bool LoomInternetPlat::is_connected ( ) const
pure virtual

Implemented in Loom_LTE, Loom_WiFi, and Loom_Ethernet.

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

Open a UDP socket for sending and recieving incoming data.

Warning
Be careful about recieving data from an open socket!
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.

Implemented in Loom_LTE, Loom_WiFi, and Loom_Ethernet.

virtual void LoomInternetPlat::package ( JsonObject  json)
inlineoverridevirtual

No package necessary for internet platforms.

implement with empty body.

Implements LoomModule.

Reimplemented in Loom_WiFi.

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.


The documentation for this class was generated from the following files: