Our book is now for nRF52 development too!  

IoT Development for ESP32 and ESP8266 with JavaScript

A Practical Guide to XS and the Moddable SDK

The software that powers IoT is changing rapidly as customers demand more sophisticated products. Developers creating the software for embedded products need to adopt new techniques to meet these increased customer expectations.

This book introduces the Moddable SDK, a breakthrough in embedded software that gives professional developers the tools they need to deliver products today. The Moddable SDK combines the ease of use of modern JavaScript with the speed of C/C++ code. Developers working this way are more productive, without compromising performance or flexibility.

The book focuses on the ESP32 and ESP8266 microcontrollers because they deliver a major leap in capabilities at a very low cost. These chips power commercial products from major companies worldwide and are also popular with students and makers.

This book draws on the author's experience creating the Moddable SDK and using it to deliver products. They introduce the reader to the Moddable SDK using short examples of techniques used in actual products. They wrote this book for embedded developers, web developers, product designers, and makers.



What's in the book

This book introduces a powerful new approach to embedded development, grounded in modern JavaScript. Each chapter goes in‑depth on a single topic, providing both practical knowledge and examples for you to learn from, run, modify, and incorporate into your products.

Examples are available in the book's repository on GitHub. The examples can be built using a macOS, Windows, or Linux computer.

JavaScript

JavaScript is the language of the web, popular for communication and building user interfaces. It just makes sense to use it in connected IoT products too. You'll learn how to use JavaScript efficiently in IoT products. For embedded developers, JavaScript is a new tool to create more reliable, more powerful products more quickly. For web developers, JavaScript is a way apply their skills to IoT products. The book also includes a fast-paced, practical introduction to JavaScript for embedded programmers more familiar with C or C++.

Network

Network communication is fundamental to IoT. All of the major protocols used to communicate with IoT cloud services are covered including HTTP, WebSockets, and MQTT. Examples walk through the process of establishing a secure connection using TLS, including the use of private certificates. You'll learn to scan for Wi‑Fi networks and manage Wi-Fi connections using the built-in Wi‑Fi on the ESP32 and ESP8266. Once connected to Wi-Fi, you'll learn how to use mDNS to discover other nearby IoT devices.

Graphics

Displays make products easier to understand and use, so it is no surprise they are becoming more common in IoT products. You'll learn how to overcome the constraints of inexpensive microcontrollers to deliver high-quality, high-performance graphics, text, and animation using the APIs and build tools in the Moddable SDK.

Sensors

Sensors are a key hardware component in most IoT products. You'll learn how to read data from a widely used temperature sensor, configure the resolution of its readings, and manage its energy use. More importantly, you'll see how to read a sensor's data sheet extract the information needed to write the software to communicate with it, so you'll be ready to support any sensor your project needs.

User interface

Getting pixels on the screen is only the first step in building a user interface. It is challenging to create an interface that looks and feels like it belongs next to a modern mobile phone. The Piu user interface framework brings powerful ideas from the web to inexpensive microcontrollers. That includes cascading styles, responsive layout, timeline driven animation, and declarative user interface specification.

A series of step-by-step examples shows you how to use Piu to create a beautifully animated interface for your project, including an expanding touch keyboard for small screens.

Hardware

When writing software for an IoT product, eventually you need to write code that interacts directly with the hardware. You'll learn how to detect presses of tactile buttons, control single and tri‑color LEDs, turn servo motors commonly used in robotics, retrieve readings from sensors, and play sound on a speaker.

For web developers getting started with embedded development the book introduces hardware communication protocols used in microcontrollers. It also includes color wiring diagrams for connecting inexpensive hardware components to your development board. No soldering required!

Bluetooth Low Energy (BLE)

BLE is the most energy efficient way for IoT products to communicate wirelessly. It is found in electric toothbrushes, ovens, phones, lightbulbs, and more. Starting with a simple JSON device description, you'll see how to implement a heart rate monitor peripheral for ESP32 that communicates with your phone. You'll also learn how to advertise services over BLE and discover nearby BLE devices.

