Chapter 1
Elixir and Nerves for IoT

In this book, we’ll be exploring the capabilities of the Elixir programming language paired with the Nerves IoT (Internet of things) platform. To understand how real-world Nerves applications are developed and structured, we’ll be building a network-enabled IoT weather station. The Nerves-powered weather station will be able to collect a wide array of sensor data and will then publish that data to a lightweight Phoenix back-end application which will be backed by a time-series database for efficient data storage and retrieval.

As you’ll see through the various stages of the project, having the power of the Linux kernel at your disposal allows you to iterate quickly and to focus on the important parts of your project—getting your weather station to read sensor data and publish it over the network. Pair that with the power of the concurrent, functional, and pragmatic Elixir programming language and you have a recipe for a powerful yet simple, network-enabled, embedded IoT device.

Frank says:
Frank says:
How Does Nerves Relate to Linux?

It’s important to differentiate the Linux kernel from all the libraries, shells, utilities, and other software found on Linux systems. Nerves uses the Linux kernel for basic operating services and device drivers such as those needed to use WiFi or operate a camera. Nerves configures the Linux kernel so that it starts the BEAM and your applications on boot.

Since OTP provides such a rich set of services out of the box, the usual Linux utilities aren’t needed, and Nerves provides slim and efficient base images by default. In the cases where you can’t avoid a Linux program or service, though, Nerves provides a way to include those.[10] Elixir and the BEAM are always front and center with Nerves, but you’re not locked into only using those technologies.

You’ll start off the weather station sensor hub application by creating a vanilla Nerves project and pushing that firmware to a Raspberry Pi. After you’ve burned an initial firmware to the device, you’ll work on getting it onto the wireless network so that you can communicate with your IoT device, even when it’s not hooked up to your development machine. From there, you’ll learn about organizing your Nerves projects and reading sensor data over I2C. With all of your sensors hooked up and fetching data, you’ll add a component to your Nerves application to publish data over the network.

Once you start developing network-enabled applications, the main features of Elixir and OTP quickly jump to the forefront. Since networked software must often wait for responses from remote servers, concurrency becomes vitally important. In addition, given that complex software is more likely to crash, the ability for OTP to restart itself becomes crucial. Finally, dealing with complexity is easier in a higher-level language with more and better abstractions; Elixir’s functional programming model also presents plenty of opportunities for higher productivity.

Before diving into the weather station project though, it’s important to first discuss what IoT is at a high level and why Nerves is a good fit for the IoT space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.28.9