SlideShare a Scribd company logo
1 of 4
Download to read offline
Web of Things: HTML5 for resource constrained Embedded
Systems
Jonny Doin, Principal Engineer
Sergio Eduardo Alves de Paula, R&D Engineer
Several current embedded systems, like industrial instrumentation, sensor
networks and control oriented systems have embedded HTML servers. Often
these HTML servers need to have dynamic updating webpages, with realtime
data. Using the new features of HTML5, rich and lightweight embedded web
servers with dynamic content and graphs can be designed. This white paper
will show techniques combining these new HTML5 features with managed
HTTP frames, which can be applied to any microcontroller to achieve
embedded servers using a minimum of resources. The interaction of page
script and server side processing will be shown for implementing SSE and
HTML5 dynamic content. The systems targeted are small bare-metal
embedded systems with hardware-based TCP/IP implemented on separate
chips, but the techniques presented can be used in any system.
Embedded Systems
The class of “Embedded Systems” range from dedicated application controllers that run
full-featured operating systems such as Linux, down to microcontrollers running very small
RTOS or bare-metal applications.
We are targeting the low-end systems, often used in control-intensive applications.
These systems usually are based on microcontrollers with limited resources, like small on-
chip Flash program memory ranging from 128KB to 2MB and on-chip RAM ranging from
32KB to 256KB.
Such systems are usually found in Industrial instrumentation and control devices, often
connected to fieldbus and other dedicated networks. In recent years, these Industrial
control systems are being connected to TCP/IP networks, driven by the need to integrate
their process data to the factory IT backend.
Besides normal M2M connectivity, that includes traditional socket-level TCP/IP and higher-
level fieldbus protocols, these systems are also required to serve web-based human
interfaces.
Embedded Web Servers
The demands of an embedded instrumentation web server today go far beyond showing a
collection of simple pages with fixed content. Current embedded web servers are dynamic
monitors for the realtime process data, interact with the control process to send realtime
commands, and are also complex configuration user interfaces, often with dynamic
graphics content. Add the need to be compatible with several different browsers and you
have a formidable set of requirements.
Traditionally, these requirements demanded a powerful web server, comparable to a
LAMP stack (Linux, Apache, MySql, PHP/Perl/Python). The dynamic content coupled with
a responsive user interface usually requires large RAM buffers and backend support for
the dynamic content.
In a dedicated embedded system with constrained resources, the toll of such a fast
dynamic web server can be excessive, moreover when the web server functionality is not
the main purpose of the system. This toll takes on RAM and processing resources, and
may introduce processing latency and significantly reduce available RAM for core data
processing.
Many embedded web server implementations allow allocation of system resources, by
limiting the RAM footprint taken by network buffers and reducing processor bandwidth for
the web server task. Not surprisingly, there is a clear tradeoff involved in reducing these
system resources, and the most evident is a reduced performance in dynamic web page
update and responsiveness.
The TCP/IP Stack
We based our implementation on a hardware-based TCP/IP implementation.
This decision suits small embedded systems very well, because the main system
resources needed on a web server application are located in the TCP/IP stack.
From the point of view of system resources allocation, the TCP/IP core demands more
RAM usage and CPU load for the protocol state machine processing than the socket-layer
state machines needed to support a web server functionality.
Keeping the network access on a separate processing environment also brings higher
system reliability to low-end embedded systems.
The core app is insulated from the toxic environment of the network. Stack overflow
attacks directed to the network protocol layers are contained and can be dealt with by the
core application by resetting the network chip. Payload buffer overflow and CGI abuse still
need to be addressed by the application.
Socket Layer backend
The server must implement the HTTP state machine, which consists of a HTTP text parser
and an HTTP frame composer. The server also needs to implement the handlers for
Server Sent Events (SSE - more on that later), and the Common Gateway Interface (CGI)
command parser and dispatcher.
Some Non-Functional Requirements are very important to keep the system reliability.
Special consideration must be dispensed to buffer overflow in the parsers, and memory
allocation must be strictly controlled, following the rules of the core application. Another
NFR is that all state machines must be safe, i.e., must not lock up in a frozen state.
The main NFR on this implementation is that functional failures on the web server should
not affect the main application core.
This is all it takes for a simple web server.
Dynamic Content Handling
Web pages with rich data sets tend to be large. Frequently, large Javascript frameworks
and libraries are used to support platform agnostic behavior.
Like other encapsulated frames, HTTP frames need a header descriptor that specify the
length of the payload. This imposes that HTTP frames must have payload sizes
determined prior to be transmitted. That is not a problem for fixed frames, such as fixed
content pages, because their length can be predetermined and saved with a page
descriptor, and access to the length can be made without reading the full payload at once,
which would demand excessively large RAM buffers.
One method used in the past by simple embedded servers for dynamic HTML pages was
to printf() the dynamic data directly into the page text. Besides being an extremely slow
method for content update, dependent on page refresh, this usually means that the entire
frame must reside in RAM, have its length determined, and only then be sent to the socket
layer. This also imposes large RAM buffers to hold the page rendering.
Instead of rendering the data onto the page text, a much better approach is to use a fixed
page with placeholders for event sources of dynamic data. With the resulting fixed frames,
the server can apply the same approach to fixed and dynamic pages, because they are
essentially fixed text frames.
One aspect of this approach is that it improves concern separation for the server and
client, and delegates to the page script and description full control over location and
appearance of the dynamic data.
Another important aspect for the implementation is that by applying a “window” buffer to
the data stream to the socket layer, we can serve multiple sockets with very little RAM. A
typical responsive system demands less than 200bytes per socket.
HTML5 streaming data: SSE
With HTML5, several aspects of dynamic web page content got addressed by new
constructs. Especially, SSE (Server Sent Events) allow streaming data to be sent to a
client and displayed by the page javascript, without changing the page text. Although this
was possible before HTML5, SSE allow asynchronous streams to be sent to the client, at
the server timing, without a formal request. That feature simplifies the collection of realtime
data, reduces latency and cuts bandwidth for embedded data traffic.
The main contribution of the SSE for dynamic data streams is that a single request is
needed by the page script to start the event generator on the server side, and from that
point on, the event source will supply a stream of data to the client, simplifying client script
and reducing network traffic by half.
These features allow a lightweight server engine, using less resources and less network
bandwidth for streaming data, making SSE very attractive to embedded web server
applications.
JSON Data formatting
JSON (Javascript Object Notation) is a text data format used for data exchange. It is
based in simple comma-separated name:value pair descriptors, making it very simple to
parse and compose.
When used with javascript, JSON formatted data are converted to javascript objects,
readily accessible to the page script.
JSON data can easily be applied to streaming text data, making it perfect for use with SSE
streams.
Its simplicity and {name:value} also helps to generalize the server side processing, by
using data descriptors on the server side.
XML HTTP Requests
XML HTTP Requests is an API to send HTTP requests from the page to the server directly
under javascript control. It is used in the AJAX framework to implement asynchronous
dynamic pages, with the webpage requesting data and displaying in formatted fields.
We use XML HTTP Requests to send data and commands to the server under user
interaction.
Putting it all together
When using SSE to send streaming server data, the page script must open a data session
and keep it open for the whole duration of the stream. Usually, for a embedded web server
that is monitoring realtime data, this means that the socket is dedicated to the connection.
The client cannot send data to the server while the SSE data stream is active.
To do this, the page script detects the need to send commands or data to the server,
closes the SSE session, sends the data as a XML HTTP Request, then re-opens the SSE
session for the streaming data. This process is very fast, and is almost imperceptible to the
user.
The page script must detect errors in all stages of the process, including browser support
for the features used. The advantage of this simple process is that the server can be
implemented as a very lightweight and robust backend.
Some Performance Data
A simple web server using the techniques shown is realizable with very little code and
SRAM footprint, and yet shows remarkable user responsiveness and data update rate.
A server with a few pages and more than 10 streams of sensor data takes less than 5KB
of code footprint, and as low as 2KB for up to 4 sessions of client browsing, with very
responsive user interfaces and page update rates.
The full web server layer, implemented in a ARM7 or ARM Cortex-M3 takes less than 500
lines of code.

