For his Hackaday Prize entry, [Yann] is building something that isn’t hardware, but it’s still fascinating. He’s come up with a minimalist HTTP compliant server written in C. It’s small, it’s portable, and in some cases, it will be a bunch better solution than throwing a full Linux stack into a single sensor.
This micro HTTP server has two core modules, each with a specific purpose. The file server does exactly what it says on the tin, but the HTTaP is a bit more interesting. HTTaP is a protocol first published in 2014 that is designed to be a simpler alternative to WebSockets.
[Yann] has been experimenting with HTTaP, and the benefits are obvious. You don’t need Apache to make use of it, HTTaP can work directly with an HTML/JavaScript page, and using only GET and POST messages, you can control hardware and logic circuits.
As this is a minimalist HTTP server, the security is dubious at best. That’s not the point, though. This is just a tool designed for use in a lab or controlled environments with an air gap. Safety, scheduling, encryption, and authentication are not part of HTTaP or this micro HTTP server.
Thank you Brian, it’s a pretty good summary, I was too waist-deep in the code to come up with it :-)
The HTTaP module is going to be upgraded to a better, more modular system so people don’t have to modify the core server’s source code, but you know the tune, work and other projects are always getting in the way…
There are dozens of servers written in C, and some are very mature:
https://github.com/lammertb/libhttp
or if you are blessed by a *nix environment:
https://www.gnu.org/software/libmicrohttpd/
Real programmers are lazy, and will simply push a patch to a repo for their particular use case.
;-)
Hi,
Yes i’ve looked at them already :-)
My use cases however require dynamic switching from polling to blocking behaviour because of the way it interacts with a possible user-made wrapper. Multithreading is not possible and race conditions must be avoided… but the application must still be responsive, whether it uses 100% or 0% of the CPU…
Oh I forgot : I need to have everything under AGPLv3 for coherence and convenience.
In the end I had a set of requirement so specific that hacking another lib woud have been too hard.
After this is solved, the other part of the equation is to get/make a TCP/IP stack. So far I use the hardware stacks from Wiznet so it saves a lot of hassles :-)
You may want to check out lwip on Espressif original SDK or:
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
Vendor specific solutions are always a bad gamble in the long term.
+10
A small echo server written in x86-32 asm https://github.com/kelseyhightower/echod
nasm for ever !!! :-D
Speaking of minimalism, I once had an ESP8266 handy and wanted to come up with a no-surprise HTTP server in about one hour. It’s not in C (which is more of a feature), but at 86 lines it’s quite compact, and I think it’s quite pretty too.
https://lab.whitequark.org/notes/2016-10-20/controlling-a-gpio-through-an-esp8266-based-web-server/
wow, I must check this :-D
OK,it’s so much shorter than the HTTaP server because I had to write the interface with the POSIX sockets in C at the low level, fine-tune certain details, extend to the most general cases… The actual “HTTP” part is pretty small and it’s an ignored fact that despite the moutains of RFC, the principles of HTTP are ridiculously simple (which explains its success)
Of course. This is not some sort of contest, I just wanted a quick and reasonably non-dirty way of exposing a microcontroller. I can write C just as well as Python but why bother if it’s a hindrance? (the Xtensa toolchain alone is aggravating enough)
The point of developing this microserver is to make this sort of hack very easy and yet very low footprint while still being powerful, and without any OS. For now it is being developed for the RPi under Linux but hopefully it can be ported to µC (such as the YASEP ;-) )
This is a very good idea, I also have something similar ( C based ) and also targeted for Linux RPI like devices , robots ( https://www.youtube.com/watch?v=41_8ktacxt8 ) etc. Having a web interface allows all kinds of remote controlling from mobile phones/PC/scripting , it is really useful!
https://github.com/AmmarkoV/AmmarServer
Wow !!! That’s impressive ! I’m not sure it would help HTTaP (you use pthreads while I use single-threaded code and switch from polling to stalling and back, as desired) but it certainly helps some of my other needs :-D
How come I haven’t heard about this code before ?
Thanks for your tip !
I hope this takes off for those who do micro-controller projects.
Most HTTP stacks I see are bloatware and need at least 32 bits and lots of RAM to get off the ground.
As [Yann Guidon / YGDES] said above Quote: “despite the moutains [sic] of RFC, the principles of HTTP are ridiculously simple”
The vast majority of internet protocols like email servers are also incredibly simple and can easily run on an 8-bit. They’re all just ‘Stringy’ protocols that need a fair amount of ROM (FLASH) for the strings and very little RAM and CPU power and that quite well describes the 8-bit end micro-controller hierarchy.
There are also lots of protocol gateways out there if you don’t want to write your own. Want to send a SMS, no problem find a SMS gateway that has an API that accepts requests via HTTP.
This is an excellent project and it’s the missing link for a lot of hackers/engineers that have been shy of internet protocols. Now they have something written in a language they are familiar with and can be used directly or serve as a learning experience to understand just how simple internet or TCP/IP protocols are so they can go write their own.
+10 to Yann Guidon / YGDES
Thank you Röb ! I feel vindicated by your post :-)
I didn’t create HTTaP in the void : I’ve seen the first PIC-based servers using ISA cards and I’ve worked with the Rabbit Semiconductor micro web server, which is entirely written in C and which I had modified for my own purposes 12 years ago… But this code is proprietary so I HAD to make an open source, tailored version.
Developing the YASEP framework made me understand that the browser was like an autistic genius and needed an easy, simple communication system so I created the HTTaP sub-protocol (despite the existence websockets).
I also need to host the JS application on the same server (to avoid cross-origins limitations) so this slowly shaped the dual-use server that is described in this post…
One goal is to make the server run on the YASEP (one day :-) )
So yes, the “missing link” argument was my motivation all along :-D
Finding a FREE SMS gateway would be the harder part.
> “despite the moutains [sic] of RFC, the principles of HTTP are ridiculously simple”
Why [sic]? What are you Refering to?
maybe because I used a french idiom, “mountains”=”huge quantities”
The spelling of “mountains.”
…and the spelling of molehills. :)
Note : the “project” is split into
a) the specification of the protocol (see the link provided in the story)
b) the implementation (the project https://hackaday.io/project/20042 ) where you’ll find the source code in C :-)
Since it’s interacting with post and get make a hardware based authentication that simply does not respond with error let or get provides null values.
Would you/Could you elaborate ?
Contiki Os ?
http://www.contiki-os.org/
Been done before…
Pre-Contiki:
https://github.com/adamdunkels/uip/tree/master/apps/webserver
Thanks very much. The protocol is interesting because of the generality but the most basic “hello world” web server is only a dozen or so lines of logic in C. There’s more work to interface with the adapter hardware than the client.
https://olduino.wordpress.com/2014/12/11/minimal-http-server-with-w5500/
I had not seen other servers in C so this project and thread are great.