Preface
Device manufacturers are missing a huge opportunity to give their users a better experience while providing more capabilities. The key is to take advantage of the capabilities of the power of their portable devices and the web browser. This doesnāt replace the control panel but can greatly enhance the capabilities while allowing innovation.
Unlike a browser, a web server can run on even very small systems. In these columns I share my own experience in understanding how the servers work and their potential.
In http://rmf.vc/IEEEBlinky (2016 - 80/20 Consumer Electronics) I wrote a simple server using pure sockets with a client side that displayed the lights blinking on a Raspberry pi. The goal was to get to the basics and show how simple such an app can be.
Later that year I was inspired to rewrite my personal website (https://rmf.vc/IEEEInsites) using the NodeJS http library. This was a time when promises were not part of JavaScript. The code was more complicated than Iād liked. It made me conservative in my approach. I also avoided any client-side code because I didnāt want to assume that browsers were very capable and up to date.
I have since become more familiar with tools, especially Express for building websites. The other big change, over the last year, has been my use of ChatGPT, Copilot and other assists, as well as TypeScript. The big advantage is not so much in the tool doing coding for me, as much as in doing the hard part of poring through documentation and examples to find techniques I might not have been aware of.
Practice also helps a lot. I no longer use platform GUIs but, instead, take full advantage of web protocols and tools to build interactive applications. What I learn by doing the site applies equally well to building all applications.
Web Site Version 4
My latest site (https://Frankston.com) implementation differs sharply from my previous version.
With the help of my tools, Iāve been able to improve my use of Express. The basic structure of the program is a pipeline with each stage handler or routing requests. When a web request is received it is preprocessed and dispatched according to the host name. This makes it easy to support subsites such as one for my wife to host her artwork.
For my main site I provide a standard index.html for all pages. The URL itself is processed client-side where a client app processes the URL and then issues a request to the server for what it needs.
The advantage of first building a site with pure sockets is that I can see how the mechanism works and how http works ā what the over-the-wire format. As I mentioned in my previous column, I can select certificates and handle http vs https dynamically on any port. I also have a routine that allows me to renew certificates even if they arenāt directly accessible from the public Internet.
Instead of sending finished pages to the client, I send data which is then formatted and presented.
Doing this processing client side means depending on running JavaScript code on the client. I am conservative in that I try not to depend on the most recent features of JavaScript. I was reluctant to take this step previously because I was concerned that some users didnāt enable JavaScript. But today they have little choice, and they also need to keep the browsers updated for security updates.
Piping
Itās useful to understand techniques such as piping which enable me to manage flows such as sessions. I might have multiple web requests being processed ā each with its own state. That state is not necessarily stored on the server but is passed from the client to the server and back.
When a request is received by the server it is processed in, what is effect, a pipeline. The first HTTP(S) handler examines the URL. It can take the command line parameters and store processed form in the request object.
This is one way that JavaScriptās prototype-based approach of creating objects differs sharply from the approach taken in C-type languages in which objects are well-defined. The objects are more like bags in which you can place other objects dynamically. TypeScript works well with this in allowing me to tell it that weāve added information to this common object. This is how libraries in Express work though, until you recognize the technique it seems like magic.
In this example, I add my own session options so that a āpd=2017ā value on the command line is stored in sesh (short for session). I can declare this extra property to TypeScript to make sure I use it correctly.
The next handler can then use the sesh property as when I filter requests to generate the sidebar and table of contents. This allows me to handle multiple client sessions across multiple procedures without global values. Multithreading can get complicated, so it is important to carefully manage the visibility of objects and route the requests to the appropriate handlers.
Server and Client
For dynamic sites, I present a standard client-side framing as index.html. The client site procedure then requests content from the server. It first requests the side bar (filtered by the query parameters). The formatting is done on the client using HTML templates.
The main body is a document from my CMS (Content Management System). In practice each document is an HTML file. I extract the <ARTICLE> and do a small a small amount of processing on the server such as generating per-use email addresses and filling in directory listings if needed. Only the body of the document is sent, not the header information.
The API is a well-defined security boundary. The client can do elaborate processing but doesnāt have access to the raw information. It submits request tokens rather than providing file paths thus blocking common attack vectors.
The client also implements the # part of the URL to position the document after it was downloaded.
Overall, the split worked smoothly though there was some complexity that came from trying to maintain compatibility with older approaches. Ordering is also important ā one of the bugs came from the need to set the baseurl value before assigning InnerHTML so that the content got rendered correctly.
Beyond the Desktop
By shifting from platform GUI (such as Windows forms) to using web protocols not only am I able to take advantage of the rich tooling available for web applications, but I am also no longer tied to my desktop. This came in handy when I wanted to use an application, I wrote to monitor ping times on my network. Unlike the earlier version in C#, I realized I could use the browser on my phone to monitor the results from anywhere ⦠in the world. Though I may need to open a port on my gateway to forward requests. Due to the current limitations of the protocols, each application needs its own port if it is to run standalone. Thanks to routing, I can also make any site a subsite of another and dispatch on host name, the path in the URL or any other criterion. I can also run the same server on a dedicated post.
Software is the art of illusion, and I can present the site in various forms. This approach also facilitates testing ā I can assign test ports for test versions.
There are other workarounds such as NGINX which forward requests. Or I could use proxy operations to pass on http requests adding header information at each stage.
I can take advantage of the pipeline approach to support authentication. I can look for an authentication token in the initial processing and then pass it on to the later handlers. Thus, I can give my family access to photos without making them public.
Processing authentication myself allows me to use smartphones as control surfaces (such as light switches). I can have a policy that allows local use without authentication while requiring it when Iām away from home.
Appliances and Devices
These concepts are important for the next generation of devices and applications. I like the term UX for User Experience rather than User Interface (UI) since we need to think about the entire experience and how the users interact with the devices, as well as how devices interact with each other.
Today a refrigerator and dishwasher donāt have much to say to each other though, in the future, I can see them working together to balance energy consumption.
We can realize the full potential for rich interfaces by taking advantage of the full capabilities of modern browsers rather than being limited to a control panel on the device. A web server has a very low computer requirement so it can be implemented on an appliance at a fairly low cost.
A full browser device with sophisticated graphics might be expensive but the user has already paid for a smartphone for other reasons. There is also the option of having additional screens. These too can be shared across multiple applications and control multiple devices.
Thus, the appliance maker doesnāt have to bear the full cost of the devices but still can provide a rich interface. The large market for smart screens is also driving the price of such devices down.
These same market forces have also driven down the cost of the computing chips (such as the Espressif 8266) to the point that the cost of a powerful computing chip with Wi-Fi and Bluetooth is about $2. It is likely that adding such a chip would reduce the cost by replacing other components that implement part of the functionality with a single process. And the processor can be programmed using the same tools and languages as the web applications thus increasing programmer productivity and improving reliability.
A New Experience
This is not a separate Internet of Things. There are simply devices taking advantage of modern technologies and capabilities. The value of connectivity is not in the ability to do āhome automationā, it is the ability for our devices to work together. In particular the power of the portable browser devices is an opportunity for manufacturers to add value to their products and provide an enhanced user experience.