Peter Hoddie, Kinoma VP, gave a talk at the IoT-themed API-Craft meet-up at the Tradeshift HQ in San Francisco. He discusses connectivity, the challenges and demands of IoT, and how Kinoma is building a set of APIs for the IoT.
2. @kinoma
Overview
1. IoT is the modernization of embedded computing, defined by
connectivity
2. How IoT devices are programmed needs to change
3. The unique challenges, demands, and priorities of IoT
4. Why Kinoma uses JavaScript together with C
5. Three areas of API functionality that are central to IoT
6. How Kinoma is building a set of APIs for IoT
5. @kinoma
High level programming languages
on embedded systems
Relatedly, writing software to control drones, vending
machines, and dishwashers has become as easy as
spinning up a website. Fast, efficient processors … are
turning JavaScript into a popular embedded
programming language—unthinkable less than a
decade ago.
6. JavaScriptforIoT
@kinoma
• JSON built in – de facto data format of the web
• Exceptionally portable – OS independent
• Helps eliminate memory leaks so devices can run
for a very long time – garbage collector
7. Securefoundation
@kinoma
• Sandbox
• Core language provides no access to network, files, hardware, screen,
audio, etc.
• Scripts can only see and do what the system designer chooses to
provide
• Secure – many classes of security flaws in native code are nonexistent
• Uninitialized memory
• Stack overflow
• Buffer overruns
• Mal-formed data injection
8. First truly major enhancements to the language.
ES6 contains more than 400 individual changes including:
• Classes – familiar tool for inheritance
• Promises – clean, consistent asynchronous operation
• Modules – reusable code libraries
• ArrayBuffer – work with binary data
JavaScript6thEdition–FeaturesforIoT
@kinoma
11. @kinoma
HTTPClient
let HTTPClient = require("HTTPClient");
let http = new HTTPClient(url);
http.onTransferComplete = function(status) {
trace(`Transfer complete : ${status}n`);
};
http.onDataReady = function(buffer) {
trace(String.fromArrayBuffer(buffer));
};
http.start();
12. @kinoma
HTTPServer
let HTTPServer = require("HTTPServer");
let server = new HTTPServer({port: 80});
server.onRequest = function(request) {
trace(`new request: url = ${request.url}n`);
request.addHeader("Connection", "close");
request.response();
};
13. @kinoma
I2CAccelerometer
let accel = new I2C(1, 0x53);
let id = accel.readChar(0x00);
if (0xE5 != id)
throw new Error(`unrecognized id: ${id}`);
accel.write(0x2d, [0x08]);
accel.write(0x38, [(0x01 << 6) | 0x1f]);
let status = accel.readByte(0x39);
let tmp = accel.readByte(0x32);
let x = (tmp << 8) | accel.readByte(0x33);
tmp = accel.readByte(0x34);
let y = (tmp << 8) | accel.readByte(0x35);
tmp = accel.readByte(0x36);
let z = (tmp << 8) | accel.readByte(0x37);
14. @kinoma
AddingES6toyourproduct
• Just a few steps to get the basics working
• Get XS6 from GitHub
• Build it with your product
• Entirely ANSI C – likely builds as-is
• All host OS dependencies in three files xs6Host.c,
xs6Platform.h, and xs6Platform.6
• Update as needed for your host OS / RTOS
17. Readingenvironmentvariables
To allow a script to do this trace(getenv("XS6") + "n");
trace(getenv("XSBUG_HOST") + "n");
xsResult = xsNewHostFunction(xs_getenv, 1);
xsSet(xsGlobal, xsID("getenv"), xsResult);
void xs_getenv(xsMachine* the)
{
xsStringValue result = getenv(xsToString(xsArg(0)));
if (result)
xsResult = xsString(result);
}
Implement xs_getenv in C
Add getenv function to
the virtual machine
18. Avoidthe“100%pure”trap
• It doesn’t make sense to code
everything in script
• Native code is great
• Fast
• Access to native functionality
• Access to hardware functions
• Re-use of proven, reliable code
• Secure
20. @kinoma
Scriptableisscalable
• Your organization can’t implement everything itself
• Interactions with other devices
• Mobile experience
• Interactions with cloud service
• Building partnerships directly is slow, expensive, and limited
• Opening your product to Apps let’s individuals and companies
integrate your product with theirs
• Brings new abilities, new customers, access to new markets
22. @kinoma
ScriptablewillrealizepotentialofIoT
• We can’t organize to connect all these
devices and services together
• This is not a central design / control
problem
• Organic exploration and growth
• Consumers will get the magic they
expect, just as the mobile app
ecosystem snapped into place
23. @kinoma
[InClosing]
• [Review your main ideas in summary form; repetition is important for
comprehension and recall, so repeat your important points. This also indicates
to the audience that your talk is coming to an end and they can start to
formulate their questions.]
• Calls to action:
• [Additional resources to point them to]
• [Recommended reading]
• [Where to dig into Kinoma APIs]
• Final statement before opening up to questions; what you want your audience
to remember after it has forgotten everything else from your talk.