Introduction: How to Control Arduino With a Mail

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).

Step 1: Download the Software

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.

Step 2: 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.

Step 3: Start the Software

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

Comments

author
DIY Hacks and How Tos (author)2015-10-31

Great Arduino controller.

author

Thanks, Ardulink Mail is just an application of the Ardulink distribution.

Ardulink is a complete, open source, java solution for the control
and coordination of Arduino boards. It defines a communication protocol
and a communication interface allowing several protocol implementations.

It is composed by the following java libraries/applications:

  • Ardulink Core the main java library
  • Ardulink SWING that is a ready java SWING components collection able to communicate with Arduino.
  • Ardulink Console that is a SWING application that can be used to control an Arduino board without programmer skill.
  • Ardulink Network Proxy Server that is a command line application. It is a network client/server technology for remote control purpose.
  • Ardulink Mail that is a command line application. With this application an user can control several Arduino boards sending just e-mails.
  • Ardulink MQTT that is a command line application able to connect Arduino boards with an MQTT broker.

About This Instructable

849views

27favorites

License:

Bio: I was born in Rome in 1972. I have a degree in computer science but I am continuing to study it. My interest in this ... More »
More by lzu:How to use MQTT in Arduino without an Ethernet ShieldHow to control arduino with a mailHow to save/load java classes to a stream (or file) in XML format
Add instructable to: