lbussy / LCBUrl

Arduino library for handling URLs
MIT License
7 stars 1 forks source link
arduino arduino-lib arduino-library url urllib

LCBUrl - An Arduino library for handling URLs

Arduino Library GitHub Release MIT License GitHub Issues GitHub Pull Requests Contributors Welcome

This library was written by and for a non-professional programmer. If you find some use out of it, that will make me happy, but if not, I'm still using it in my projects.

This library will parse a URL, and normalize it according to the information provided in RFC3986. Take for example this terrifying URL:

http://%7EFoo:%7Ep@$$word@servername.local:80/%7Ethis/is/a/./path/test.php?foo=bar#frag

LCBUrl will allow you to parse and access the hostname, user name, password, path, query string, fragment, etc.:

If you are using mDNS in your projects, you may have discovered many microcontroller libraries do not support mDNS in all areas. This library will additionally (but conditionally) re-parse a URL and replace the *.local hostname with the resolved IP address.

:exclamation: IMPORTANT: Using any of the network-based methods in a timer (i.e. Ticker) will crash or hang your program. This hang is not a shortcoming of this library; it is how radio-functions (networking being one) work.

Public Methods

Core Methods

Original Utility Methods

:exclamation: These methods are deprecated and slated to be removed.

These utility methods are dependant upon the class' instantiation and current URL string.

Utility Methods

These methods are intended to extend functionality of the TCP libraries, and may be leveraged independent of a specific instance declaration.

Progress:

Installation

Installation is particular to the platform with which you are developing:

PlatformIO

This library is available as lbussy/LCBUrl in PlatformIO's library manager.

Arduino IDE

LCBUrl is published via the Arduino Library Manager. You can include this library in your project by navigating to Sketch -> Include Libraries -> Manage Libraries (or Ctrl - Shift - I). Type LCBUrl in the search bar:

Manual

To install this library, place this entire folder as a subfolder in your ./lib/targets/libraries folder.

When installed, this library should contain the following files:

./lib/targets/libraries/LCBUrl                    (this library's folder)
./lib/targets/libraries/LCBUrl/examples           (the examples in the "open" menu)
./lib/targets/libraries/LCBUrl/keywords.txt       (the syntax coloring file)
./lib/targets/libraries/LCBUrl/library.properties (properties of this library)
./lib/targets/libraries/LCBUrl/LICENSE            (the license for this library)
./lib/targets/libraries/LCBUrl/README.md          (this file)
./lib/targets/libraries/LCBUrl/src/LCBUrl.cpp     (the library implementation file)
./lib/targets/libraries/LCBUrl/src/LCBUrl.h       (the library description file)

Building

Ensure that you add a corresponding line to the top of your sketch:

#include <LCBUrl.h>

To stop using this library, delete that line from your sketch.

mDNS Support {#mdns-support}

To enable mDNS support, define the macro before including the library:

#define LCBURL_MDNS
#include <LCBUrl.h>

Or, define it globally in the platformio.ini or compiler definitions:

-DLCBURL_MDNS

Without this definition, the mDNS functions will return failures.

mDNS on ESP8266

After initial release of this library, the upstream WiFi.hostByName() stopped resolving mDNS queries. I am exploring other options to provide name resolution for mDNS on the ESP8266.

Contributing

If you would like to contribute to this project:

License

The library is licensed under the MIT License.

Copyright

LCBUrl is Copyright © 2019-2022 by Lee C Bussy.