BLE has a lot of specialized terminology that can be overwhelming when you are just getting started. This book guides you through the maze of terminology by fully and precisely introducing key terms and concepts from the BLE standard.

JavaScript for Embedded C and C++ Programmers

Many embedded developers working in C or C++ see what's possible with the Moddable SDK and want to give it a try. They hesitate because they don't yet know JavaScript, and all the introductions are written for developers working on the web. This book contains the first ever introduction to JavaScript written for C and C++ programmers. The focus is on the JavaScript features essential for embedded development, including topics often overlooked in web development like working with binary data and memory management.

The chapter combines dozens of short code examples with explanations that highlight the similarities and differences to C and C++ code. Because C and JavaScript have so much in common, this fast paced, no-nonsense introduction will have you quickly reading and writing JavaScript.

Who should read this book

This book is for professionals creating IoT products. It explains the capabilities and constraints of microcontrollers and provides a wealth of practical example code to perform common tasks.

The book is written for both embedded developers getting started with JavaScript and web developers getting started with embedded development. It is also a valuable resource for students, makers, and hobbyists looking to get the most out of their ESP32 and ESP8266 development boards.

Embedded developers

The ever increasing demand for more features in IoT products means embedded developers are expected to move at web development speed. Using the high level JavaScript language lets developers move faster. The many powerful modules built into the Moddable SDK — graphics, user interface, networking, BLE, sensors — augment the capabilities of the embedded platform. The book also shows you how to bridge between JavaScript and C code for a speed boost or to reuse existing native code.

Web developers

Web developers are constantly learning new tools and techniques to grow their skills. With modern JavaScript now a reality on low cost IoT hardware, web developers have a head start in extending their skills to an entirely new field, to move from animating elements on a web page to animating objects the real world. This book introduces key concepts in embedded development, so you don't need any prior embedded knowledge.

Product designers

The choice of hardware to use in a product has far reaching consequences, from the product's features and performance to its price. Many product designers, unfamiliar with just how powerful modern microcontrollers are, choose unnecessarily powerful hardware that costs more. This book shows how much can be done with hardware that costs just a few dollars. It also includes a detailed discussion about adding a cost effective display to an IoT product.

Makers

Makers are looking for the fastest way to bring their project to life. Using JavaScript and the Moddable SDK lets makers focus more on achieving their vision because they need to spend less time on technical details. The forgiving nature of the JavaScript language is particularly valuable when exploring and prototyping. Once you've finished reading this book, you'll be ready to use many modules in the Moddable SDK in your own projects.

What readers are saying

"This book is brilliant for getting started with JS on embedded devices."

Nick Hehr, Twitter (February 3, 2022)

"IoT Development for ESP32 and ESP8266 with JavaScript is a fantastic resource to dive into the capabilities of Moddable and XS. The first third of the book is perhaps the best introduction to JavaScript for C/C++ developers I've seen. Even though I've programmed in JavaScript for years, it was still informative and filled in some important gaps for how it relates to the microcontroller world." ... "If you want to accelerate your development cycle, and build world class microcontroller experience, I highly recommend Moddable and this book is a 'must have' compliment to that platform."

TechFanatic, Amazon Review (December 5, 2020)

"Programmers, product managers, and designers will get a sense of how much is now possible on very small systems. It is a complete guide for those with and without JavaScript experience."

Bob Frankston, Amazon Review (November 25, 2020)

"IoT Development for ESP32 and ESP8266 with JavaScript continues with the best guide of JavaScript I have ever read. Kernighan and Ritchie can eat their hearts out. I have developed in JavaScript (sic) for over a decade and I thought I knew and understood the language well. I was amazed at how much I learned reading this section. I drank it in! The organization, and writing is a pleasure. The examples are perfect. Just a pleasure."

Jill Wernicke, Amazon Review (December 20, 2020)

"Now anybody can jump into the world of hardware programming with JavaScript."

Kentaro Miura, Amazon Review (November 27, 2020)

"I would recommend [IoT Development for ESP32 and ESP8266 with JavaScript] for anyone that is starting out trying to learn JavaScript to bring a UI to life on a Moddable device."

