├── .travis.yml ├── README.md ├── aREST_UI.h ├── examples ├── ESP8266 │ └── ESP8266.ino ├── WiFi_CC3000 │ └── WiFi_CC3000.ino └── WildFire │ └── WildFire.ino ├── library.json └── library.properties /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | before_install: 3 | - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" 4 | - sleep 3 5 | - export DISPLAY=:1.0 6 | - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz 7 | - tar xf arduino-1.6.5-linux64.tar.xz 8 | - sudo mv arduino-1.6.5 /usr/local/share/arduino 9 | - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino 10 | install: 11 | - ln -s $PWD /usr/local/share/arduino/libraries/aREST_UI 12 | - arduino --install-library "Adafruit CC3000 Library" 13 | - arduino --install-library "CC3000 MDNS" 14 | - arduino --install-library "aREST" 15 | script: 16 | - arduino --verify --board arduino:avr:mega:cpu=atmega2560 $PWD/examples/WiFi_CC3000/WiFi_CC3000.ino 17 | notifications: 18 | email: 19 | on_success: change 20 | on_failure: change -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aREST_UI [![Build Status](https://travis-ci.org/marcoschwartz/aREST_UI.svg)](https://travis-ci.org/marcoschwartz/aREST_UI) 2 | 3 | Version 1.1.1 4 | 5 | ## Overview 6 | 7 | aREST UI is an embedded UI for the aREST framework. Currently works with the Arduino Mega & Arduino Due with the CC3000 WiFi chip, the WiFi shield, and the Ethernet shield. It works as well with the Arduino Zero with the WiFi 101 shield, and with the Arduino MKR1000 board. 8 | 9 | It also works with the ESP8266 WiFi chip. 10 | 11 | If you want to know more about aREST, go over to [http://arest.io/](http://arest.io/). 12 | 13 | ## Contents 14 | 15 | - aREST_UI.h: the library file. 16 | - examples: several examples using the aREST UI library 17 | 18 | ## Requirements 19 | 20 | To use the library with Arduino boards you will need the latest version of the Arduino IDE: 21 | 22 | - [Arduino IDE 1.6.5](http://arduino.cc/en/main/software) 23 | 24 | You will also need the aREST library: 25 | 26 | - [aREST](https://github.com/marcoschwartz/aREST) 27 | 28 | ### For WiFi using the CC3000 chip 29 | 30 | - [Adafruit CC3000 Library](https://github.com/adafruit/Adafruit_CC3000_Library) 31 | - [Adafruit MDNS Library](https://github.com/adafruit/CC3000_MDNS) 32 | - MDNS support in your operating system: 33 | - For OS X it is supported through Bonjour, you don't have anything to install. 34 | - For Linux, you need to install [Avahi](http://avahi.org/). 35 | - For Windows, you need to install [Bonjour](http://www.apple.com/support/bonjour/). 36 | 37 | ## Setup 38 | 39 | To install the library, simply clone this repository in the /libraries folder of your Arduino folder. 40 | 41 | ## Quick test (WiFi) 42 | 43 | 1. Connect a LED & resistor to pin number 6 of your Arduino Mega board 44 | 2. Open the WiFi_CC3000 example sketch and modify the WiFi SSID and password 45 | 3. Upload the sketch to the board 46 | 4. Go to a web browser and type `http://arduino.local` 47 | 5. Click on the 'On' button and the LED should turn on 48 | 49 | ## Quick test (WildFire) 50 | 51 | 1. Connect a LED & resistor to pin number 6 of your WildFire board 52 | 2. Open the WildFire example sketch and modify the WiFi SSID and password 53 | 3. Upload the sketch to the board 54 | 4. Go to a web browser and type `http://wildfire.local` 55 | 5. Click on the 'On' button and the LED should turn on 56 | 57 | ## API documentation 58 | 59 | ### Create aREST UI instance 60 | 61 | You can simply create an instance of aREST UI with the following command: 62 | 63 | `aREST_UI ui = aREST_UI();` 64 | 65 | ### Title 66 | 67 | If you don't want to run with the default title, set your own for the UI. 68 | 69 | `ui.title("Your title");` 70 | 71 | ### Button 72 | 73 | Buttons are used to control the state of a digital output pin. The command creates two button inside the interface, one 'On' button, and one 'Off' button. For example, the following command creates a pair of buttons to control pin number 6: 74 | 75 | `ui.button(6)` 76 | 77 | ### Slider 78 | 79 | The slider command creates a slider to control a pin via PWM. For example, it can be used to control the intensity of a LED connected to this pin. The following command creates a pair of buttons to control pin number 6: 80 | 81 | `ui.slider(6)`; 82 | 83 | ### Label 84 | 85 | Labels are used to display the value of variables inside the interface. Before you can use this command, you need to create the corresponding variable first. The following command declares a variable called temperature: 86 | 87 | `ui.variable("temperature",&temperature);` 88 | 89 | After that, you can use the following command to create the corresponding label inside the interface: 90 | 91 | `ui.label("temperature")`; 92 | -------------------------------------------------------------------------------- /aREST_UI.h: -------------------------------------------------------------------------------- 1 | /* 2 | aREST UI for Arduino & the ESP8266 3 | See the README file for more details. 4 | 5 | Written in 2015 by Marco Schwartz under a GPL license. 6 | Version 1.1.1 7 | 8 | Changelog: 9 | 10 | Version 1.1.1: Fixed bug with NodeMCU boards 11 | Version 1.1.0: Added support for functions 12 | Version 1.0.1: Initial release with buttons only 13 | */ 14 | 15 | #ifndef aRest_ui_h 16 | #define aRest_ui_h 17 | 18 | // Include Arduino header 19 | #include "Arduino.h" 20 | 21 | // Using ESP8266 ? 22 | #if defined(ESP8266) 23 | #include "stdlib_noniso.h" 24 | #endif 25 | 26 | class aREST_UI: public aREST { 27 | 28 | public: 29 | 30 | aREST_UI() { 31 | 32 | } 33 | 34 | // Get title 35 | void title(String the_title) { 36 | ui_title = the_title; 37 | } 38 | 39 | // Create button 40 | void button(int pin){ 41 | 42 | // Set pin as output 43 | #if defined(ARDUINO_ESP8266_NODEMCU) || defined(ARDUINO_ESP8266_WEMOS_D1MINI) 44 | pinMode(esp_12_pin_map(pin), OUTPUT); 45 | #else 46 | pinMode(pin, OUTPUT); 47 | #endif 48 | 49 | // Set in button array 50 | buttons[buttons_index] = pin; 51 | buttons_index++; 52 | 53 | } 54 | 55 | // Create function control 56 | void callFunction(char * functionName, char * type){ 57 | 58 | // Set in callFunction array 59 | callFunctionNames[functions_index] = functionName; 60 | callFunctionTypes[functions_index] = type; 61 | functions_index++; 62 | 63 | } 64 | 65 | // Create slider 66 | void slider(int pin) { 67 | 68 | // Set pin as output 69 | #if defined(ARDUINO_ESP8266_NODEMCU) || defined(ARDUINO_ESP8266_WEMOS_D1MINI) 70 | pinMode(esp_12_pin_map(pin), OUTPUT); 71 | #else 72 | pinMode(pin, OUTPUT); 73 | #endif 74 | 75 | // Set in button array 76 | sliders[sliders_index] = pin; 77 | sliders_index++; 78 | 79 | } 80 | 81 | // Create label 82 | void label(char * label_name){ 83 | 84 | int_labels_names[int_labels_index] = label_name; 85 | int_labels_index++; 86 | 87 | } 88 | 89 | // Handle connection 90 | virtual void root_answer() { 91 | 92 | // Answer 93 | addToBuffer("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"); 94 | addToBuffer(""); 95 | addToBuffer(""); 96 | addToBuffer(""); 99 | addToBuffer(""); 100 | addToBuffer(""); 101 | addToBuffer(""); 102 | addToBuffer(""); 103 | addToBuffer("
"); 104 | 105 | // Title 106 | if (ui_title.length() != 0) { 107 | addToBuffer("

