Care for some JavaScript with your IoT? New QCA4020 developer projects from Moddable.

Thursday 8/22/19 09:00am
|
Posted By Rajan Mistry
  • Up0
  • Down0

Snapdragon and Qualcomm branded products are products of
Qualcomm Technologies, Inc. and/or its subsidiaries.

If you’ve started building embedded IoT devices on the Qualcomm® QCA4020 and Qualcomm® QCA4024, you’ve probably seen how tight your code needs to be. Sure, you get Wi-Fi, Bluetooth 5 and Zigbee/Thread connectivity all wrapped up in one compact system on chip (SoC), but embedded development is about making the most of scarce resources. Several developers featured on our Projects page have built tight, embedded apps with the QCA4020 Development Kit, and we have three new projects for you.

Moddable has announced that its Moddable SDK now supports the QCA4020 platform for efficient, security-rich application development in JavaScript. The Moddable SDK is a combination of development tools and runtime software to create applications for resource-constrained SoC and microcontroller platforms. With this port of the SDK, you can create robust applications combining JavaScript and native C/C++ that run efficiently on devices you build around the QCA4020.

And, because showing is better than telling, Moddable has also published three QCA4020 projects based on its SDK.

1. Get started with a Hello World project

The Hello World project is a beginner-level project that introduces you to Moddable SDK development in JavaScript on the QCA4020 Development Kit. It covers setup of the Linux host environment and walks you through building, flashing and running the helloworld JavaScript example app in the Moddable SDK.

The app connects to Moddable’s JavaScript source-level debugger, xsbug, and traces the string 'Hello, world – sample’ to the debugger console.

Inside the Moddable SDK you’ll find several example apps that demonstrate available modules such as display and sensor drivers, networking and Bluetooth low energy (BLE).

2. User interface development using JavaScript

In this project, a JavaScript weather app from the Moddable SDK issues HTTP requests to the OpenWeatherMap REST API. It then displays the forecast for various U.S. cities on a color 240 x 320 LCD.

The app is built with the Piu UI framework, designed for smooth animations and crisp font rendering. You’ll see that, even on microcontrollers with tight resource constraints like the QCA4020, you can use Piu to build a UI in JavaScript with text, buttons and animations, as shown in the image.

The Piu UI framework allows you to develop beautiful, advanced user interfaces that integrate fonts and images, have responsive layouts, and display smooth, flicker-free animations. The project also shows you how to attach a SPI LCD and use Moddable’s integrated ILI9341 MIPI-compatible display driver.

3. Using JavaScript for networking, HTTP and REST APIs (JSON) on embedded devices

This project showcases the httpgetjson example app, a JavaScript app from the Moddable SDK. The app issues an HTTP request to the OpenWeatherMap REST API to retrieve the current weather in Menlo Park, California. The response is delivered in JSON format, parsed into a JavaScript object and output to the xsbug debugger, as shown in the screenshot.

The app uses a dictionary of properties along with JavaScript template literals. Compared to native C code, this is a much simpler way to build and issue an HTTP request.

Why? First, JavaScript automatically allocates the memory required to contain the URI components. Next, it frees the memory once the request is complete, reducing the risk of memory buffer overrun and related security vulnerabilities. Then, you specify HTTP request properties, like headers and body, by simply adding associated properties to the dictionary. Finally, the HTTP 'Request’ class is the only module required for the request; no additional networking, HTTP or Wi-Fi libraries are needed.

Next Steps

Who knew how quick and efficient embedded development could be in JavaScript using the Moddable SDK runtime software and development tools?

But I don’t want to steal Moddable’s thunder. The company has put together a trio of developer projects with ample documentation and step-by-step instructions, so head over to our Projects page and take them for a spin.

Sections: