Intro: 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.
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:
- 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)
- one or more Arduino/Genuino boards (or compatible boards)
- an USB cable
- a Java runtime (1.6+)
- the Ardulink distribution (into this distribution you can find Ardulink Mail that is the command line application we are searching for)
- 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)
- 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.
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.
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:
<value>SERIAL CONNECTION ID</value>
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:
or like this:
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:
<name>ACCENDI LED 26 e 27</name>
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.
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.
Since v0.6.0 Gutenberg, Ardulink has two main features:
- Ardulink Mail explained in this instructables
- Ardulink MQTT that is a command line application able to connect Arduino boards with an MQTT broker