"); 108 | addToBuffer(ui_title); 109 | addToBuffer("

"); 110 | } 111 | else { 112 | addToBuffer("

Interface

"); 113 | } 114 | 115 | // Buttons UI 116 | for (int i = 0; i < buttons_index; i++) { 117 | addToBuffer("
"); 118 | addToBuffer("
"); 121 | addToBuffer("
"); 124 | addToBuffer("
"); 125 | } 126 | 127 | // Function calls UI 128 | for (int i = 0; i < functions_index; i++) { 129 | 130 | if (callFunctionTypes[i] == "push") { 131 | 132 | addToBuffer("
"); 133 | addToBuffer("
"); 138 | addToBuffer("
"); 139 | 140 | } 141 | } 142 | 143 | // Sliders UI 144 | for (int i = 0; i < sliders_index; i++) { 145 | addToBuffer("
"); 146 | #if defined(ESP8266) 147 | addToBuffer("
"); 153 | addToBuffer("
"); 154 | } 155 | 156 | // Labels UI 157 | for (int j = 0; j < int_labels_index; j++) { 158 | addToBuffer("
"); 159 | addToBuffer("
"); 160 | addToBuffer(int_labels_names[j]); 161 | addToBuffer(":
"); 162 | addToBuffer("
"); 165 | addToBuffer("
"); 166 | } 167 | 168 | addToBuffer("
"); 169 | 170 | addToBuffer(""); 218 | 219 | addToBuffer("\r\n"); 220 | 221 | } 222 | 223 | private: 224 | 225 | // UI title 226 | String ui_title; 227 | 228 | // Buttons array 229 | int buttons[10]; 230 | int buttons_index; 231 | 232 | // Functions array 233 | char * callFunctionNames[10]; 234 | char * callFunctionTypes[10]; 235 | int functions_index; 236 | 237 | // Buttons array 238 | int sliders[10]; 239 | int sliders_index; 240 | 241 | // Indicators array 242 | uint8_t int_labels_index; 243 | int * int_labels_variables[10]; 244 | char * int_labels_names[10]; 245 | 246 | }; 247 | 248 | #endif 249 | -------------------------------------------------------------------------------- /examples/ESP8266/ESP8266.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This a simple example of the aREST UI Library for the ESP8266. 3 | See the README file for more details. 4 | 5 | Written in 2014-2016 by Marco Schwartz under a GPL license. 6 | */ 7 | 8 | // Import required libraries 9 | #include 10 | #include 11 | #include 12 | 13 | // Create aREST instance 14 | aREST_UI rest = aREST_UI(); 15 | 16 | // WiFi parameters 17 | const char* ssid = "yourSSID"; 18 | const char* password = "yourPassword"; 19 | 20 | // The port to listen for incoming TCP connections 21 | #define LISTEN_PORT 80 22 | 23 | // Create an instance of the server 24 | WiFiServer server(LISTEN_PORT); 25 | 26 | // Variables to be exposed to the API 27 | int temperature; 28 | float humidity; 29 | 30 | int ledControl(String command); 31 | 32 | void setup(void) { 33 | // Start Serial 34 | Serial.begin(115200); 35 | 36 | // Set the title 37 | rest.title("aREST UI Demo"); 38 | 39 | // Create button to control pin 5 40 | rest.button(5); 41 | 42 | // Init variables and expose them to REST API 43 | temperature = 22; 44 | humidity = 39.1; 45 | rest.variable("temperature", &temperature); 46 | rest.variable("humidity", &humidity); 47 | 48 | // Labels 49 | rest.label("temperature"); 50 | rest.label("humidity"); 51 | 52 | // Function to be exposed 53 | rest.function("led", ledControl); 54 | 55 | // Give name and ID to device 56 | rest.set_id("1"); 57 | rest.set_name("esp8266"); 58 | 59 | // Connect to WiFi 60 | WiFi.begin(ssid, password); 61 | while (WiFi.status() != WL_CONNECTED) { 62 | delay(500); 63 | Serial.print("."); 64 | } 65 | Serial.println(""); 66 | Serial.println("WiFi connected"); 67 | 68 | // Start the server 69 | server.begin(); 70 | Serial.println("Server started"); 71 | 72 | // Print the IP address 73 | Serial.println(WiFi.localIP()); 74 | 75 | } 76 | 77 | void loop() { 78 | // Handle REST calls 79 | WiFiClient client = server.available(); 80 | if (!client) { 81 | return; 82 | } 83 | while (!client.available()) { 84 | delay(1); 85 | } 86 | rest.handle(client); 87 | 88 | } 89 | 90 | int ledControl(String command) { 91 | // Print command 92 | Serial.println(command); 93 | 94 | // Get state from command 95 | int state = command.toInt(); 96 | 97 | digitalWrite(5, state); 98 | return 1; 99 | } 100 | -------------------------------------------------------------------------------- /examples/WiFi_CC3000/WiFi_CC3000.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This a simple example of the aREST UI Library for Arduino (Mega/Due) 3 | using the CC3000 WiFi chip. See the README file for more details. 4 | 5 | Written in 2014 by Marco Schwartz under a GPL license. 6 | */ 7 | 8 | // Import required libraries 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // These are the pins for the CC3000 chip if you are using a breakout board 17 | #define ADAFRUIT_CC3000_IRQ 3 18 | #define ADAFRUIT_CC3000_VBAT 5 19 | #define ADAFRUIT_CC3000_CS 10 20 | 21 | // Create CC3000 instance 22 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, 23 | SPI_CLOCK_DIV2); 24 | // Create aREST UI instance 25 | aREST_UI rest = aREST_UI(); 26 | 27 | // Your WiFi SSID and password 28 | #define WLAN_SSID "yourSSID" 29 | #define WLAN_PASS "yourPassword" 30 | #define WLAN_SECURITY WLAN_SEC_WPA2 31 | 32 | // The port to listen for incoming TCP connections 33 | #define LISTEN_PORT 80 34 | 35 | // Server instance 36 | Adafruit_CC3000_Server restServer(LISTEN_PORT); 37 | 38 | // DNS responder instance 39 | MDNSResponder mdns; 40 | 41 | // Variables to be exposed to the API 42 | int temperature; 43 | int humidity; 44 | 45 | void setup(void) 46 | { 47 | // Start Serial 48 | Serial.begin(115200); 49 | 50 | // Create button to control pin 6 51 | rest.button(6); 52 | 53 | // Init variables and expose them to REST API 54 | temperature = 24; 55 | humidity = 40; 56 | rest.variable("temperature",&temperature); 57 | rest.variable("humidity",&humidity); 58 | 59 | // Function to be exposed 60 | rest.function("led",ledControl); 61 | 62 | // Give name and ID to device 63 | rest.set_id("1"); 64 | rest.set_name("cc3000"); 65 | 66 | // Set up CC3000 and get connected to the wireless network. 67 | if (!cc3000.begin()) 68 | { 69 | while(1); 70 | } 71 | if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { 72 | while(1); 73 | } 74 | while (!cc3000.checkDHCP()) 75 | { 76 | delay(100); 77 | } 78 | Serial.println(); 79 | 80 | // Print CC3000 IP address. Enable if mDNS doesn't work 81 | //while (! displayConnectionDetails()) { 82 | // delay(1000); 83 | //} 84 | 85 | // Start multicast DNS responder 86 | if (!mdns.begin("arduino", cc3000)) { 87 | while(1); 88 | } 89 | 90 | // Start server 91 | restServer.begin(); 92 | Serial.println(F("Listening for connections...")); 93 | 94 | // Enable watchdog 95 | wdt_enable(WDTO_4S); 96 | } 97 | 98 | void loop() { 99 | 100 | // Handle any multicast DNS requests 101 | mdns.update(); 102 | 103 | // Handle REST calls 104 | Adafruit_CC3000_ClientRef client = restServer.available(); 105 | rest.handle(client); 106 | wdt_reset(); 107 | 108 | // Check connection, reset if connection is lost 109 | if(!cc3000.checkConnected()){while(1){}} 110 | wdt_reset(); 111 | 112 | } 113 | 114 | // Print connection details of the CC3000 chip 115 | bool displayConnectionDetails(void) 116 | { 117 | uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; 118 | 119 | if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) 120 | { 121 | Serial.println(F("Unable to retrieve the IP Address!\r\n")); 122 | return false; 123 | } 124 | else 125 | { 126 | Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); 127 | Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); 128 | Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); 129 | Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); 130 | Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); 131 | Serial.println(); 132 | return true; 133 | } 134 | } 135 | 136 | // Custom function accessible by the API 137 | int ledControl(String command) { 138 | 139 | // Get state from command 140 | int state = command.toInt(); 141 | 142 | digitalWrite(6,state); 143 | return 1; 144 | } -------------------------------------------------------------------------------- /examples/WildFire/WildFire.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This a simple example of the aREST UI Library for the WildFire v3 board. 3 | See the README file for more details. 4 | 5 | Written in 2014 by Marco Schwartz under a GPL license. 6 | */ 7 | 8 | // Import required libraries 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // These are the pins for the CC3000 chip on the WildFire v3 board 17 | #define ADAFRUIT_CC3000_IRQ 22 18 | #define ADAFRUIT_CC3000_VBAT 23 19 | #define ADAFRUIT_CC3000_CS 21 20 | 21 | // Create CC3000 instance 22 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, 23 | SPI_CLOCK_DIV2); 24 | // Create aREST UI instance 25 | aREST_UI rest = aREST_UI(); 26 | 27 | // Your WiFi SSID and password 28 | #define WLAN_SSID "yourSSID" 29 | #define WLAN_PASS "yourPassword" 30 | #define WLAN_SECURITY WLAN_SEC_WPA2 31 | 32 | // The port to listen for incoming TCP connections 33 | #define LISTEN_PORT 80 34 | 35 | // Server instance 36 | Adafruit_CC3000_Server restServer(LISTEN_PORT); 37 | 38 | // DNS responder instance 39 | MDNSResponder mdns; 40 | 41 | // Variables to be exposed to the API 42 | int temperature; 43 | int humidity; 44 | 45 | void setup(void) 46 | { 47 | // Start Serial 48 | Serial.begin(115200); 49 | 50 | // Create button to control pin 6 51 | rest.button(6); 52 | 53 | // Init variables and expose them to REST API 54 | temperature = 24; 55 | humidity = 40; 56 | rest.variable("temperature",&temperature); 57 | rest.variable("humidity",&humidity); 58 | 59 | // Function to be exposed 60 | rest.function("led",ledControl); 61 | 62 | // Give name and ID to device 63 | rest.set_id("1"); 64 | rest.set_name("wifi"); 65 | 66 | // Set up CC3000 and get connected to the wireless network. 67 | if (!cc3000.begin()) 68 | { 69 | while(1); 70 | } 71 | if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { 72 | while(1); 73 | } 74 | while (!cc3000.checkDHCP()) 75 | { 76 | delay(100); 77 | } 78 | Serial.println(); 79 | 80 | // Print CC3000 IP address. Enable if mDNS doesn't work 81 | //while (! displayConnectionDetails()) { 82 | // delay(1000); 83 | //} 84 | 85 | // Start multicast DNS responder 86 | if (!mdns.begin("arduino", cc3000)) { 87 | while(1); 88 | } 89 | 90 | // Start server 91 | restServer.begin(); 92 | Serial.println(F("Listening for connections...")); 93 | 94 | // Enable watchdog 95 | wdt_enable(WDTO_4S); 96 | } 97 | 98 | void loop() { 99 | 100 | // Handle any multicast DNS requests 101 | mdns.update(); 102 | 103 | // Handle REST calls 104 | Adafruit_CC3000_ClientRef client = restServer.available(); 105 | rest.handle(client); 106 | wdt_reset(); 107 | 108 | // Check connection, reset if connection is lost 109 | if(!cc3000.checkConnected()){while(1){}} 110 | wdt_reset(); 111 | 112 | } 113 | 114 | // Print connection details of the CC3000 chip 115 | bool displayConnectionDetails(void) 116 | { 117 | uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; 118 | 119 | if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) 120 | { 121 | Serial.println(F("Unable to retrieve the IP Address!\r\n")); 122 | return false; 123 | } 124 | else 125 | { 126 | Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); 127 | Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); 128 | Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); 129 | Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); 130 | Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); 131 | Serial.println(); 132 | return true; 133 | } 134 | } 135 | 136 | // Custom function accessible by the API 137 | int ledControl(String command) { 138 | 139 | // Get state from command 140 | int state = command.toInt(); 141 | 142 | digitalWrite(6,state); 143 | return 1; 144 | } -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aREST UI", 3 | "version": "1.1.1", 4 | "keywords": "UI, REST, wifi, ethernet, http, web, server, json, spi", 5 | "description": "A graphical user interface for Arduino based on the aREST API", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/marcoschwartz/aREST_UI.git" 10 | }, 11 | "frameworks": "arduino", 12 | "platforms": 13 | [ 14 | "atmelavr", 15 | "atmelsam", 16 | "espressif", 17 | "teensy" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=aREST UI 2 | version=1.1.1 3 | author=Marco Schwartz 4 | maintainer=Marco Schwartz 5 | sentence=A graphical user interface for Arduino based on the aREST API. 6 | paragraph=A graphical user interface for Arduino based on the aREST API. It is designed to be universal and currently supports REST calls via HTTP, Serial & BLE. See more at: http://arest.io/ 7 | category=Communication 8 | url=https://github.com/marcoschwartz/aREST_UI 9 | architectures=* 10 | --------------------------------------------------------------------------------