Patrick S. Sweeney, Amazon Review (February 22, 2021)

"WOW this is a fantastic book (and beautiful to look at full color diagrams!) 👏💕"
"Chapter 2: JavaScript for Embedded C and C++ Programmers is 100 pages long! Amazing! I love that so much care was put into centering this onboard path 🥰"

Rick Waldron, Twitter (December 16, 2021)

"Reading the 'JavaScript for Embedded C and C++ Programmers' is fun [from my] perspective as a full-time JS dev."

Nick Hehr, Twitter (November 29, 2020)

"...highly recommend [IoT Development for ESP32 and ESP8266 with JavaScript it does a great job of explaining what's really unique about Moddable for small footprint devices, and the examples show the power of mods, especially how simple and fast development can be."

About the authors

Peter Hoddie and Lizzie Prader worked together for years to bring the power and flexibility of JavaScript to embedded developers. Before founding Moddable in 2017, they worked together on the KinomaJS, Kinoma Create, and Kinoma Element projects at Marvell Semiconductor. Both contribute to Ecma TC53, a new standard for JavaScript APIs in embedded systems.

Peter and Lizzie's provocative talk "Resuscitating IoT with JavaScript" at OpenJS World 2020 is available for viewing. Their follow-up interview with Bruno Couriol of InfoQ goes in depth about their vision for an IoT powered by standard, open JavaScript.

Peter Hoddie  

Peter Hoddie is an engineer and entrepreneur focused on client software. He is recognized for crafting compact and efficient code that pushes the boundaries of user experience on consumer hardware. The software he and his teams have built has powered mass-market consumer products from companies including Apple, Palm, Sling, HP, Sony, and Whirlpool. Peter recognizes that the first users of any product are the developers creating it, and that those developers cannot build compelling consumer products on a foundation thats unstable, complex, or confusing.

Peter has founded several companies including Moddable and Kinoma, which merged into Marvell Semiconductor. He led QuickTime development at Apple during the 1990s as a Distinguished Engineer. He contributed to the development of the QuickTime file format and its adoption by ISO into the MPEG-4 standard. He is a member of the JavaScript language standards committee (Ecma TC39) and chair of ECMAScript Modules for Embedded Systems (Ecma TC53).


Lizzie Prader  

Lizzie Prader is an engineer, educated in theoretical computer science, currently focused on developers success. She recognizes the importance of customer support during all stages of a project, and enjoys working with developers to smooth the on-ramp to embedded development. Working with users of all skill levels from professional engineers to makers and hobbyists to absolute programming beginners has made her an advocate of well-organized documentation and readable code.

Prior to Moddable, Lizzie worked as a developer relations engineer at Kinoma. Her main goal was to help customers get the most out of Kinoma's software and hardware prototyping products, both through direct contact with developers and by creating a variety of resources including sample code, tutorials, and blog posts.

Special Offers from Moddable

All books ordered from Moddable include FREE shipping

Book orders are only available in the United States

Book and device bundle

Get our new book along with Moddable Two, our most popular and most powerful development board. Shipping is free!

With a Moddable Two, you'll be ready to run the examples in the book including networking, BLE, graphics, and user interface. Moddable Two includes an ESP32 microcontroller with Wi‑Fi and BLE built in, plus a high quality color IPS display with capacitive touch. The bundle also includes the Moddable Programmer for installing and debugging over USB.

Just the book

Get "IoT Development for ESP32 and ESP8266 with JavaScript" and the shipping is on us!

You can run the examples on popular development boards including Moddable One, Moddable Two, Moddable Three, M5Stack, M5StackFire, M5StackCore2, M5AtomMatrix, M5AtomEcho, M5AtomLite, M5StickC, ESP32Thing, NodeMCUESP8266, NodeMCUESP32, and ESP32-WROVER.

Book availability

Purchase this book through your favorite book seller and these vendors:

Amazon
Amazon-Kindle
Keplers
Keplers
Springer
Available in PDF
and ePub formats.
ACM
Available in ACM Learning Center (ACM members only).