IoT Development for ESP32 and ESP8266 with JavaScript : A Practical Guide to XS and the Moddable SDK
معرفی کتاب «IoT Development for ESP32 and ESP8266 with JavaScript : A Practical Guide to XS and the Moddable SDK» نوشتهٔ Peter Hoddie و Lizzie Prader، منتشرشده توسط نشر Apress : Imprint: Apress در سال 2020. این کتاب در 602 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «IoT Development for ESP32 and ESP8266 with JavaScript : A Practical Guide to XS and the Moddable SDK» در دستهٔ برنامهنویسی قرار دارد.
This book introduces a new approach to embedded development, grounded in modern, industry-standard JavaScript. Using the same language that powers web browsers and Node.js, the Moddable SDK empowers IoT developers to apply many of the same tools and techniques used to build sophisticated websites and mobile apps. The Moddable SDK enables you to unlock the full potential of inexpensive microcontrollers like the ESP32 and ESP8266. Coding for these microcontrollers in C or C++ with the ESP-IDF and Arduino SDKs works for building basic products but doesn't scale to handle the increasingly complex IoT products that customers expect. The Moddable SDK adds the lightweight XS JavaScript engine to those traditional environments, accelerating development with JavaScript while keeping the performance benefits of a native SDK.Building user interfaces and communicating over the network are two areas where JavaScript really shines. __IoT Development for ESP32 and ESP8266 with JavaScript__ shows you how to build responsive touch screen user interfaces using the Piu framework. You'll learn how easy it is to securely send and receive JSON data over Wi-Fi with elegant JavaScript APIs for common IoT protocols, including HTTP/HTTPS, WebSocket, MQTT, and mDNS. You'll also learn how to integrate common sensors and actuators, Bluetooth Low Energy (BLE), file systems, and more into your projects, and you'll see firsthand how JavaScript makes it easier to combine these diverse technologies. If you're an embedded C or C++ developer who has never worked in JavaScript, don't worry. This book includes an introduction to the JavaScript language just for embedded developers experienced with C or C++.**What You'll Learn** + Building, installing, and debugging JavaScript projects on the ESP32 and ESP8266 + Using modern JavaScript for all aspects of embedded development with the Moddable SDK + Developing IoT products with animated user interfaces, touch input, networking, BLE, sensors, actuators, and more **Who This Book Is For** + Professional embedded developers who want the speed, flexibility, and power of web development in their embedded software work + Makers who want a faster, easier way to build their hobby projects + Web developers working in JavaScript who want to extend their skills to hardware products Table of Contents About the Authors About the Technical Reviewers About the Editor Acknowledgments Foreword Introduction Chapter 1: Getting Started Hardware Requirements Software Requirements Downloading the Example Code Setting Up Your Build Environment Using xsbug Important Features for Examples in This Book Running Examples Installing the Host mcconfig Confirming the Host Was Installed Installing helloworld mcrun Finishing Up Troubleshooting Device Not Connected/Recognized macOS/Linux Windows Incompatible Baud Rate Device Not in Bootloader Mode Adding a Display Connecting a Display to the ESP32 Connecting a Display to the ESP8266 Installing helloworld-gui Conclusion Chapter 2: JavaScript for Embedded C and C++ Programmers Fundamental Syntax “Hello, world” Semicolons Declaring Variables and Constants The if Statement The switch Statement Loops Types undefined Boolean Values Numbers Infinity and NaN Bases Numeric Separators Bitwise Operators The Math Object Converting Numbers to Strings Converting Strings to Numbers Strings Accessing Individual Characters Modifying Strings Determining the Length of Strings Embedding Quotes and Control Characters String Substitution Adding Strings Converting String Case Extracting Parts of Strings Repeating Strings Trimming Strings Searching Strings Functions Function Arguments Passing Functions As Arguments Declaring Functions Closures Objects Object Shorthand Deleting Properties Checking for Properties Adding Properties to Functions Freezing Objects null Comparisons Comparing Objects Errors and Exceptions Classes Class Constructor and Methods Static Methods Subclasses Private Fields Private Methods Using Callback Functions in Classes Modules Importing from Modules Exporting from Modules ECMAScript Modules vs. CommonJS Modules Globals Arrays Array Shorthand Accessing Elements of an Array Iterating over Arrays Adding and Removing Elements of an Array Searching Arrays Sorting Arrays Binary Data ArrayBuffer Typed Arrays Typed Array Shorthand Copying Typed Arrays Filling Typed Arrays Writing Typed Array Values Floating-Point Typed Arrays Data Views Accessing Values of a Data View Memory Management The Date Class Event-Driven Programming Conclusion Chapter 3: Networking About Networking Connecting to Wi-Fi Connecting from the Command Line Connecting with Code Connecting to Any Open Access Point Installing the Network Host Installing Examples Getting Network Information Making HTTP Requests Fundamentals GET Streaming GET GET JSON Subclassing an HTTP Request Setting Request Headers Getting Response Headers POST Handling Errors Securing Connections with TLS Using TLS with the SecureSocket Class Public Certificates Private Certificates Creating an HTTP Server Fundamentals Responding to a Request Responding to JSON PUT Receiving a Streaming Request Sending a Streaming Response mDNS Claiming a Name Finding a Service Advertising a Service WebSocket Connecting to a WebSocket Server Creating a WebSocket Server MQTT Connecting to an MQTT Server Subscribing to a Topic Publishing to a Topic SNTP Advanced Topics Creating a Wi-Fi Access Point Promises and Asynchronous Functions Conclusion Chapter 4: Bluetooth Low Energy (BLE) BLE Basics GAP Centrals and Peripherals GATT Clients and Servers GAP vs. GATT Profiles, Services, and Characteristics Profiles Services Characteristics The BLE API of the Moddable SDK The BLEClient Class The BLEServer Class Installing the BLE Host Creating a BLE Scanner Creating Two-Way Communication Connecting to the Peripheral The onConnected Callback The onServices Callback The onCharacteristics Callback Receiving Notifications Creating a Heart Rate Monitor Defining and Deploying Services Advertising Establishing a Connection Sending Notifications Responding to Read Requests Establishing Secure Communication Secure Heart Rate Monitor Conclusion Chapter 5: Files and Data Installing the Files and Data Host Files File Classes File Paths File Operations Determining Whether a File Exists Deleting a File Renaming a File Opening a File Writing to a File Writing Text Writing Binary Data Getting File Size Writing Mixed Types Reading from a File Reading Text Reading Text in Pieces Reading Binary Data Reading Binary Data in Pieces Directories Iterating over Directories Iterating with JavaScript Iterators Getting File System Information Preferences The Preference Class Preference Names Preference Data Reading and Writing Preferences Deleting Preferences Don’t Use JSON Security Resources Adding Resources to a Project Accessing Resources Using Resources Accessing Flash Memory Directly Flash Hardware Fundamentals Accessing Flash Partitions Getting Partition Information Reading from a Flash Partition Erasing a Flash Partition Writing to a Flash Partition Mapping a Flash Partition Example: Frequently Updated Integer Initializing the Block Updating the Value Reading the Value Benefits and Future Work Conclusion Chapter 6: Hardware Installing the Hardware Host Notes on Wiring Following the Wiring Instructions Troubleshooting Wiring Issues Blinking an LED Reading a Button Other Digital Input Modes ESP32 Wiring Instructions ESP8266 Wiring Instructions Understanding the external-button Code More About Pull-Up and Pull-Down Resistors Monitoring for Changes Controlling a Tri-color LED LED Setup ESP32 Wiring Instructions ESP8266 Wiring Instructions Using Digital with a Tri-color LED Using PWM with a Tri-color LED Rotating a Servo ESP32 Wiring Instructions ESP8266 Wiring Instructions Understanding the servo Code Getting the Temperature TMP36 ESP32 Wiring Instructions ESP8266 Wiring Instructions Understanding the tmp36 Code TMP102 ESP32 Wiring Instructions ESP8266 Wiring Instructions Understanding the tmp102 Code Using SMBus Configuring the TMP102 Reading Higher Temperatures with Extended Mode Setting the Conversion Rate Saving Energy with Shutdown Mode Taking One-Shot Temperature Readings Conclusion Chapter 7: Audio Speaker Options Adding the Analog Speaker ESP32 Wiring Instructions ESP8266 Wiring Instructions Adding an I2S Chip and Digital Speaker ESP32 Wiring Instructions ESP8266 Wiring Instructions Installing the Audio Host The AudioOut Class AudioOut Configuration Audio Hardware Protocols Pulse-Density Modulation (PDM) I2S Audio Data Formats Audio Compression Setting the Audio Queue Length Playing Audio with AudioOut Instantiating AudioOut Playing a Single Sound Repeating a Sound Using Callbacks to Synchronize Audio Using Commands to Change Volume Playing a Sequence of Sounds Playing Sounds Simultaneously Playing Part of a Sound Flushing the Audio Queue Conclusion Chapter 8: Graphics Fundamentals Why Add a Display? Overcoming Hardware Limitations Pixel Rate Impacts Frame Rate Drawing Frames Scanline Rendering Restricting the Drawing Area Pixels Pixel Formats Configuring a Host for a Pixel Format Freedom to Choose a Display Graphics Assets Masks Adding Masks to Your Project Mask Compression Uncompressed Masks Fonts Converting TrueType Fonts to Bitmap Fonts Using Scalable Fonts Font Copyright Color Images Display Rotation Rotating in Software Rotating in Hardware Poco or Piu? Conclusion Chapter 9: Drawing Graphics with Poco Installing the Poco Host Preparing to Draw Drawing Rectangles Filling the Screen Updating Part of the Screen Drawing Random Rectangles Drawing Blended Rectangles Drawing Bitmaps Drawing Masks Using an Uncompressed Mask Drawing Part of a Mask Fading a Mask In and Out Drawing Color Images Drawing JPEG Images Storing JPEG Data in Resources Drawing a JPEG Image from Memory Drawing a JPEG Image During Decompression Filling with Color Images Drawing Masked Color Images Drawing Text Drawing a Text Shadow Measuring Text Truncating Text Wrapping Text Additional Drawing Techniques Restricting Text to a Box Easily Reusing Drawing Code Efficiently Rendering Gradients Touch Input Accessing the Touch Driver Reading Touch Input Using Multi-touch Applying Rotation Conclusion Chapter 10: Building User Interfaces with Piu Key Concepts Everything Is an Object Every User Interface Element Is a Content Object Not All Piu Objects Are Content Objects Defining Appearance Controlling Behavior Animating Installing the Piu Host “Hello, World” with Piu Fonts Font Names Font Resources Additional Notes on Fonts Adding Color Specifying Color Changing Color Based on State Responding to Events with Behaviors “Hello, World” with a Behavior The onTimeChanged and onDisplaying Events Adding Images Drawing Part of an Image Drawing Multiple Icons from One Image Using Masks Tiling Images Tiling a Single Image Drawing 9-Patch Images with Tiles Building Compound User Interface Elements Creating a Header Relative and Absolute Coordinates Adding and Removing Container Contents One Container for Each Content Object Building Responsive Layouts Row and Column Layouts Scrolling Content Templates for Content Objects Creating a Button Template Class Content Constructor Arguments The Instantiating Data Argument The Content Dictionary Argument Accessing Content Objects in a Container Using first, last, next, and previous Accessing Children by Index and Name Accessing Content with Anchors Defining and Triggering Your Own Events Triggering Events on a Content Object Distributing Events Inside a Container Bubbling Events Up the Containment Hierarchy Animation Easing Equations Animating Content Objects Animating Transitions Drawing a Graph in Real Time Adding an Onscreen Keyboard Organizing User Interface Code Using Modules The Modules The Application Logic The Splash Screen The Home Screen Adding More Screens Conclusion Chapter 11: Adding Native Code Installing the Host Generating Random Integers Creating a Native Function Implementing a Native Function Using the Hardware Random Number Generator Restricting Random Numbers to a Range Comparing Random Number Approaches The BitArray Class Using Memory Allocated by ArrayBuffer The get Function The set Function Security Vulnerability Using Memory Allocated by calloc The Class Declaration The Constructor The Destructor The close Function The get and set Functions The length Property Advantages to This Approach Wi-Fi Signal Notifications The Test Code The WiFiRSSINotify Class The Native RSSINotifyRecord Structure The Constructor The Destructor The close Function The Callback Additional Techniques Debugging Native Code Accessing Global Variables Getting a Function’s Return Value Getting Values Setting Values Determining a Value’s Type Working with Strings Ensuring Your Buffer Pointers Are Valid Integrating with C++ Using Threads Conclusion Glossary Index This book introduces a new approach to embedded development, grounded in modern, industry-standard JavaScript. Using the same language that powers web browsers and Node.js, the Moddable SDK empowers IoT developers to apply many of the same tools and techniques used to build sophisticated websites and mobile apps. The Moddable SDK enables you to unlock the full potential of inexpensive microcontrollers like the ESP32 and ESP8266. Coding for these microcontrollers in C or C++ with the ESP-IDF and Arduino SDKs works for building basic products but doesn't scale to handle the increasingly complex IoT products that customers expect. The Moddable SDK adds the lightweight XS JavaScript engine to those traditional environments, accelerating development with JavaScript while keeping the performance benefits of a native SDK. Building user interfaces and communicating over the network are two areas where JavaScript really shines. IoT Development for ESP32 and ESP8266 with JavaScript shows you how to build responsive touch screen user interfaces using the Piu framework. You'll learn how easy it is to securely send and receive JSON data over Wi-Fi with elegant JavaScript APIs for common IoT protocols, including HTTP/HTTPS, WebSocket, MQTT, and mDNS. You'll also learn how to integrate common sensors and actuators, Bluetooth Low Energy (BLE), file systems, and more into your projects, and you'll see firsthand how JavaScript makes it easier to combine these diverse technologies. If you're an embedded C or C++ developer who has never worked in JavaScript, don't worry. This book includes an introduction to the JavaScript language just for embedded developers experienced with C or C++. What You'll Learn Building, installing, and debugging JavaScript projects on the ESP32 and ESP8266 Using modern JavaScript for all aspects of embedded development with the Moddable SDK Developing IoT products with animated user interfaces, touch input, networking, BLE, sensors, actuators, and more Who This Book Is For Professional embedded developers who want the speed, flexibility, and power of web development in their embedded software work Makers who want a faster, easier way to build their hobby projects Web developers working in JavaScript who want to extend their skills to hardware products
دانلود کتاب IoT Development for ESP32 and ESP8266 with JavaScript : A Practical Guide to XS and the Moddable SDK