More Related Content

What's hot

Web servers (l6)
Web servers (l6)Web servers (l6)
Web servers (l6)
Nanhi Sinha
 
Mashup Services Overview
Mashup Services OverviewMashup Services Overview
Mashup Services Overview
zeljkoobrenovic
 

What's hot (20)

Application server vs Web Server
Application server vs Web ServerApplication server vs Web Server
Application server vs Web Server
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
 
Web servers (l6)
Web servers (l6)Web servers (l6)
Web servers (l6)
 
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
Web Server And Database Server
Web Server And Database ServerWeb Server And Database Server
Web Server And Database Server
 
Web Server - Internet Applications
Web Server - Internet ApplicationsWeb Server - Internet Applications
Web Server - Internet Applications
 
Proxy Server
Proxy ServerProxy Server
Proxy Server
 
Mashup Services Overview
Mashup Services OverviewMashup Services Overview
Mashup Services Overview
 
EAI design patterns/best practices
EAI design patterns/best practicesEAI design patterns/best practices
EAI design patterns/best practices
 
Websphere interview Questions
Websphere interview QuestionsWebsphere interview Questions
Websphere interview Questions
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
Www and http
Www and httpWww and http
Www and http
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
May proxy be_with_you
May proxy be_with_youMay proxy be_with_you
May proxy be_with_you
 
