Fetch for Arduino Aims to Dramatically Simplify HTTP and HTTPS Operations on Your Microcontroller

Designed for simplicity, Fetch for Arduino handles most headers automatically — and provides the response at once.

ghalfacree
almost 4 years ago Internet of Things

Muhammad Abdullah, co-founder of Internet of Things (IoT) startup Grandeur Technologies, has released a library designed to make it as easy as possible to get your Arduino compatible microcontroller talking to a web server: Fetch for Arduino.

"I wrote Fetch for Arduino so I can make requests from my [Espressif] ESP by avoiding as many mistakes as possible," Abdullah explains. "The bigger the surface area of the code, the greater the possibility that I'd miss a header or mistype a character somewhere and it'd become a debugging nightmare for me."

Fetch for Arduino slots into your sketches to make HTTP requests a cinch. (📷: Muhammad Abdullah)

The result, inspired by a friend's failure to convert sample code designed for GET requests to POST to an HTTPS-connected server, is designed as a simpler alternative to existing HTTPS-compatible libraries. "The httpsClient on Arduino doesn't return you the response as elegantly as fetch [in a browser]," Abdullah explains. "You have to manually read the headers line by the line, then break the loop when a double newline occurs, and then read the body from thereon.

"So, I made a bare-minimum library that could do all of this under the constraints of the microcontroller environment."

The Fetch for Arduino library aims to mimic the simplicity of using fetch in a browser, including automatically setting the correct headers based on the URL and the content being sent — both issues which had prevented Abdullah's friend's code from working correctly.

The library has been tested on an Espressif ESP8266, but should be broadly compatible. (📷: Espressif)

At the same time, it also correctly processes the response — including highlighting the HTTP status code and providing the body in a single function call, rather than a loop which takes its input line-by-line.

"This bare-minimum effort does not yet have the automatic Content-Type guessing feature," Abdullah admits, "but I'll plug it in [when] I get some free time from work! That would knock out another mistake that a developer like me can make while writing RequestOptions."

More details on Fetch for Arduino are available in Abdullah's Instructables post, while the code — tested on the Espressif ESP8266 — has been published to GitHub under the reciprocal GNU General Public License 3.

ghalfacree

Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.

Latest Articles