Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Chris Carter
#24278 As an update, for now I've also got the mDNS function working.

This will let me just go to thelightclock.local/ and find the ESP8266 that way. Seems to be natively built into apple stuff, require itunes or bonjour install for windows, there is no android support that I can find unfortunately :(

I may become everything I ever hated and only support iOS, not android.

Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>

MDNSResponder mdns;

snip
    if (!mdns.begin("thelightclock")) {
      Serial.println("Error setting up MDNS responder!");
      while (1) {
        delay(1000);
      }
    } else {
      Serial.println("mDNS responder started");
User avatar
By bkrajendra
#25500 SSDP is better solution. Even there are Mobile Apps or Cordova libraries available for detecting all SSDP services on network.

Code Example from Arduino ESP8266 repo.

Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266SSDP.h>

const char* ssid = "************";
const char* password = "***********";

ESP8266WebServer HTTP(80);

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("Starting WiFi...");

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if(WiFi.waitForConnectResult() == WL_CONNECTED){

    Serial.printf("Starting HTTP...\n");
    HTTP.on("/index.html", HTTP_GET, [](){
      HTTP.send(200, "text/plain", "Hello World!");
    });
    HTTP.on("/description.xml", HTTP_GET, [](){
      SSDP.schema(HTTP.client());
    });
    HTTP.begin();

    Serial.printf("Starting SSDP...\n");
    SSDP.setSchemaURL("description.xml");
    SSDP.setHTTPPort(80);
    SSDP.setName("ioCare IoT Switch");
    SSDP.setSerialNumber("654654");//string Can be replaced with ESP.getChipID();
    SSDP.setURL("index.html");
    SSDP.setModelName("ioCare Switch");
    SSDP.setModelNumber("IOC8266SW8");
    SSDP.setModelURL("http://www.iocare.in/iocswb");
    SSDP.setManufacturer("ioCare, Pune, India");
    SSDP.setManufacturerURL("http://www.iocare.in");
    SSDP.begin();

    Serial.printf("Ready!\n");
  } else {
    Serial.printf("WiFi Failed\n");
    while(1) delay(100);
  }
}

void loop() {
  HTTP.handleClient();
  delay(1);
}


A Cordova Plugin for implementing Mobile app to scan all available ESP in the network.
https://github.com/scottdermott/cordova ... -discovery