How to Control Arduino With a Mail

by lzu in Circuits > Arduino

1633 Views, 29 Favorites, 0 Comments

How to Control Arduino With a Mail

ArdulinkMail.png

There are a lot of solutions to control an Arduino board: web solutions, desktop application solutions, hardware solutions. But what about mail? Yes, you can find something on the web but they need for ethernet shields and often is Arduino that sends mail. I'd like to control Arduino with a mail. So I've written a command line application that uses my Ardulink java open source library. It's called Ardulink Mail and it's able to receive message, analyze them and control the Arduino boards connected to a PC.

DISCLAIMER

Even if Ardulink Mail has some security controls that application could expose your system on risks for malicious attacks. So please use it very carefully. The author and Ardulink organization is not responsible for damages (http://www.apache.org/licenses/LICENSE-2.0).

Download the Software

NewLogo1.png

You need for:

Hardware

  1. a regular PC or a SoC (system on chip) like Raspberry PI you can use the operating system you like (Microsoft Windows, Linux or even an Apple)
  2. one or more Arduino/Genuino boards (or compatible boards)
  3. an USB cable

Software

  1. a Java runtime (1.6+)
  2. the Ardulink distribution (into this distribution you can find Ardulink Mail that is the command line application we are searching for)
  3. RXTX Library (for Windows systems it is already in the Ardulink distribution, for Linux system it's possible install it with an apt get command see this more detailed guide for Raspberry)

Mail Account

  1. Of course to receive mail, Ardulink Mail has to open an inbox mail. Actually Ardulink Mail is tested and works very fine with a Google mail account.

Configuring the Software

Ardulink Mail has two configuration files. They are located into conf folder in the Ardulink distribution.

ardulinkmail-conf.properties

In this file you can configure:

  • The mail account you like to use with Ardulink Mail. Actually it is tested and works fine with a Google Mail account.
  • Two security parameters. You can enable/disable a list of mail addresses from which Ardulink Mail can receive messages. You can also enable/disable a mail content password. If enabled Ardulink Mail checks if this password is contained in the mail or not.

ArdulinkMailConfiguration.xml
This XML file contains info about links, connections and mail handlers that Ardulink Mail has to manage. So you can define a connection with an XML fragment like this:

<aconnections>
<className>org.zu.ardulink.connection.serial.SerialConnection</className>
<constructorParameters>
<type>java.lang.String</type>
<value>SERIAL CONNECTION ID</value>
</constructorParameters>
<constructorParameters>
<type>int</type>
<value>255</value>
</constructorParameters>
<name>SERIAL CONNECTION</name>
</aconnections>

See Ardulink API to understand connections: http://www.ardulink.org/javadoc/ardulink-core/index.html Then you can define a link with an XML fragment like this:

<alinks>
<connectParameters>
<type>java.lang.String</type>
<value>COM5</value>
</connectParameters>
<defaultLink>true</defaultLink>
<name>LINK 1</name>
<waitSecondsAfterConnection>10</waitSecondsAfterConnection>
</alinks>

or like this:

<alinks>
<aConnectionName>SERIAL CONNECTION</aConnectionName>
<connectParameters>
<type>java.lang.String</type>
<value>COM6</value>
</connectParameters>
<connectParameters>
<type>int</type>
<value>115200</value>
</connectParameters>
<defaultLink>false</defaultLink>
<name>LINK 2</name>
<protocolName>ArdulinkProtocol</protocolName>
<waitSecondsAfterConnection>10</waitSecondsAfterConnection>
</alinks>

See Ardulink API to understand links: http://www.ardulink.org/javadoc/ardulink-core/index.html

Now you can define commands that execute code when a mail is incoming. A command used in the video above is this:

<acommands>
<aLinkNames>LINK 1</aLinkNames>
<className>org.zu.ardulink.mail.server.contentmanagement.SimpleContentManager</className>
<mailContentHooks>accendi</mailContentHooks>
<mailContentHooks>turn on</mailContentHooks>
<name>ACCENDI LED 26 e 27</name>
<values>alp://ppsw/26/1</values>
<values>alp://ppsw/27/1</values>
</acommands>

In the className tag you can choose a content manager implementation.
Actually Ardulink Mail has two content manager implementation. The first in the example above search for a mail content hook (defined in the mailContentHooks tag) into the incoming mail body. If a content hook is find (the string “turn on” or its Italian translation “accendi”) then all values are sent to all the link names (in the example just one: LINK 1). So in the example regardless the link’s protocol two strings are sent. These strings are two ALProtocol messages and then PIN 26 and PIN 27 are set to HIGH.

There is another content manager implementation. Unfortunately this implementation has a bug in the v0.6.0. The fix will be general available in the next release. See here for more detail.

NOTE:
Since logic on when a content manager has to do something and logic on what a content manager has to do is delegated to the content manager, you can implement a content manager that do what you want when a right incoming mail is read by Ardulink Mail. Even if you content manager don’t use a link to send messages to an Arduino. So Ardulink Mail can be used as a generic mail processor.

Start the Software

How Ardulink Mail works

From Ardulink lib folder you have just to type this command:

java -jar ardulink-mail-0.6.0.jar

See the video to see Ardulink Mail in action.

Enjoy.

You can find more info about Ardulink on Ardulink official site or on Github.

NOTE:

Since v0.6.0 Gutenberg, Ardulink has two main features:

  1. Ardulink Mail explained in this instructables
  2. Ardulink MQTT that is a command line application able to connect Arduino boards with an MQTT broker