-->
Page 1 of 1

Here is a small sketch to make the ESP8266 Easier to use.

PostPosted: Thu Feb 04, 2016 9:16 pm
by johnbravo
I know this is not perfect, I just started working on it. I dont know if anyone has any interest in it, but i figured i would let everyone take a look. tell me what you think. And please keep in mind that this is a work in progress.

Just upload the sketch to the esp8266 and connect over serial from arduino to esp8266 and send the commands.

UPDATE New Commands Added!



Commands
This sets your ssid of the access point you want to connect to
SSID|linksys

This is the password to the access point
PASS|123456

The host you want to connect to
HOST|www.adafruit.com

The url for the web page you want to see
URL|/testwifi/index.html

Sends data to remote host
SEND|Somedata

Sets the port of the remote host
PORT|80

Request web page
GET|

connect to the access point
JOIN|





Code: Select all    #include <ESP8266WiFi.h>
   WiFiClient client;
   char ssid[56];
   char password[56];
    char host[56];
   char url[500];
   uint16 port;

void setup() {
   Serial.begin(115200);
   delay(100);
}
 
void Joinnetwork() {
   Serial.println();
   Serial.println();
   Serial.print("Connecting to ");
   Serial.println(ssid);
   
   WiFi.begin(ssid, password);
   
   while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
   }

   Serial.println("");
   Serial.println("WiFi connected");
   Serial.println("IP address: ");
   Serial.println(WiFi.localIP());

   GetPage();
}

void GetPage() {
   Serial.print("connecting to ");
   Serial.println(host);
 
   if (!client.connect(host , port)) {
      Serial.println("connection failed");
      return;
   }

   Serial.print("Requesting URL: ");
   Serial.println(url);
   
   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
   "Host: " + host + "\r\n" +
   "Connection: close\r\n\r\n");
   
   delay(5000);
   
   while(client.available()){
      String line = client.readStringUntil('\r');
      Serial.print(line);
   }
   
   Serial.println();
   Serial.println("closing connection");
}



void loop() {
   String content = "";
   char character;
   
   while (Serial.available()){
      character = Serial.read();
      content.concat(character);
   }

   if (content != "") {
      CMD = stringOne.substring(0, 4);
      DATA = stringOne.substring(5);

      if (CMD == "SSID"){
         strcpy(ssid, DATA.c_str());
      }else if (CMD == "PASS"){
         strcpy(password, DATA.c_str());
      }else if (CMD == "HOST"){
         strcpy(host, DATA.c_str());
      }else if (CMD == "SEND"){
         client.print(DATA);
      }else if (CMD == "PORT"){
         port = DATA.toInt();
      }else if (CMD == "URL") {
         strcpy(url, DATA.c_str());
      }else if (CMD == "GET") {
         GetPage();
      }else if (CMD == "JOIN") {
         JoinAccessPoint();
      }
   }
   delay(100);
}
 

Re: Here is a small sketch to make the ESP8266 Easier to use

PostPosted: Fri Feb 05, 2016 1:29 pm
by johnbravo
my goal here is to make it as easy to as possible. just plug it into an Arduino and tell it what to do. I personally dont like using the AT commands or lua. Any feedback or suggestion are welcom

Re: Here is a small sketch to make the ESP8266 Easier to use

PostPosted: Sat Feb 06, 2016 10:48 pm
by preinoso
You read my mind! :D I was just going to code something like this to use in an app im working ok. Congrats

Re: Here is a small sketch to make the ESP8266 Easier to use

PostPosted: Fri Apr 08, 2016 6:35 pm
by inciteman
Has anyone tried using this code? It seems like it has a few errors, won't compile.

CMD, StringOne, DATA, JoinAccessPoint() are not defined?