Skip to content

How to create a thing

Ulf edited this page Aug 22, 2013 · 17 revisions

What will the thing do for us?

We will create a thing which sends mails if it gets a message from a specific driver from a specific node with a specific body. All other messages, which will come this node will be logged with a warning.

Before we can send the email, we have to initialize the driver, because we have to start an external application. This will be done in the init function.

Note: For sending the emails we will use gen_smtpc which is a simple mail client.

Ok, let's start

  1. Create a new module in the app/horst/src directory.
-module(mail_client_driver).

-export([init/1,handle_msg/3]).

init(Config) ->
	lager:info("mail_client_driver:init('~p')", [Config]),	
	application:start(gen_smtpc).

handle_msg([Node ,Sensor, Id, Time, Body], Config, Module_config) ->
	Config.
  1. Edit the things.config and add the new driver

The things.config is the configuration file where you can enable/disable and configure your things.

{thing, "Mail_Client", 
	[
	{type, actor}, 
	{driver, {mail_client_driver, handle_msg}, [{init, true, [{options, [{use_ssl, true}, {host, "smtp.gmail.com"}, {port, 465}]}]}]},
	{activ, true},
	{timer, 0},
	{database, []},
	{description, "Mail Client for sending notification."}
	]}.

Clone this wiki locally