gofortution
gofortutiongofortution
gofortution
 
Clustering - october 2006
Clustering  - october 2006Clustering  - october 2006
Clustering - october 2006
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7
 
Mobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValueMobility Information Series - Webservice Architecture Comparison by RapidValue
Mobility Information Series - Webservice Architecture Comparison by RapidValue
 
Server and Its Types - Presentation
Server and Its Types - PresentationServer and Its Types - Presentation
Server and Its Types - Presentation
 

Viewers also liked

Product Catalogue--Tablet PC
Product Catalogue--Tablet PCProduct Catalogue--Tablet PC
Product Catalogue--Tablet PC
Yang Flower
 
Robotic Project - published paper
Robotic Project - published paperRobotic Project - published paper
Robotic Project - published paper
Robert Rosier
 
Profile_ Accomplishment_Ravindra Kumar
Profile_ Accomplishment_Ravindra Kumar Profile_ Accomplishment_Ravindra Kumar
Profile_ Accomplishment_Ravindra Kumar
Ravindra Kumar Devaraj
 
The EZLAW Firm Profile
The EZLAW Firm ProfileThe EZLAW Firm Profile
The EZLAW Firm Profile
Hoang Tran
 

Viewers also liked (18)

Product Catalogue--Tablet PC
Product Catalogue--Tablet PCProduct Catalogue--Tablet PC
Product Catalogue--Tablet PC
 
Vocabulary-it was Hilarious!
Vocabulary-it was Hilarious!Vocabulary-it was Hilarious!
Vocabulary-it was Hilarious!
 
Presentación Fauna y Flora
Presentación Fauna y FloraPresentación Fauna y Flora
Presentación Fauna y Flora
 
Fuentes derecho internacional privado
Fuentes derecho internacional privadoFuentes derecho internacional privado
Fuentes derecho internacional privado
 
Robotic Project - published paper
Robotic Project - published paperRobotic Project - published paper
Robotic Project - published paper
 
TESTIMONIALS 3
TESTIMONIALS 3TESTIMONIALS 3
TESTIMONIALS 3
 
SoC Newsletter
SoC NewsletterSoC Newsletter
SoC Newsletter
 
προϊόντα μακιγιάζ
προϊόντα μακιγιάζπροϊόντα μακιγιάζ
προϊόντα μακιγιάζ
 
La stratégie des dominos au XXI siècle / The dominoes' strategy in the 21st c...
La stratégie des dominos au XXI siècle / The dominoes' strategy in the 21st c...La stratégie des dominos au XXI siècle / The dominoes' strategy in the 21st c...
La stratégie des dominos au XXI siècle / The dominoes' strategy in the 21st c...
 
Uitstap Gent
Uitstap GentUitstap Gent
Uitstap Gent
 
La nube
La nubeLa nube
La nube
 
Profile_ Accomplishment_Ravindra Kumar
Profile_ Accomplishment_Ravindra Kumar Profile_ Accomplishment_Ravindra Kumar
Profile_ Accomplishment_Ravindra Kumar
 
AutoCAD
AutoCAD   AutoCAD
AutoCAD
 
Obligaciones extracontractuales en el dip
Obligaciones extracontractuales en el dipObligaciones extracontractuales en el dip
Obligaciones extracontractuales en el dip
 
Harimau dari madiun
Harimau dari madiunHarimau dari madiun
Harimau dari madiun
 
