The API - ArduinoEthernetController/API_1.2 GitHub Wiki
With the Arduino Ethernet Controller the user is able to control a microcontroler over a simple HTTP request. It’s possible to send commands over Notification-Center and the app itself.
To make programming as easy as possible, we decided to write a Library for the Arduino Programming environment. The library has to be copied in your Arduino library directory.
A example sketch is located in the AEC library folder under examples. It contains all methods and shows you how they are used. The sketch is well commented and easy to understand.
setup methods
- start( int ip[] , byte mac[], String deviceName)
- createButton(String name, char command )
- createPinButton(String name, int pin)
- createSlider(String name, char command, int startValue, int endValue)
- createPinSlider(String name, int pin)
- createFeedback(char flag)
- createColor(String name, char command)
loop methods
- searchForClient()
- searchForAction(char command, int value)
- searchForColor(char command, int valueR, int value G, int valueB, int alpha)
- receiveTrigger()
- setHTMLrequest(String website)
- Feedback(char flag, String message)
start( int ip[] , byte mac[], String deviceName)
- Initialize the AEC library with IP- , MAC- address and device name. If the IP-address or name was changed by the app, the MCU will load the changed values after restart from the EEPROM. So if you want to start with your default values, you have to set the EEPROM at address 4 to 0 by an extra sketch.
EEPROM.write(4, 0);
To get the library initialized, you have to include the Ethernet.h, SPI.h and EEPROM.h library.
createButton(String name, char command )
createSlider(String name, char command, int startValue, int endValue)
createFeedback(char flag)
createColor(String name, char command)
- This Methods have to be called only once for each command. They only work with an Atmega2560 due to the bigger memory of the MCU. Calling this methods set up the commands, which can be imported in the app. You don’t need to add virtual comands manually any more.
createPinButton(String name, int pin)
createPinSlider(String name, int pin)
- These methods are similar to the
createButton()andcreateSlider()methods. The difference is that they refer to a Pin and are not virtual.
searchForClient()
- It’s a neccessary loop method which looks for new clients and catches the incoming HTML request. This method is required for the
searchForAction()andsearchForColor()methods.
searchForAction(char command, int value)
- Filter the HTML request. This is a void method which changes pre-initialized variables!
Look at the example sketch for more details.
searchForColor(char comand, int valueR, int value G, int valueB, int alpha)
- It’s similar to
searchForAction()
receiveTrigger()
- This boolean method returns true if a new command is received.
Be aware that a refresh of the HTML website could cause a trigger.
setHTMLrequest(String website)
- If you set a response webpage via this method, the default webpage will be disabled.
Feedback(char flag, String message)
- Send a feedback back to the app with this method. If the flag of this method matches with a feedback-flag in your app, the message will be displayed in there.
The difference is that Virtual commands can be generated by your own with individual command characters and values e.g Button ON = z1 OFF = z0, they can be caught in the arduino code by a method. You can handle them in whatever wich way you like.
The pin-commands instead, are already evaluated in the AEC-library and passed through to a digital or analog output pin.
Pin-Buttons ON and OFF correspond to pin-voltage HIGH/LOW respectively 1 / 0 (digital)
Pin-Sliders can have values between 0 and 255 (analog)
To implement pin-commands, you just need to initialize the AEC-library.
After a change of the address is made, a reboot of the Arduino is necessary to accept the changes.
If the IP-address was changed to a unreachable IP-range by mistake, a 0 has to be wirtten in the EEPROM memory address 4.
We suggest to create a extra sketch like this:
#include <EEPROM.h>
void setup(){
EEPROM.write(4,0);
}
void loop(){}