SlideShare a Scribd company logo
1 of 24
Download to read offline
Adding Support for Networking
and Web Technologies to an
Embedded System
John Efstathiades
Pebble Bay Consulting
About Pebble Bay
• Independent embedded software specialists
• founded 8 years ago
• based in Leamington Spa
• Consultancy
• independent review and advice
• Software development
• fully-managed projects
• Expertise
• real-time operating systems
• hardware/software interfacing
• software porting and optimisation
22-May-14 © 2012 Pebble Bay Consulting Limited 2
Project Background
• Industrial control system
• Controller with LCD and keypad
• Remote access from PC via RS-485
• Hardware re-design
• Cortex M3 processor
• Improved LCD panel
• Reduce manufacturing costs
• Make provision for networking
• Software porting
• Update low-level code
• Minimize changes to GUI and remote access API
Networking Update
• RS-485 remote access protocol allows:
• Configuration and data access
• Front panel LCD and button mirroring
• New customer requirements:
• Access from mobile devices
• Access over LAN/WAN/Internet(?)
• Networking options
• RS-485 extenders
• No software changes
• Relatively simple to deploy
• Use on-board networking
• No additional hardware
• Extend product features
Software Requirements
• Industry standard networking technology
• Maintain existing remote access protocol
• Implement transport independent interface
• Support existing customer base
• Opportunity to sell enhanced capabilities
• Brower-based client
• OS and hardware independent
• No additional software to install
• User authentication
• Restrict access to device
Software Solution
• lwIP TCP/IP network stack
• Mature product with BSD licence
• StellarisWare integration available (?)
• HTTP web server available
• AJAX Programming
• Client-side processing
• Dynamic page updates with new information
• HTML and JavaScript
• Fast client application prototyping
• DataView class
• Efficient mechanism for handling binary data
• Easy to represent arrays and structs in target device memory
lwIP Integration and Configuration
• Documentation
• lwIP Application Developers Manual
• lwip/doc/rawapi.txt
• Which release?
• Latest (v1.4.1) vs. StellarisWare (v1.3.2)
• lwIP operation
• Periodic timer tick
• Task model or interrupt thread
• Compatible with main-loop design with interrupts
• lwipOpts.h
• Includes/excludes stack features and behaviour
• Overrides defaults in lwip/src/include/lwip/opt.h
• Debugging, memory management, stack components, …
lwIP Abstraction Layer
• No RTOS - define NO_SYS
• Porting Layer
• Ethernet hardware interface
• Interrupt handling routines
• lwIPInit()
• Initialises stack modules
• Registers Ethernet hardware with stack
• lwIPEthernetIntHandler()
• Handles received packets
• Sends packets in transmit queue
• lwIPTimer()
• Stack timer processing
HTTP Server
• Provided as application add-on module
• HTTP server module
• Raw vs. socket interface
• File system APIs
• Optional ROM-based file system
• Stores HTML pages and images
• C array created by
makefsdata perl script
• Code space may be issue?
• Integrated with lwIP
• Call httpd_init()after
lwip_init()
Device Security
• Need to protect device against
• Unauthorised access
• Data theft
• Malicious intent
• Authentication Options
• Public key authentication
• Digest authentication
• Basic authentication
• HTTP Basic Authentication
• Simple mechanism using HTTP headers
• Credentials encoded with Base64 – not encrypted
• Fits in well with lwIP HTTP header processing
HTTP Basic Authorisation
• Supported by all browsers
• Server
• Sends Authenticate header with HTTP 401 response
• Client
• Sends Authorization request header (in every transaction)
• Base64 encoded username and password
• Cached by browser once accepted by server
• lwIP HTTP header processing easy to extend
• Extend http_recv() to look for Authorization header
• Extend get_http_headers() to send 401 if no authorisation
• Add routines to decode and check user credentials
lwIP Hints and Tips
• Debug control in lwipOpts.h
• Overrides defaults in lwip/src/include/lwip/debug.h
• LWIP_DEBUGF() common debug macro
• LWIP_PLATFORM_DIAG() device-specific debug output
• Stack runs in interrupt context
• Enabling debug could affect system behaviour
• Memory trace buffer and JTAG debugger less intrusive
• May need to experiment with memory configuration
• Overall heap size
• lwIP buffer pool size
• Received packets stored in buffer chains
• Buffer payload size set by PBUF_POOL_BUFSIZE => default is 256
AJAX Programming Methodology
• Collection of related technologies
• HTML for presentation of data
• XMLHttpRequest object for asynchronous server communication
• Document Object Model for dynamic display and manipulation of data
• JavaScript implementation language
• Client application sends request to server (device)
• Request encoded in HTTP request
• Read/write operational data
• Send control/status requests – get battery level, start processing, …
• Client application receives asynchronous response
• Callback function invoked when data received
• Page contents dynamically updated – no page refresh required
Device Support for Web I/O
• HTTP GET vs. POST
• GET has query strings encoded in URL
• POST has query strings in HTTP message body
• POST is “preferred” mechanism but not supported in lwip 1.3.2
• Define query strings for control/status requests
www.mydevice.com/control?led=1&status=on
www.mydevice.com/status?led=1
• Direct handling of HTTP Query Strings
• Extract name/value tuples from HTTP request
• Implement handler for each query type
• Response sent to client when operation is complete
• Self-contained => minimal impact on existing software
Query String Processing
/*
* Find an asynchronous I/O handler
*/
if (webIoHandlerGet (queryStr, &ioFunc, &bufLen) == 0)
{
char * pBuf;
int responseLen;
/* Allocate memory for the response string */
pBuf = mem_malloc (bufLen);
if (pBuf == 0)
{
mem_free (ptFile);
return NULL;
}
/* Perform the I/O operation */
responseLen = ioFunc (name, pBuf, bufLen);
/*
* After the I/O handler has been invoked all the data to be returned
* is in the response buffer so set index to the end of the "file".
*/
HTTP and Binary Data
• Poor browser support for sending/receiving binary data
• Standard problems:
• Byte order
• Alignment and packing
• Message/structure delimiters
• DataView and TypedArray objects
• Allows complex data types to be created
• Independent of client’s native byte order
• Base64 encoding
• Standard mechanism for encoding binary data into ASCII strings
• Simple algorithm to implement
DataView Example
/*
* Construct a key press message
*/
function v42KeypressCmd(key)
{
var buffer = new ArrayBuffer (REM_KEYPRESS_CMD_PKT_LEN);
var dv = new DataView (buffer);
var byteArray = new Uint8Array(buffer);
var crc;
dv.setUint8 (REM_CMD_BYTE_OFFSET, REM_KEYPRESS_CMD_BYTE);
dv.setUint8 (REM_ID_BYTE_OFFSET, unitNum & 0x0f);
dv.setUint16 (REM_MEM_ADDR_OFFSET, 0);
dv.setUint16 (REM_RETURN_MSG_LEN_OFFSET, REM_KEYPRESS_CMD_RESP_MSG_LEN);
dv.setUint16 (REM_PKT_LEN_OFFSET, REM_KEYPRESS_CMD_PKT_LEN);
dv.setUint8 (REM_KEYPRESS_CMD_MSG_KEY, key);
dv.setUint8 (REM_KEYPRESS_CMD_MSG_PREV, 0);
dv.setUint8 (REM_KEYPRESS_CMD_MSG_SLAVE, 1);
crc = crc16 (byteArray, REM_KEYPRESS_CMD_PKT_LEN - REM_TRAILER_LENGTH);
dv.setUint16 (REM_KEYPRESS_CMD_CRC_OFFSET, crc);
return base64Encode (byteArray);
}
HTML Document Object Model
• Cross-platform representation of objects in HTML
• HTML elements as objects
• Properties of HTML elements
• Methods and events for HTML elements
Dynamically Get, Change, Add, or Delete HTML elements
• Use JavaScript to create dynamic HTML
• Update pages with latest device data
• Build page elements “on the fly” based on device responses
• Periodic page updates using timer
document.getElementById(“<element>").innerHTML =
JavaScript DOM Example
/*
* Update the zone summary table
*/
function zoneTableBuild (zoneId, zoneData)
{
document.getElementById("zone_data").innerHTML =
"<table>" +
"<tr>" +
"<td>" + "Zone id" + "</td>" +
"<td>" + zoneId + "</td>" +
"</tr>" +
"<tr>" +
"<td>" + "Name" + "</td>" +
"<td>" + zoneData[ZONE_NAME] + "</td>" +
"</tr>" +
"<tr>" +
"<td>" + "Actual temp" + "</td>" +
"<td>" + zoneData[ZONE_ACTUAL_TEMP] + "</td>" +
"</tr>" +
"<tr>" +
"<td>" + "Target temp" + "</td>" +
"<td>" + zoneData[ZONE_TARGET_TEMP] + "</td>" +
"</tr>" +
"</table>";
}
HTML Hints and Tips
• Cross-browser compatibility issues
• HTML element support varies => unexpected behaviour
• HTML rendering varies => unexpected representation
• Browser testing may be time consuming
• HTTP GET request caching
• Client can cache GET requests
=> Put random string into each request
www.mydevice.com/control?led=1&status=on&msg=97453
• Consider AJAX framework
• GUI development
• Which one to choose?
• Cost and learning time?
Javascript Hints and Tips
• +ve – Javascript syntax has similarities to C
• Relatively easy to pick-up
• -ve – Javascript syntax has similarities to C
• Subtle semantic differences – easy to make big mistakes
• Many books and online resources
• Get editor that is Javascript (and HTML) aware
• Will save considerable time (=money)
• Use console object
• Output debug and status messages to browser console window
• Many browsers have Javascript debugger (F12)
• Inspect variables, set breakpoints, call stack, …
Summary
• HTTP is powerful, flexible device interface
• lwIP integration relatively smooth
• Ported to many hardware and software environments
• Good tools are essential – not a surprise!
• Minimal impact on existing device software
• HTML + DOM can produce effective dynamic pages
• (in the right hands)
• (Be prepared to) throw away prototypes
• JS can produce elegant, object-oriented code
• (in the right hands)
• Very easy to abuse – (be prepared to) throw away prototypes
• Easy to under-estimate effort for JS and HTML development
More Information
• Pebble Bay Consulting
• www.pebblebay.com
• info@pebblebay.com
• 01926 421700

More Related Content

What's hot

Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)
ewerkboy
 
Geek Sync | Infrastructure for the Data Professional: An Introduction
Geek Sync | Infrastructure for the Data Professional: An IntroductionGeek Sync | Infrastructure for the Data Professional: An Introduction
Geek Sync | Infrastructure for the Data Professional: An Introduction
IDERA Software
 
NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5
UniFabric
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
EDB
 

What's hot (20)

From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
 
Introduction to Business Processes 3.7
Introduction to Business Processes 3.7Introduction to Business Processes 3.7
Introduction to Business Processes 3.7
 
Geek Sync | Infrastructure for the Data Professional: An Introduction
Geek Sync | Infrastructure for the Data Professional: An IntroductionGeek Sync | Infrastructure for the Data Professional: An Introduction
Geek Sync | Infrastructure for the Data Professional: An Introduction
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 
EDB Postgres with Containers
EDB Postgres with ContainersEDB Postgres with Containers
EDB Postgres with Containers
 
NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5
 
Postgres-XC: Symmetric PostgreSQL Cluster
Postgres-XC: Symmetric PostgreSQL ClusterPostgres-XC: Symmetric PostgreSQL Cluster
Postgres-XC: Symmetric PostgreSQL Cluster
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional Databases
 
Best Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisBest Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on Solaris
 
Distributed applications using Hazelcast
Distributed applications using HazelcastDistributed applications using Hazelcast
Distributed applications using Hazelcast
 
Social Connections 13 - Troubleshooting Connections Pink
Social Connections 13 - Troubleshooting Connections PinkSocial Connections 13 - Troubleshooting Connections Pink
Social Connections 13 - Troubleshooting Connections Pink
 
Architecture for building scalable and highly available Postgres Cluster
Architecture for building scalable and highly available Postgres ClusterArchitecture for building scalable and highly available Postgres Cluster
Architecture for building scalable and highly available Postgres Cluster
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
 
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best PracticesApril, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
 
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, VerseNext Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
 
Deep Dive into RDS PostgreSQL Universe
Deep Dive into RDS PostgreSQL UniverseDeep Dive into RDS PostgreSQL Universe
Deep Dive into RDS PostgreSQL Universe
 

Viewers also liked (11)

Funny photos-2272847
Funny photos-2272847Funny photos-2272847
Funny photos-2272847
 
Cloud Computing: An Overview
Cloud Computing: An OverviewCloud Computing: An Overview
Cloud Computing: An Overview
 
Judy Poferl
Judy PoferlJudy Poferl
Judy Poferl
 
Wally Goulet
Wally GouletWally Goulet
Wally Goulet
 
乱乱
 
Sman1 x1 matahari
Sman1 x1 matahariSman1 x1 matahari
Sman1 x1 matahari
 
Tom Lilja
Tom LiljaTom Lilja
Tom Lilja
 
Fa qs about education in the u
Fa qs about education in the uFa qs about education in the u
Fa qs about education in the u
 
Matriz CTA secundaria
Matriz CTA secundariaMatriz CTA secundaria
Matriz CTA secundaria
 
Internship report presentation on cloud computing
Internship report presentation on cloud computingInternship report presentation on cloud computing
Internship report presentation on cloud computing
 
Embedded System Networking
Embedded System NetworkingEmbedded System Networking
Embedded System Networking
 

Similar to Adding Support for Networking and Web Technologies to an Embedded System

COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
Alfredo Abate
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing Levels
Positive Hack Days
 
Vulnerabilities in data processing levels
Vulnerabilities in data processing levelsVulnerabilities in data processing levels
Vulnerabilities in data processing levels
beched
 

Similar to Adding Support for Networking and Web Technologies to an Embedded System (20)

COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoop
 
Hpc lunch and learn
Hpc lunch and learnHpc lunch and learn
Hpc lunch and learn
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Performance management
Performance managementPerformance management
Performance management
 
SharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi VončinaSharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi Vončina
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing Levels
 
Vulnerabilities in data processing levels
Vulnerabilities in data processing levelsVulnerabilities in data processing levels
Vulnerabilities in data processing levels
 
Big Data Quickstart Series 3: Perform Data Integration
Big Data Quickstart Series 3: Perform Data IntegrationBig Data Quickstart Series 3: Perform Data Integration
Big Data Quickstart Series 3: Perform Data Integration
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
Hadoop introduction
Hadoop introductionHadoop introduction
Hadoop introduction
 
Powering up on PowerShell - BSides Greenville 2019
Powering up on PowerShell  - BSides Greenville 2019Powering up on PowerShell  - BSides Greenville 2019
Powering up on PowerShell - BSides Greenville 2019
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core Hacks
 
SQL Server 2019 CTP2.4
SQL Server 2019 CTP2.4SQL Server 2019 CTP2.4
SQL Server 2019 CTP2.4
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
PEARC17: Live Integrated Visualization Environment: An Experiment in General...
PEARC17: Live Integrated Visualization Environment: An Experiment in General...PEARC17: Live Integrated Visualization Environment: An Experiment in General...
PEARC17: Live Integrated Visualization Environment: An Experiment in General...
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
Informix Data Streaming Overview
Informix Data Streaming OverviewInformix Data Streaming Overview
Informix Data Streaming Overview
 
Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?Webinar: What's new in CDAP 3.5?
Webinar: What's new in CDAP 3.5?
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Adding Support for Networking and Web Technologies to an Embedded System

  • 1. Adding Support for Networking and Web Technologies to an Embedded System John Efstathiades Pebble Bay Consulting
  • 2. About Pebble Bay • Independent embedded software specialists • founded 8 years ago • based in Leamington Spa • Consultancy • independent review and advice • Software development • fully-managed projects • Expertise • real-time operating systems • hardware/software interfacing • software porting and optimisation 22-May-14 © 2012 Pebble Bay Consulting Limited 2
  • 3. Project Background • Industrial control system • Controller with LCD and keypad • Remote access from PC via RS-485 • Hardware re-design • Cortex M3 processor • Improved LCD panel • Reduce manufacturing costs • Make provision for networking • Software porting • Update low-level code • Minimize changes to GUI and remote access API
  • 4. Networking Update • RS-485 remote access protocol allows: • Configuration and data access • Front panel LCD and button mirroring • New customer requirements: • Access from mobile devices • Access over LAN/WAN/Internet(?) • Networking options • RS-485 extenders • No software changes • Relatively simple to deploy • Use on-board networking • No additional hardware • Extend product features
  • 5. Software Requirements • Industry standard networking technology • Maintain existing remote access protocol • Implement transport independent interface • Support existing customer base • Opportunity to sell enhanced capabilities • Brower-based client • OS and hardware independent • No additional software to install • User authentication • Restrict access to device
  • 6. Software Solution • lwIP TCP/IP network stack • Mature product with BSD licence • StellarisWare integration available (?) • HTTP web server available • AJAX Programming • Client-side processing • Dynamic page updates with new information • HTML and JavaScript • Fast client application prototyping • DataView class • Efficient mechanism for handling binary data • Easy to represent arrays and structs in target device memory
  • 7. lwIP Integration and Configuration • Documentation • lwIP Application Developers Manual • lwip/doc/rawapi.txt • Which release? • Latest (v1.4.1) vs. StellarisWare (v1.3.2) • lwIP operation • Periodic timer tick • Task model or interrupt thread • Compatible with main-loop design with interrupts • lwipOpts.h • Includes/excludes stack features and behaviour • Overrides defaults in lwip/src/include/lwip/opt.h • Debugging, memory management, stack components, …
  • 8. lwIP Abstraction Layer • No RTOS - define NO_SYS • Porting Layer • Ethernet hardware interface • Interrupt handling routines • lwIPInit() • Initialises stack modules • Registers Ethernet hardware with stack • lwIPEthernetIntHandler() • Handles received packets • Sends packets in transmit queue • lwIPTimer() • Stack timer processing
  • 9. HTTP Server • Provided as application add-on module • HTTP server module • Raw vs. socket interface • File system APIs • Optional ROM-based file system • Stores HTML pages and images • C array created by makefsdata perl script • Code space may be issue? • Integrated with lwIP • Call httpd_init()after lwip_init()
  • 10. Device Security • Need to protect device against • Unauthorised access • Data theft • Malicious intent • Authentication Options • Public key authentication • Digest authentication • Basic authentication • HTTP Basic Authentication • Simple mechanism using HTTP headers • Credentials encoded with Base64 – not encrypted • Fits in well with lwIP HTTP header processing
  • 11. HTTP Basic Authorisation • Supported by all browsers • Server • Sends Authenticate header with HTTP 401 response • Client • Sends Authorization request header (in every transaction) • Base64 encoded username and password • Cached by browser once accepted by server • lwIP HTTP header processing easy to extend • Extend http_recv() to look for Authorization header • Extend get_http_headers() to send 401 if no authorisation • Add routines to decode and check user credentials
  • 12.
  • 13. lwIP Hints and Tips • Debug control in lwipOpts.h • Overrides defaults in lwip/src/include/lwip/debug.h • LWIP_DEBUGF() common debug macro • LWIP_PLATFORM_DIAG() device-specific debug output • Stack runs in interrupt context • Enabling debug could affect system behaviour • Memory trace buffer and JTAG debugger less intrusive • May need to experiment with memory configuration • Overall heap size • lwIP buffer pool size • Received packets stored in buffer chains • Buffer payload size set by PBUF_POOL_BUFSIZE => default is 256
  • 14. AJAX Programming Methodology • Collection of related technologies • HTML for presentation of data • XMLHttpRequest object for asynchronous server communication • Document Object Model for dynamic display and manipulation of data • JavaScript implementation language • Client application sends request to server (device) • Request encoded in HTTP request • Read/write operational data • Send control/status requests – get battery level, start processing, … • Client application receives asynchronous response • Callback function invoked when data received • Page contents dynamically updated – no page refresh required
  • 15. Device Support for Web I/O • HTTP GET vs. POST • GET has query strings encoded in URL • POST has query strings in HTTP message body • POST is “preferred” mechanism but not supported in lwip 1.3.2 • Define query strings for control/status requests www.mydevice.com/control?led=1&status=on www.mydevice.com/status?led=1 • Direct handling of HTTP Query Strings • Extract name/value tuples from HTTP request • Implement handler for each query type • Response sent to client when operation is complete • Self-contained => minimal impact on existing software
  • 16. Query String Processing /* * Find an asynchronous I/O handler */ if (webIoHandlerGet (queryStr, &ioFunc, &bufLen) == 0) { char * pBuf; int responseLen; /* Allocate memory for the response string */ pBuf = mem_malloc (bufLen); if (pBuf == 0) { mem_free (ptFile); return NULL; } /* Perform the I/O operation */ responseLen = ioFunc (name, pBuf, bufLen); /* * After the I/O handler has been invoked all the data to be returned * is in the response buffer so set index to the end of the "file". */
  • 17. HTTP and Binary Data • Poor browser support for sending/receiving binary data • Standard problems: • Byte order • Alignment and packing • Message/structure delimiters • DataView and TypedArray objects • Allows complex data types to be created • Independent of client’s native byte order • Base64 encoding • Standard mechanism for encoding binary data into ASCII strings • Simple algorithm to implement
  • 18. DataView Example /* * Construct a key press message */ function v42KeypressCmd(key) { var buffer = new ArrayBuffer (REM_KEYPRESS_CMD_PKT_LEN); var dv = new DataView (buffer); var byteArray = new Uint8Array(buffer); var crc; dv.setUint8 (REM_CMD_BYTE_OFFSET, REM_KEYPRESS_CMD_BYTE); dv.setUint8 (REM_ID_BYTE_OFFSET, unitNum & 0x0f); dv.setUint16 (REM_MEM_ADDR_OFFSET, 0); dv.setUint16 (REM_RETURN_MSG_LEN_OFFSET, REM_KEYPRESS_CMD_RESP_MSG_LEN); dv.setUint16 (REM_PKT_LEN_OFFSET, REM_KEYPRESS_CMD_PKT_LEN); dv.setUint8 (REM_KEYPRESS_CMD_MSG_KEY, key); dv.setUint8 (REM_KEYPRESS_CMD_MSG_PREV, 0); dv.setUint8 (REM_KEYPRESS_CMD_MSG_SLAVE, 1); crc = crc16 (byteArray, REM_KEYPRESS_CMD_PKT_LEN - REM_TRAILER_LENGTH); dv.setUint16 (REM_KEYPRESS_CMD_CRC_OFFSET, crc); return base64Encode (byteArray); }
  • 19. HTML Document Object Model • Cross-platform representation of objects in HTML • HTML elements as objects • Properties of HTML elements • Methods and events for HTML elements Dynamically Get, Change, Add, or Delete HTML elements • Use JavaScript to create dynamic HTML • Update pages with latest device data • Build page elements “on the fly” based on device responses • Periodic page updates using timer document.getElementById(“<element>").innerHTML =
  • 20. JavaScript DOM Example /* * Update the zone summary table */ function zoneTableBuild (zoneId, zoneData) { document.getElementById("zone_data").innerHTML = "<table>" + "<tr>" + "<td>" + "Zone id" + "</td>" + "<td>" + zoneId + "</td>" + "</tr>" + "<tr>" + "<td>" + "Name" + "</td>" + "<td>" + zoneData[ZONE_NAME] + "</td>" + "</tr>" + "<tr>" + "<td>" + "Actual temp" + "</td>" + "<td>" + zoneData[ZONE_ACTUAL_TEMP] + "</td>" + "</tr>" + "<tr>" + "<td>" + "Target temp" + "</td>" + "<td>" + zoneData[ZONE_TARGET_TEMP] + "</td>" + "</tr>" + "</table>"; }
  • 21. HTML Hints and Tips • Cross-browser compatibility issues • HTML element support varies => unexpected behaviour • HTML rendering varies => unexpected representation • Browser testing may be time consuming • HTTP GET request caching • Client can cache GET requests => Put random string into each request www.mydevice.com/control?led=1&status=on&msg=97453 • Consider AJAX framework • GUI development • Which one to choose? • Cost and learning time?
  • 22. Javascript Hints and Tips • +ve – Javascript syntax has similarities to C • Relatively easy to pick-up • -ve – Javascript syntax has similarities to C • Subtle semantic differences – easy to make big mistakes • Many books and online resources • Get editor that is Javascript (and HTML) aware • Will save considerable time (=money) • Use console object • Output debug and status messages to browser console window • Many browsers have Javascript debugger (F12) • Inspect variables, set breakpoints, call stack, …
  • 23. Summary • HTTP is powerful, flexible device interface • lwIP integration relatively smooth • Ported to many hardware and software environments • Good tools are essential – not a surprise! • Minimal impact on existing device software • HTML + DOM can produce effective dynamic pages • (in the right hands) • (Be prepared to) throw away prototypes • JS can produce elegant, object-oriented code • (in the right hands) • Very easy to abuse – (be prepared to) throw away prototypes • Easy to under-estimate effort for JS and HTML development
  • 24. More Information • Pebble Bay Consulting • www.pebblebay.com • info@pebblebay.com • 01926 421700