Sunday, November 15, 2015

Standalone ESP8266/ESP-12: web control on-board LED

It's a example of Standalone ESP8266/ESP-12 web server, to control on-board LED.


Prepare:
Install ESP8266 Board to Arduino IDE
Program standalone ESP8266/ESP-12 WiFi module with Arduino IDE
Simple Web Server example of standalone ESP8266/ESP-12 WiFi Module

This example modify from the last example Simple Web Server example of standalone ESP8266/ESP-12 WiFi Module, to control on-board LED. You need a Terminal program (ex. Arduino IDE's Serial Monitor) to display the ESP8266's IP.

ESP12-WebControlLed.ino
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
 
const char* ssid = "testAP";
const char* password = "12345678";
MDNSResponder mdns;

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
  server.send(200, "text/plain", 
    "hello from esp8266!) \n/on: to tuen LED ON \n/off: to tuen LED OFF \n");

}

void handleNotFound(){
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}
 
void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  
  server.on("/", handleRoot);

  server.on("/on", [](){
    digitalWrite(BUILTIN_LED, LOW);
    server.send(200, "text/plain", "LED ON");
  });
  
  server.on("/off", [](){
    digitalWrite(BUILTIN_LED, HIGH);
    server.send(200, "text/plain", "LED OFF");
  });

  server.onNotFound(handleNotFound);
  
  server.begin();
  Serial.println("HTTP server started");

  //delay a moment, 
  //for terminal to receive inf, such as IP address
  delay(1000);
  Serial.end();
  pinMode(BUILTIN_LED, OUTPUT);
}
 
void loop(void){
  server.handleClient();
} 


Android App to test:
- Android App to control Standalone ESP8266/ESP-12 on-board LED, using HttpClient, with Android example code.


Android App to control Standalone ESP8266/ESP-12 on-board LED, using HttpURLConnection, with Android example code and APK for test without coding.


Wednesday, November 11, 2015

Simple Web Server example of standalone ESP8266/ESP-12 WiFi Module


Former posts show how to "Install ESP8266 Board to Arduino IDE" and "Program standalone ESP8266/ESP-12 WiFi module with Arduino IDE". ESP8266 Board Library come with a HelloServer example, it's easy to implement a simple web server.


Load ESP8266WebServer example of HelloServer, change ssid and password for your WiFi network, Save another file.



Next:
Standalone ESP8266/ESP-12: web control on-board LED

Sunday, November 8, 2015

What Does Open Source Mean to You? From OSCON 2015

From OSCON 2015 in Amsterdam, a number of voices from the open source community try to define its meaning and value.


Watch more from OSCON Amsterdam 2015: https://goo.gl/VeF8tq
Visit the OSCON website: http://oscon.com
Don't miss an upload! Subscribe! http://goo.gl/szEauh
Stay Connected to O'Reilly Media by Email - http://goo.gl/YZSWbO

Friday, November 6, 2015

Program standalone ESP8266/ESP-12 WiFi module with Arduino IDE


This post show how to program and run standalone ESP8266/ESP-12 WiFi module. To program ESP8266 board with Arduino, we have to "Install ESP8266 Board to Arduino IDE".

Connect USB-to-Serial adapter to ESP8266/ESP-12 board, FT232RL module is used in this example.

Minimal Hardware Setup for Bootloading only

ESPxx Hardware
PINResistorSerial Adapter
VCCVCC (3.3V)
GNDGND
TX or GPIO2RX
RXTX
GPIO0GND
ResetRTS*
GPIO15PullDown
CH_PDPullUp
  • Note
    • if no RTS is used a manual power toggle is needed

Minimal Hardware Setup for Running only

ESPxx Hardware
PINResistorPower supply
VCCVCC (3.3V)
GNDGND
GPIO0PullUp
GPIO15PullDown
CH_PDPullUp
reference: https://github.com/esp8266/Arduino/blob/master/doc/boards.md


Load Examples > esp8266 > Blink

To program ESP8266 board, press the button to connect GPIO0 to GND. Because there are no RTS in my FT232RL module, so I have to power OFF and ON to reset ESP8266 before programming.

Once programmed, power off the board, press the button to release GPIO0, then power on again to run in standalone.



Updated@2015-11-15:
My setup have no RTS, so I add a button to reset the ESP-12 manually.


List of Standalone ESP8266 board posts:
- Install ESP8266 Board to Arduino IDE
- Program standalone ESP8266/ESP-12 WiFi module with Arduino IDE (this post)
- Simple Web Server example of standalone ESP8266/ESP-12 WiFi Module
Standalone ESP8266/ESP-12: web control on-board LED

Install ESP8266 Board to Arduino IDE


With ESP8266 Board installed on Arduino IDE, we can program ESP8266 modules as a standalone microcontroller/board, as simple as program Arduino.


Installing with Boards Manager

Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. The ESP8266 packages available for Windows, Mac OS, and Linux (32 and 64 bit).
  • Install Arduino 1.6.5 from the Arduino website.
  • Start Arduino and open Preferences window.
  • Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  • Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).

With ESP8266 Board Library installed, you can build more project on Standalone ESP8266, without controller such as Arduino.


Program standalone ESP8266/ESP-12 WiFi module with Arduino IDE
Simple Web Server example of standalone ESP8266/ESP-12 WiFi Module