The EZLAW Firm Profile
The EZLAW Firm ProfileThe EZLAW Firm Profile
The EZLAW Firm Profile
 
The future of the university
The future of the universityThe future of the university
The future of the university
 
chance of a lifetime- margaret iggulden
chance of a lifetime- margaret igguldenchance of a lifetime- margaret iggulden
chance of a lifetime- margaret iggulden
 

Similar to Esc 209 paper_doin

21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS
koolkampus
 
Xml web services
Xml web servicesXml web services
Xml web services
Raghu nath
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
Neil Ghosh
 
Semantic Web Servers
Semantic Web ServersSemantic Web Servers
Semantic Web Servers
webhostingguy
 

Similar to Esc 209 paper_doin (20)

Decoding real time web communication
Decoding real time web communicationDecoding real time web communication
Decoding real time web communication
 
single page application
single page applicationsingle page application
single page application
 
21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS
 
Esc 209 slides-doin
Esc 209 slides-doinEsc 209 slides-doin
Esc 209 slides-doin
 
Xml web services
Xml web servicesXml web services
Xml web services
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
 
21 Www Web Services
21 Www Web Services21 Www Web Services
21 Www Web Services
 
Sun Web Server Brief
Sun Web Server BriefSun Web Server Brief
Sun Web Server Brief
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Server Farms and XML Web Services
Server Farms and XML Web ServicesServer Farms and XML Web Services
Server Farms and XML Web Services
 
Bt0078 website design 2
Bt0078 website design 2Bt0078 website design 2
Bt0078 website design 2
 
Semantic Web Servers
Semantic Web ServersSemantic Web Servers
Semantic Web Servers
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
 
Sun Web Server Brief
Sun Web Server BriefSun Web Server Brief
Sun Web Server Brief
 
WP Chap 1 & 2.pptx
WP Chap 1 & 2.pptxWP Chap 1 & 2.pptx
WP Chap 1 & 2.pptx
 
Presentation about servers
Presentation about serversPresentation about servers
Presentation about servers
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
How to choose a server for your data center's needs
How to choose a server for your data center's needsHow to choose a server for your data center's needs
How to choose a server for your data center's needs
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 

More from Jonny Doin

ParallelLogicToEventDrivenFirmware_Doin
ParallelLogicToEventDrivenFirmware_DoinParallelLogicToEventDrivenFirmware_Doin
ParallelLogicToEventDrivenFirmware_Doin
Jonny Doin
 
SiliconFailsafeForIoT_Doin
SiliconFailsafeForIoT_DoinSiliconFailsafeForIoT_Doin
SiliconFailsafeForIoT_Doin
Jonny Doin
 
ImplementingCryptoSecurityARMCortex_Doin
ImplementingCryptoSecurityARMCortex_DoinImplementingCryptoSecurityARMCortex_Doin
ImplementingCryptoSecurityARMCortex_Doin
Jonny Doin
 

More from Jonny Doin (11)

Jonny doin safe io t- lt_spice failsafe
Jonny doin safe io t- lt_spice failsafeJonny doin safe io t- lt_spice failsafe
Jonny doin safe io t- lt_spice failsafe
 
Impacto metrologialegal jonnydoin
Impacto metrologialegal jonnydoinImpacto metrologialegal jonnydoin
Impacto metrologialegal jonnydoin
 
Jonny doin lt spice servo_dac
Jonny doin lt spice servo_dacJonny doin lt spice servo_dac
Jonny doin lt spice servo_dac
 
Sts 401 slides-doin
Sts 401 slides-doinSts 401 slides-doin
Sts 401 slides-doin
 
Network insecuritysimplehackscortexm jonnydoin
Network insecuritysimplehackscortexm jonnydoinNetwork insecuritysimplehackscortexm jonnydoin
Network insecuritysimplehackscortexm jonnydoin
 
Io t hurdles_i_pv6_slides_doin
Io t hurdles_i_pv6_slides_doinIo t hurdles_i_pv6_slides_doin
Io t hurdles_i_pv6_slides_doin
 
Implementing lora smartcity doin
Implementing lora smartcity doinImplementing lora smartcity doin
Implementing lora smartcity doin
 
Csc jonny doin_painel1_sm
Csc jonny doin_painel1_smCsc jonny doin_painel1_sm
Csc jonny doin_painel1_sm
 
