working on it ...

Filters

Explore Public Snippets

Sort by

Found 486 snippets matching: esp8266

    public by tomsim  3174  39  5  0

    ESP8266 WiFi auto-config

    Use WiFiManager library to auto config SSID
    #include <EEPROM.h>
    #include <ESP8266WiFi.h>
    #include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
    ...
    
    /*====== WiFiManager support stuff ========*/
    void configModeCallback (WiFiManager *myWiFiManager) {
      Serial.println("In WiFi config mode");
      Serial.println(WiFi.softAPIP());
      //if you used auto generated SSID, print it
      Serial.println(myWiFiManager->getConfigPortalSSID());
    }
    
    void setup () 
    {
      Serial.begin(115200);
      delay(200);
    ...
    	/* WiFi setup */
    	WiFiManager wifiManager;
    	wifiManager.setDebugOutput(false);
    //wifiManager.resetSettings(); /* reset settings - for testing */
    	//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
    	wifiManager.setAPCallback(configModeCallback);
    
    	//fetches ssid and pass and tries to connect
    	//if it does not connect it starts an access point with the specified name
    	//here  "AutoConnectAP"
    	//and goes into a blocking loop awaiting configuration
      if (!wifiManager.autoConnect("AutoConnectAP"))
    	{
    		Serial.println("failed to connect and hit timeout");
    		//reset and try again, or maybe put it to deep sleep
    		ESP.reset();
    		delay(1000);
    	}
    
    	/*if you get here you have connected to the WiFi*/
    	Serial.println("");
    	Serial.println("WiFi connected");
    	Serial.println(WiFi.localIP());
    ...
    }
    
    void loop()
    {
    ...
    }
    
    
    
                

    public by shunkino  2997  7  4  0

    ESP8266 memo

    ESP8266 memo: gistfile1.md
    #ESP8266
    ##概要
    SocがのっていてTCPが喋れるエライ子
    
    ファーム次第でサーバーにもなれる
    
    ##ファームウェア更新
    GPIO0をGNDに接続する。再起動後esptool等でファームウェアを焼き変える
    esptoolの使い方はhttp://qiita.com/masato/items/3f386dbc600c1cd840f4
    を参考にしてください。
    
    私達の環境では
    esptool.py -p /dev/tty.wchusbserial1410 -b 115200 write_flash 0x7e000 blank.bin 0x40000 eagle.irom0text.bin 0x3e000 blank.bin 0x00000 eagle.flash.bin
    を実行することでESP-01にファームを書き込めます。
    
    ###<font color="red">!!注意!!</font>
    ファームウェアをesptoolでやくときは、オフセットが大きな方から書き込むこと。そうしないとバグる。
    
    ##Arduinoとの通信
    ArduinoIDEを通して通信するとき Arduino/ESP → TX/TX
    
    Hardware Serialを使ってArduinoから Arduino/ESP → TX/RX
    
    ###ボーレートの変更
    esp\_iot\_sdk\_1.2だとボーレートが115200に最初設定されている
    
    ```bash
     AT+UART_DEF=9600,8,1,0,0
    ```
    
    みたいにすることで設定できる。Flashに書き込まれていまうから最初は
    
    ```bash
     AT+UART_CUR=9600,8,1,0,0
    ```
    
    とかでテストしてみると良い。
    
    コマンドの中身はこんな感じ
    ![UARTコマンド](http://web.sfc.keio.ac.jp/~s13291sk/img/uart_CUR.png)
    
    STATUS:5は再接続中?
    
    

    public by tomsim  1972  1  5  0

    Dallas sensor to thingspeak

    /* Code snippet to use Dallas sensor with ThingSpeak
     * Use lib Arduino manager to install ThingSpeak and DallasTemperature libraries
     */
    
    #include "ThingSpeak.h"
    #include <ESP8266WiFi.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    ...
    /*============ Dallas device setup ==================*/
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    OneWire oneWire(ONE_WIRE_BUS);
    
    // Pass our oneWire reference to Dallas Temperature. 
    DallasTemperature tempSensor(&oneWire);
    
    const int MAX_DEVICES = 3;
    static int nDeviceCount = 0;
    static DeviceAddress tempDev[MAX_DEVICES];
    
    static void findDeviceAddr(void)
    {
    	tempSensor.begin();
    	nDeviceCount = tempSensor.getDeviceCount();
    
    	if (nDeviceCount > MAX_DEVICES)
    		nDeviceCount = MAX_DEVICES;
    
    	for (int i=0; i < nDeviceCount; i++)
    	{
      		uint8_t *devAddr = tempDev[i];
    		if (tempSensor.getAddress(devAddr,i))
    			Serial.println("getAddress ok");
    	}
    }
    static float getTempF( DeviceAddress deviceAddress)
    {
    	float tempF = DallasTemperature::toFahrenheit( tempSensor.getTempC(deviceAddress));
    	return tempF;
    }
    
    ...
    /*============ ThingSpeak setup ==================*/
    // Note:  Each channel has its own number and write API key
    // API key is what get used - wrong channel number doesn't matter
    
    static unsigned long myChannelNumber = YOUR_CHANNEL_NUMBER;	// Customize
    static const char 	*myWriteAPIKey = "Your API KEY";		// Customize
    ...
    
    /*== Global client for ThingSpeak */
    static WiFiClient  client;
    
    static void sampleTemperature()
    {
    	// request to all devices on the bus
    	tempSensor.requestTemperatures(); // Send the command to get temperatures
    
    	for (int i=0; i < nDeviceCount; i++)
    	{
    		float tempF = getTempF(tempDev[i]);
    		Serial.print(String(i+1)+": "+tempF+"F ");
    		ThingSpeak.setField( i+1, tempF);
    	}
    	Serial.println();
    	if (nDeviceCount > 0)
    	{
    		int rc = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    		Serial.println(String("Post rc=")+rc);
    	}
    }
    
    
    void setup () 
    {
      Serial.begin(115200);
    
    	/* Must Do Wifi setup first... */
    ...
    	/* Wifi should be ready after this */
    ...
    	ThingSpeak.begin(client);	// initialize ThingSpeak lib
    ...
    	findDeviceAddr();  	// locate OneWire devices on the bus
    ...
    }
    
    void loop () 
    {
    ...
    			if (itsTimeToSample)
    				sampleTemperature();
    ...
    }            

    public by tomsim  1379  2  6  0

    ESP8266 wifi web server setup

    Lambda style Wifi web server with DHT22 data upload to ThingSpeak
    /* DHTServer - ESP8266 Webserver with a DHT sensor as an input
    
       Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)
    
       Version 1.0  5/3/2014  Version 1.0 Mike Barela for Adafruit Industries
    */
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <DHT.h>
    #include <TimeLib.h>
    #include "ThingSpeak.h"
    
    #define DHTTYPE DHT22
    
    const int DHTPIN = D4;
    
    const char* ssid     = "mySSID";
    const char* password = "myPassword";
    
    ESP8266WebServer server(80);
    
    /*============ ThingSpeak setup ==================*/
    // Note:  Each channel has its own number and write API key
    // API key is what get used - wrong channel number doesn't matter
    
    // Temperature Humidity Channel
    static unsigned long myChannelNumber = 123456;
    static const char 	*myWriteAPIKey = "AB1CDEF6HIJKLMNO";
    static WiFiClient  client;
    
    /*============ End ThingSpeak setup ==============*/
    
    
    // Initialize DHT sensor 
    // NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
    // you need to increase the threshold for cycle counts considered a 1 or 0.
    // You can do this by passing a 3rd parameter for this threshold.  It's a bit
    // of fiddling to find the right value, but in general the faster the CPU the
    // higher the value.  The default for a 16mhz AVR is a value of 6.  For an
    // Arduino Due that runs at 84mhz a value of 30 works.
    // This is for the ESP8266 processor on ESP-01 
    DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
     
    float lastHumdty, lastTempF;  // Values read from sensor
    static int nextSampleMinute = 15;
    static int minuteSampleInterval = 15;
    
    // Generally, you should use "unsigned long" for variables that hold time
    unsigned long previousMillis = 0;        // will store last temp was read
    const long interval = 2000;              // interval at which to read sensor
    
    void getTemperature() {
      // Wait at least 2 seconds seconds between measurements.
      // if the difference between the current time and last time you read
      // the sensor is bigger than the interval you set, read the sensor
      // Works better than delay for things happening elsewhere also
      unsigned long currentMillis = millis();
     
      if(currentMillis - previousMillis >= interval) {
        // save the last time you read the sensor 
        previousMillis = currentMillis;   
    
        // Reading temperature for humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
        lastHumdty = dht.readHumidity();          // Read humidity (percent)
        lastTempF = dht.readTemperature(true);     // Read temperature as Fahrenheit
        // Check if any reads failed and exit early (to try again).
        if (isnan(lastHumdty) || isnan(lastTempF)) {
          Serial.println("Failed to read from DHT sensor!");
          return;
        }
      }
    }
    
    static int uploadData(void)
    {
    	ThingSpeak.setField( 1, lastTempF);
    	ThingSpeak.setField( 2, lastHumdty);
    	int rc = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    //	Serial.println(String("Post rc=")+rc);
    	return rc;
    }
    
     
    const String HTML_TYPE = "text/html";
    
    void handle_null() {
        Serial.println("Handle null");
    	server.send(200,HTML_TYPE,"");
    	delay(100);
    }
    void handleRoot()
    {
    	String wstr = 
    	"<p>Hello from the weather esp8266, read from /temp or /humidity"
    	"<br>set <a href=/set?minuteSampleInterval=5>5 minute</a> sample interval"
    	", <a href=/set?nextSampleMinute=15>sample at 15 </a> minute"
    	"<br>Take <a href=/sample>sample Data</a> and upload to ThingSpeak"
    	"<br><a href=/temp>Get Temperature</a>"
    	"<br><a href=/humidity>Get Humidity</a>";
    	wstr += "<br>Last temperature: " + String(lastTempF)+"F";
    	wstr += " humidity: " + String(lastHumdty)+"%";
    	wstr += "<br>Current minute: " + String(minute(now()));
    	wstr += " next sample time: " + String(nextSampleMinute)+" min.";
    	wstr += " sample interval: " + String(minuteSampleInterval)+" min.";
    	server.send(200,HTML_TYPE, wstr);
    	delay(100);
    }
    void doSample()
    {
    	Serial.println("DoSample");
    	getTemperature();
    	int rc = uploadData();
    	String wstr = "<p>Take sample data:  ";
    	wstr += "<br>Temperature " + String(lastTempF);
    	wstr += "<br>Humidity " + String(lastHumdty);
    	wstr += "<br>Upload thingspeak rc=" + String(rc);
    	server.send(200,HTML_TYPE, wstr);
    }
     
    // Web Server Service Definition structure
    // =======================================
    typedef struct s_WebServiceDef
    {
    	const char *urlName;
    	void (*doit)(void);
    } WebServiceDef;
    
    /* =======================================================================
    	Define web service definition here
    	Each entry has a URL name and a lambda function to service the request
       =======================================================================
    */
    static WebServiceDef wsd[] = {
    	{ "/", handleRoot },
    	{ "/favicon", handle_null },
    	{ "/temp",			// url name
    		[] ()				// lambda function
    		{
    			getTemperature();       // read sensor
    			String wstr="Temperature: "+String((int)lastTempF)+" F";
    			server.send(200, "text/plain", wstr);   // send to someones browser when asked
    		}
    	},
    	{ "/humidity", []()
    		{ 
    			getTemperature();
    			String wstr="Humidity: "+String((int)lastHumdty)+"%";
    			server.send(200, "text/plain", wstr);
    		}
    	},
    	{ "/sample", doSample },
    	{ "/set", []()
    		{
    			String n = String("minuteSampleInterval");
    			if (server.hasArg(n))
    			{
    				int v = server.arg(n).toInt();
    				if (v)
    					minuteSampleInterval = v;
    			}
    			n = String("nextSampleMinute");
    			if (server.hasArg(n))
    			{
    				int v = server.arg(n).toInt();
    				if (v)
    					nextSampleMinute = v;
    			}
    			server.send(200, "text/plain", "ok");
    		}
    	},
     	{0,0}
    };
    
    static void setupServerHandler(void)
    {
    	for (int i; wsd[i].urlName; i++)
    	{
    		server.on( wsd[i].urlName, wsd[i].doit);
    	}
    	server.onNotFound(handleRoot);
    }
    
    static int nextAlarmMin(int sampleInterval)
    {
    	int nextMin = minute(now());
    	nextMin = ((nextMin + sampleInterval) % 60);	// alarm every 5 min
    	return nextMin;
    }
    
    
    
    void setup(void)
    {
    	// You can open the Arduino IDE Serial Monitor window to see what the code is doing
    	Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
    	dht.begin();           // initialize temperature sensor
    
    	// Connect to WiFi network
    	WiFi.begin(ssid, password);
    	Serial.print("\n\r \n\rWorking to connect");
    
    	// Wait for connection
    	while (WiFi.status() != WL_CONNECTED) {
    	delay(500);
    	Serial.print(".");
    	}
    	Serial.println("");
    	Serial.println("DHT Weather Reading Server");
    	Serial.print("Connected to ");
    	Serial.println(ssid);
    	Serial.print("IP address: ");
    	Serial.println(WiFi.localIP());
    
    	ThingSpeak.begin(client);
    
    	setupServerHandler();
    
    	server.begin();
    	Serial.println("HTTP server started");
    }
     
    void loop(void)
    {
    	int currentMinute = minute(now());
    
    	if (currentMinute == nextSampleMinute)
    	{
    		// trigger sample at set interval
    		Serial.println("Regular sample");
    		getTemperature();
    		int rc = uploadData();
    		Serial.println("rc=" + String(rc));
    
    		nextSampleMinute = nextAlarmMin(minuteSampleInterval);
    		delay(1000);
    	}
    
    	server.handleClient();
    } 
    
    

    external by teos0009  596633  12  4  0

    DS18B20 nodeMCU v1.0 with ESP8266 arduino IDE stream data to thingspeak

    DS18B20 nodeMCU v1.0 with ESP8266 arduino IDE stream data to thingspeak: ds18b20-nodemcu-v1.0-esp8266-arduino-ide
    //nodeMCU v1.0 (black) with Arduino IDE
    //stream temperature data DS18B20 with 1wire on ESP8266 ESP12-E (nodeMCU v1.0)
    //shinajaran.blogspot.com
    //nodemcu pinout https://github.com/esp8266/Arduino/issues/584
    #include <ESP8266WiFi.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    //Def
    #define myPeriodic 15 //in sec | Thingspeak pub is 15sec
    #define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board
    //#define mySSR 0  // Solid State Relay on pin 0
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature DS18B20(&oneWire);
    float prevTemp = 0;
    const char* server = "api.thingspeak.com";
    String apiKey ="your API key here";
    const char* MY_SSID = "your SSID here"; 
    const char* MY_PWD = "your SSID password here";
    int sent = 0;
    void setup() {
      Serial.begin(115200);
      connectWifi();
    }
    
    void loop() {
      float temp;
      //char buffer[10];
      DS18B20.requestTemperatures(); 
      temp = DS18B20.getTempCByIndex(0);
      //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
      Serial.print(String(sent)+" Temperature: ");
      Serial.println(temp);
      
      //if (temp != prevTemp)
      //{
      //sendTeperatureTS(temp);
      //prevTemp = temp;
      //}
      
      sendTeperatureTS(temp);
      int count = myPeriodic;
      while(count--)
      delay(1000);
    }
    
    void connectWifi()
    {
      Serial.print("Connecting to "+*MY_SSID);
      WiFi.begin(MY_SSID, MY_PWD);
      while (WiFi.status() != WL_CONNECTED) {
      delay(1000);
      Serial.print(".");
      }
      
      Serial.println("");
      Serial.println("Connected");
      Serial.println("");  
    }//end connect
    
    void sendTeperatureTS(float temp)
    {  
       WiFiClient client;
      
       if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
       Serial.println("WiFi Client connected ");
       
       String postStr = apiKey;
       postStr += "&field1=";
       postStr += String(temp);
       postStr += "\r\n\r\n";
       
       client.print("POST /update HTTP/1.1\n");
       client.print("Host: api.thingspeak.com\n");
       client.print("Connection: close\n");
       client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
       client.print("Content-Type: application/x-www-form-urlencoded\n");
       client.print("Content-Length: ");
       client.print(postStr.length());
       client.print("\n\n");
       client.print(postStr);
       delay(1000);
       
       }//end if
       sent++;
     client.stop();
    }//end send
    
    
    
    

    external by prasertsakd  57923  494  5  -1

    Webserver for Arduino ESP8266

    Webserver for Arduino ESP8266: webserver.ino
    //Leonardo
    Serial_ & dbgTerminal = Serial;
    HardwareSerial & espSerial = Serial1;
    
    ////UNO & M328P
    //#include <SoftwareSerial.h>
    //SoftwareSerial dbgTerminal(10, 11); // RX, TX
    //HardwareSerial & espSerial = Serial;
    
    //
    ////MEGA2560 
    //HardwareSerial & dbgTerminal = Serial;
    //HardwareSerial & espSerial = Serial1;
    
    // set pin numbers:
    const int ledPin =  13;      // the number of the LED pin
    const int ESP8266_CHPD = 4;
    
    // Variables will change:
    int ledState = HIGH;             // ledState used to set the LED
    
    #define BUFFER_SIZE 128
    char buffer[BUFFER_SIZE];
    
    void setup() { 
      pinMode(ledPin, OUTPUT);  
      //pinMode(ESP8266_CHPD, OUTPUT);
          
      dbgTerminal.begin(9600); // Serial monitor
      espSerial.begin(115200); // ESP8266
        
      //while (!dbgTerminal) {
       // ; // wait for serial port to connect. Needed for Leonardo only
      //}
    
      dbgTerminal.println(F("ESP8266 demo."));
    
      //hardReset();
      //delay(2000);
      
      clearSerialBuffer();
      
      //connect to router
      //connectWiFi("YOUR_SSID", "YOUR_PASSWORD");
      
      //test if the module is ready
      //dbgTerminal.print("AT : ");
      //dbgTerminal.println( GetResponse("AT",100) );
        
      //Change to mode 1
      //dbgTerminal.print("AT+CWMODE=1 : ");
      //dbgTerminal.println( GetResponse("AT+CWMODE=1",10) );
            
      //set the multiple connection mode
      dbgTerminal.print(F("AT+CIPMUX=1 : "));
      dbgTerminal.println( GetResponse("AT+CIPMUX=1",10) );
      
      //set the server of port 80 check "no change" or "OK"
      dbgTerminal.print(F("AT+CIPSERVER=1,8888 : "));
      dbgTerminal.println( GetResponse("AT+CIPSERVER=1,8888", 10) );
     
      //set time out
      //dbgTerminal.print("AT+CIPSTO=15 : ");
      //dbgTerminal.println( GetResponse("AT+CIPSTO=15",10) );
      
       //print the ip addr
      dbgTerminal.print(F("ip address : "));
      dbgTerminal.println( GetResponse("AT+CIFSR", 10) );
      delay(200);
    
       
      dbgTerminal.println();
      dbgTerminal.println(F("Start Webserver"));
    
      digitalWrite(ledPin,ledState);  
    }
    
    void loop() {
      int ch_id, packet_len;
      char *pb;  
      espSerial.readBytesUntil('\n', buffer, BUFFER_SIZE);
      
      if(strncmp(buffer, "+IPD,", 5)==0) {
        // request: +IPD,ch,len:data
        sscanf(buffer+5, "%d,%d", &ch_id, &packet_len);
        if (packet_len > 0) {
          // read serial until packet_len character received
          // start from :
          pb = buffer+5;
          while(*pb!=':') pb++;
          pb++;
          if (strncmp(pb, "GET /led", 8) == 0) {
            dbgTerminal.print(millis());
            dbgTerminal.print(" : ");
            dbgTerminal.println(buffer);
            dbgTerminal.print( "get led from ch :" );
            dbgTerminal.println(ch_id);
     
            delay(100);
            clearSerialBuffer();
            
           if (ledState == LOW)
              ledState = HIGH;
           else
              ledState = LOW;
            digitalWrite(ledPin, ledState);
            
            homepage(ch_id);
    
          } else if (strncmp(pb, "GET / ", 6) == 0) {
            dbgTerminal.print(millis());
            dbgTerminal.print(" : ");
            dbgTerminal.println(buffer);
            dbgTerminal.print( "get Status from ch:" );
            dbgTerminal.println(ch_id);
            
            delay(100);
            clearSerialBuffer();
    
            homepage(ch_id);
          }
        }
      }
      clearBuffer();
    }
    
    void homepage(int ch_id) {
      String Header;
    
      Header =  "HTTP/1.1 200 OK\r\n";
      Header += "Content-Type: text/html\r\n";
      Header += "Connection: close\r\n";  
      //Header += "Refresh: 5\r\n";
      
      String Content;
      Content = "D";
      Content += String(ledState);
      
      Header += "Content-Length: ";
      Header += (int)(Content.length());
      Header += "\r\n\r\n";
      
      
      espSerial.print("AT+CIPSEND=");
      espSerial.print(ch_id);
      espSerial.print(",");
      espSerial.println(Header.length()+Content.length());
      delay(10);
      
      // for debug buffer serial error
      //while (espSerial.available() >0 )  {
      //  char c = espSerial.read();
      //  dbgTerminal.write(c);
      //  if (c == '>') {
      //      espSerial.print(Header);
      //      espSerial.print(Content);
      //  }
      //}
      
      if (espSerial.find(">")) {
          espSerial.print(Header);
          espSerial.print(Content);
          delay(10);
       }
     
    //  Serial1.print("AT+CIPCLOSE=");
    //  Serial1.println(ch_id);
    
    
    }
    
    
    
    // Get the data from the WiFi module and send it to the debug serial port
    String GetResponse(String AT_Command, int wait){
      String tmpData;
      
      espSerial.println(AT_Command);
      delay(10);
      while (espSerial.available() >0 )  {
        char c = espSerial.read();
        tmpData += c;
        
        if ( tmpData.indexOf(AT_Command) > -1 )         
          tmpData = "";
        else
          tmpData.trim();       
              
       }
       return tmpData;
    }
    
    boolean hardReset() {
      String tmpData;
      
      digitalWrite(ESP8266_CHPD,LOW);
      delay(100);
      digitalWrite(ESP8266_CHPD,HIGH);
      delay(1000);
        
      while ( espSerial.available() > 0 ) {
        char c = espSerial.read();
        tmpData +=c;
        espSerial.write(c);
        if ( tmpData.indexOf("Ready") > -1 ) {
          //Serial.println("Ready");
            clearBuffer();
            return 1;
        } 
      }
    }
    
    void clearSerialBuffer(void) {
           while ( espSerial.available() > 0 ) {
             espSerial.read();
           }
    }
    
    void clearBuffer(void) {
           for (int i =0;i<BUFFER_SIZE;i++ ) {
             buffer[i]=0;
           }
    }
             
    boolean connectWiFi(String NetworkSSID,String NetworkPASS) {
      String cmd = "AT+CWJAP=\"";
      cmd += NetworkSSID;
      cmd += "\",\"";
      cmd += NetworkPASS;
      cmd += "\"";
      
      dbgTerminal.println(cmd); 
      dbgTerminal.println(GetResponse(cmd,10));
    }
    
    

    external by George White  343  1  3  0

    Notes on using the ESP8266 with the Arduino IDE

    Notes on using the ESP8266 with the Arduino IDE: esp8266_arduino.md
    # Using ESP8266 with Arduino IDE
    
    ## Methods for getting ESP82666 support into the Arduion IDE
    
    * Adding support to Arduino IDE via a [drop-in extension](https://github.com/sandeepmistry/esp8266-Arduino) (Arduino 1.6.1, 1.6.3)
    * Adding support via [Adafruit's](http://adafruit.com) [support for additional boards](https://learn.adafruit.com/add-boards-arduino-v164/) (Arduino IDE 1.6.4+)
    * [Custom version of the Arduino IDE](https://github.com/esp8266/Arduino)
    
    ## Hooking up the ESP-01 module
    
    The [ESP-01](https://www.adafruit.com/product/2282) is probably the most common ESP8266 module available right now. No one is really happy with the  breadboard-unfriendlypin setup, the lack of an integrated voltage regulator, the number of pins broken out (two GPIO pins only?!?), or the fact that the board isn't FCC/CE certified. But it's cheap, was first to market and what folks could get their hands on. Fortunately, new boards are coming on the market, such as the [Adafruit HUZZAH ESP8266 breakout](https://www.adafruit.com/product/2471).
    
    There are a bunch of resources for how to hook this board up for both bootloading and use, but they're a little confusing.
    
    ## Some useful resources
    
    [Alasdair Allan](http://makezine.com/author/alasdair-allan) has written a nice walkthrough of getting things up and running with an ESP-01. I found that this article really helped me get over some issues I was waving getting the Arudino environment to work with the ESP-01.
    
    * http://makezine.com/2015/04/01/installing-building-arduino-sketch-5-microcontroller/
    
    Adafruit has several tutorials for the ESP8266, using either the ESP-01 or their own HUZZAH ESP8266 breakout board.
    
    * https://learn.adafruit.com/esp8266-temperature-slash-humidity-webserver/
    * https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout
    
    

    external by dnc40085  1725  3  3  0

    assembler code for esp8266 function wifi_set_event_handler from ESP8266_NONOS_SDK_V1.5.1_16_01_08.zip

    assembler code for esp8266 function wifi_set_event_handler from ESP8266_NONOS_SDK_V1.5.1_16_01_08.zip: wifi_set_event_handler_cb.asm
    40213fd0 <wifi_set_event_handler_cb>:
    40213fd0:	fffd31        	l32r	a3, 40213fc4 <wifi_set_status_led_output_level+0x48>
    40213fd3:	f0c112        	addi	a1, a1, -16
    40213fd6:	0129      	s32i.n	a2, a1, 0
    40213fd8:	1109      	s32i.n	a0, a1, 4
    40213fda:	000332        	l8ui	a3, a3, 0
    40213fdd:	fffa01        	l32r	a0, 40213fc8 <wifi_set_status_led_output_level+0x4c>
    40213fe0:	23ec      	bnez.n	a3, 40214006 <wifi_set_event_handler_cb+0x36>
    40213fe2:	fffa21        	l32r	a2, 40213fcc <wifi_set_status_led_output_level+0x50>
    40213fe5:	531c      	movi.n	a3, 21
    40213fe7:	052c      	movi.n	a5, 32
    40213fe9:	004d      	mov.n	a4, a0
    40213feb:	60c442        	addi	a4, a4, 96
    40213fee:	f2d401        	l32r	a0, 40210b40 <ets_timer_handler_isr+0xcc>
    40213ff1:	0000c0        	callx0	a0
    40213ff4:	fff461        	l32r	a6, 40213fc4 <wifi_set_status_led_output_level+0x48>
    40213ff7:	150c      	movi.n	a5, 1
    40213ff9:	fff381        	l32r	a8, 40213fc8 <wifi_set_status_led_output_level+0x4c>
    40213ffc:	0178      	l32i.n	a7, a1, 0
    40213ffe:	7879      	s32i.n	a7, a8, 28
    40214000:	004652        	s8i	a5, a6, 0
    40214003:	000046        	j	40214008 <wifi_set_event_handler_cb+0x38>
    40214006:	7029      	s32i.n	a2, a0, 28
    40214008:	1108      	l32i.n	a0, a1, 4
    4021400a:	10c112        	addi	a1, a1, 16
    4021400d:	f00d      	ret.n
    4021400f:	d7c000        	excw
    40214012:	e04024        	excw
    40214015:	4024d7        	blt	a4, a13, 40214059 <system_uart_swap+0x5>
    
    
    

    external by iddar  624  8  3  0

    Enlaces relacionados con el modulo ESP8266 (Related links with ESP8266)

    Enlaces relacionados con el modulo ESP8266 (Related links with ESP8266): ESP8266-links.md
    [Espressif Systems](http://espressif.com/en/products/esp8266/)
    
    [DataSheet](https://anibit.com/sites/default/files/product_files/ESP8266_Specifications_English.pdf)
    
    [Wi07c Buena documentación](http://www.electrodragon.com/w/Wi07c)
    
    [Official Community](http://www.esp8266.com/)
    
    [ESP8266 Wiki](http://www.esp8266.com/wiki/doku.php)
    
    [GitHub-Wiki ESP8266](https://github.com/esp8266/esp8266-wiki/wiki)
    
    [Community Repo](https://github.com/esp8266)
    
    [Open SDK](https://github.com/pfalcon/esp-open-sdk)
    
    [Oficial Forum](http://bbs.espressif.com/)
    
    [NodeMcu - A lua based firmware for wifi-soc esp8266](https://github.com/nodemcu/nodemcu-firmware)
    
    [Frankenstein is a quick and dirty firmware](https://github.com/nekromant/esp8266-frankenstein)
    
    [FCC Authorization](https://apps.fcc.gov/tcb/GetTcb731Report.do?applicationId=794971&fcc_id=2AC7Z-ESP8266EX)
    
    [NodeLua](http://nodelua.org/)
    
    [ESP8266 + DHT22](http://harizanov.com/2014/11/esp8266-powered-web-server-led-control-dht22-temperaturehumidity-sensor-reading/)
    
    [SDK based on FreeRTOS](https://github.com/andrewclink/esp_iot_rtos_sdk)
    
    [esptool.py](https://github.com/tommie/esptool)
    
    [esptool-ck](https://github.com/tommie/esptool-ck)
    
    ## News
    [New Chip](http://hackaday.com/2014/08/26/new-chip-alert-the-esp8266-wifi-module-its-5/)
    
    [FCC Authorization](http://hackaday.com/2014/12/17/esp-gets-fcc-and-ce/)
    
    ## Tutorials / Instructables
    [ESP8266 and PL2303HX-gpio](http://ncrmnt.org/wp/2014/11/04/esp8266-and-pl2303hx-gpio-adventures/)
    
    [Use module](http://www.instructables.com/id/Using-the-ESP8266-module/)
    
    [Getting ESP8266 with Arduino](http://nerdclub-uk.blogspot.mx/2014/10/getting-esp8266-wifi-module-to-work.html)
    
    [ESP8266 Busy S (updated)](https://scargill.wordpress.com/2014/10/17/esp8266-busy-s/)
    
    [ESP8266 Now Working/Updated](https://scargill.wordpress.com/2014/10/05/esp8266-working/)
    
    [Hackaday.io projects](http://hackaday.io/list/3553-esp8266-projects)
    
    [Espruino example](http://www.espruino.com/ESP8266)
    
    [HowTo - ESP826 LUA firmware](https://importhack.wordpress.com/2014/11/22/how-to-use-ep8266-esp-01-as-a-sensor-web-client/)
    
    [First Impressio](http://rayshobby.net/?p=9734)
    
    

    external by sticilface  772  4  3  0

    Send buffered packets from print to either ESP8266WebServer or WiFiClient on ESP8266

    Send buffered packets from print to either ESP8266WebServer or WiFiClient on ESP8266: Bufferedpackets.h
    /*
    	Send out buffered packets to ESP8266WebServer or WiFiClient on ESP8266 on Arduino IDE. 
    See https://github.com/bblanchon/ArduinoJson/issues/166
    
    exmaple of use with arudino json
        size_t jsonlength = root.measureLength();
        HTTP.setContentLength(jsonlength);
        HTTP.send(200, "text/json" );
        BufferedPrint<HTTP_DOWNLOAD_UNIT_SIZE> proxy(HTTP);
        root.printTo(proxy);
        proxy.flush();
    OR
        size_t jsonlength = root.measureLength();
        HTTP.setContentLength(jsonlength);
        HTTP.send(200, "text/json" );
        WiFiClient client = HTTP.client(); 
        BufferedPrint<HTTP_DOWNLOAD_UNIT_SIZE> proxy(client);
        root.printTo(proxy);
        proxy.flush();
    */
    template<size_t CAPACITY>
    class BufferedPrint : public Print
    {
    public:
    	BufferedPrint(ESP8266WebServer & HTTP) : _size(0)
    	{
    		_client = HTTP.client();
    	}
    	
    	BufferedPrint(WiFiClient & client) : _client(client), _size(0)
    	{
    	}
    
    	~BufferedPrint() {
    		_client.stop(); 
    	}
    
    	virtual size_t write(uint8_t c)
    	{
    		_buffer[_size++] = c;
    
    		if (_size + 1 == CAPACITY)
    		{
    			flush();
    		}
    	}
    
    	void flush()
    	{
    		 _client.write( (const char *)_buffer, _size);
    		 _size = 0;
    	}
    
    private:
    	WiFiClient _client;
    	size_t _size;
    	char _buffer[CAPACITY];
    };
    
    
    
    • Public Snippets
    • Channels Snippets