ParallelLogicToEventDrivenFirmware_Doin
ParallelLogicToEventDrivenFirmware_DoinParallelLogicToEventDrivenFirmware_Doin
ParallelLogicToEventDrivenFirmware_Doin
 
SiliconFailsafeForIoT_Doin
SiliconFailsafeForIoT_DoinSiliconFailsafeForIoT_Doin
SiliconFailsafeForIoT_Doin
 
ImplementingCryptoSecurityARMCortex_Doin
ImplementingCryptoSecurityARMCortex_DoinImplementingCryptoSecurityARMCortex_Doin
ImplementingCryptoSecurityARMCortex_Doin
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Esc 209 paper_doin

  • 1. Web of Things: HTML5 for resource constrained Embedded Systems Jonny Doin, Principal Engineer Sergio Eduardo Alves de Paula, R&D Engineer Several current embedded systems, like industrial instrumentation, sensor networks and control oriented systems have embedded HTML servers. Often these HTML servers need to have dynamic updating webpages, with realtime data. Using the new features of HTML5, rich and lightweight embedded web servers with dynamic content and graphs can be designed. This white paper will show techniques combining these new HTML5 features with managed HTTP frames, which can be applied to any microcontroller to achieve embedded servers using a minimum of resources. The interaction of page script and server side processing will be shown for implementing SSE and HTML5 dynamic content. The systems targeted are small bare-metal embedded systems with hardware-based TCP/IP implemented on separate chips, but the techniques presented can be used in any system. Embedded Systems The class of “Embedded Systems” range from dedicated application controllers that run full-featured operating systems such as Linux, down to microcontrollers running very small RTOS or bare-metal applications. We are targeting the low-end systems, often used in control-intensive applications. These systems usually are based on microcontrollers with limited resources, like small on- chip Flash program memory ranging from 128KB to 2MB and on-chip RAM ranging from 32KB to 256KB. Such systems are usually found in Industrial instrumentation and control devices, often connected to fieldbus and other dedicated networks. In recent years, these Industrial control systems are being connected to TCP/IP networks, driven by the need to integrate their process data to the factory IT backend. Besides normal M2M connectivity, that includes traditional socket-level TCP/IP and higher- level fieldbus protocols, these systems are also required to serve web-based human interfaces. Embedded Web Servers The demands of an embedded instrumentation web server today go far beyond showing a collection of simple pages with fixed content. Current embedded web servers are dynamic monitors for the realtime process data, interact with the control process to send realtime commands, and are also complex configuration user interfaces, often with dynamic graphics content. Add the need to be compatible with several different browsers and you have a formidable set of requirements. Traditionally, these requirements demanded a powerful web server, comparable to a LAMP stack (Linux, Apache, MySql, PHP/Perl/Python). The dynamic content coupled with
  • 2. a responsive user interface usually requires large RAM buffers and backend support for the dynamic content. In a dedicated embedded system with constrained resources, the toll of such a fast dynamic web server can be excessive, moreover when the web server functionality is not the main purpose of the system. This toll takes on RAM and processing resources, and may introduce processing latency and significantly reduce available RAM for core data processing. Many embedded web server implementations allow allocation of system resources, by limiting the RAM footprint taken by network buffers and reducing processor bandwidth for the web server task. Not surprisingly, there is a clear tradeoff involved in reducing these system resources, and the most evident is a reduced performance in dynamic web page update and responsiveness. The TCP/IP Stack We based our implementation on a hardware-based TCP/IP implementation. This decision suits small embedded systems very well, because the main system resources needed on a web server application are located in the TCP/IP stack. From the point of view of system resources allocation, the TCP/IP core demands more RAM usage and CPU load for the protocol state machine processing than the socket-layer state machines needed to support a web server functionality. Keeping the network access on a separate processing environment also brings higher system reliability to low-end embedded systems. The core app is insulated from the toxic environment of the network. Stack overflow attacks directed to the network protocol layers are contained and can be dealt with by the core application by resetting the network chip. Payload buffer overflow and CGI abuse still need to be addressed by the application. Socket Layer backend The server must implement the HTTP state machine, which consists of a HTTP text parser and an HTTP frame composer. The server also needs to implement the handlers for Server Sent Events (SSE - more on that later), and the Common Gateway Interface (CGI) command parser and dispatcher. Some Non-Functional Requirements are very important to keep the system reliability. Special consideration must be dispensed to buffer overflow in the parsers, and memory allocation must be strictly controlled, following the rules of the core application. Another NFR is that all state machines must be safe, i.e., must not lock up in a frozen state. The main NFR on this implementation is that functional failures on the web server should not affect the main application core. This is all it takes for a simple web server. Dynamic Content Handling Web pages with rich data sets tend to be large. Frequently, large Javascript frameworks and libraries are used to support platform agnostic behavior.
  • 3. Like other encapsulated frames, HTTP frames need a header descriptor that specify the length of the payload. This imposes that HTTP frames must have payload sizes determined prior to be transmitted. That is not a problem for fixed frames, such as fixed content pages, because their length can be predetermined and saved with a page descriptor, and access to the length can be made without reading the full payload at once, which would demand excessively large RAM buffers. One method used in the past by simple embedded servers for dynamic HTML pages was to printf() the dynamic data directly into the page text. Besides being an extremely slow method for content update, dependent on page refresh, this usually means that the entire frame must reside in RAM, have its length determined, and only then be sent to the socket layer. This also imposes large RAM buffers to hold the page rendering. Instead of rendering the data onto the page text, a much better approach is to use a fixed page with placeholders for event sources of dynamic data. With the resulting fixed frames, the server can apply the same approach to fixed and dynamic pages, because they are essentially fixed text frames. One aspect of this approach is that it improves concern separation for the server and client, and delegates to the page script and description full control over location and appearance of the dynamic data. Another important aspect for the implementation is that by applying a “window” buffer to the data stream to the socket layer, we can serve multiple sockets with very little RAM. A typical responsive system demands less than 200bytes per socket. HTML5 streaming data: SSE With HTML5, several aspects of dynamic web page content got addressed by new constructs. Especially, SSE (Server Sent Events) allow streaming data to be sent to a client and displayed by the page javascript, without changing the page text. Although this was possible before HTML5, SSE allow asynchronous streams to be sent to the client, at the server timing, without a formal request. That feature simplifies the collection of realtime data, reduces latency and cuts bandwidth for embedded data traffic. The main contribution of the SSE for dynamic data streams is that a single request is needed by the page script to start the event generator on the server side, and from that point on, the event source will supply a stream of data to the client, simplifying client script and reducing network traffic by half. These features allow a lightweight server engine, using less resources and less network bandwidth for streaming data, making SSE very attractive to embedded web server applications. JSON Data formatting JSON (Javascript Object Notation) is a text data format used for data exchange. It is based in simple comma-separated name:value pair descriptors, making it very simple to parse and compose. When used with javascript, JSON formatted data are converted to javascript objects, readily accessible to the page script.
  • 4. JSON data can easily be applied to streaming text data, making it perfect for use with SSE streams. Its simplicity and {name:value} also helps to generalize the server side processing, by using data descriptors on the server side. XML HTTP Requests XML HTTP Requests is an API to send HTTP requests from the page to the server directly under javascript control. It is used in the AJAX framework to implement asynchronous dynamic pages, with the webpage requesting data and displaying in formatted fields. We use XML HTTP Requests to send data and commands to the server under user interaction. Putting it all together When using SSE to send streaming server data, the page script must open a data session and keep it open for the whole duration of the stream. Usually, for a embedded web server that is monitoring realtime data, this means that the socket is dedicated to the connection. The client cannot send data to the server while the SSE data stream is active. To do this, the page script detects the need to send commands or data to the server, closes the SSE session, sends the data as a XML HTTP Request, then re-opens the SSE session for the streaming data. This process is very fast, and is almost imperceptible to the user. The page script must detect errors in all stages of the process, including browser support for the features used. The advantage of this simple process is that the server can be implemented as a very lightweight and robust backend. Some Performance Data A simple web server using the techniques shown is realizable with very little code and SRAM footprint, and yet shows remarkable user responsiveness and data update rate. A server with a few pages and more than 10 streams of sensor data takes less than 5KB of code footprint, and as low as 2KB for up to 4 sessions of client browsing, with very responsive user interfaces and page update rates. The full web server layer, implemented in a ARM7 or ARM Cortex-M3 takes less than 500 lines of code.