Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created February 20, 2017 17:00
Show Gist options
  • Save manashmandal/8b92e68aacd85d1daff5bb5f36dae845 to your computer and use it in GitHub Desktop.
Save manashmandal/8b92e68aacd85d1daff5bb5f36dae845 to your computer and use it in GitHub Desktop.
ESP8266 With Arduino
#define baud 115200
#define RX 10
#define TX 11
#include <SoftwareSerial.h>
String inputString = "";
bool stringComplete = false;
SoftwareSerial wifi(RX, TX);
void setup() {
Serial.begin(baud);
wifi.begin(baud);
wifi.setTimeout(1000);
// put your setup code here, to run once:
while(!wifi);
Serial.println("ESP8266 Demo on Mega2560");
while(wifi.available() > 0){
Serial.println(wifi.read());
}
wifi.println("AT\r");
Serial.println(wifi.readStringUntil('\n'));
//
delay(1000);
//Set Static IP of the Wifi module
wifi.println("AT+CIPSTA=\"192.168.101.2\",\"192.168.101.1\",\"255.255.255.0\"\r");
delay(1000);
// Connect to a wifi hotspot, set the ssid and password according to your pc
wifi.println("AT+CWJAP=\"PC-Faster\",\"654321987\"\r");
delay(10000);
}
void loop() {
wifi.print("AT\r\n");
// put your main code here, to run repeatedly:
Serial.println(wifi.readString());
delay(100);
//This will establish a TCP [Transmission Control Protocol] with http://webwork.manash.me website
wifi.print("AT+CIPSTART=\"TCP\",\"webwork.manash.me\",80\r\n");
Serial.println(wifi.readString());
delay(1000);
wifi.print("AT+CIPSEND=77\r\n");
delay(1000);
//This will send a GET Request to the url with some parameters
wifi.print("GET /esp8266.php?apples=400&oranges=22 HTTP/1.1\r\nHost: webwork.manash.me\r\n\r\n\n");
delay(1000);
Serial.println("SENDING DONE");
// Read back response
if (stringComplete){
Serial.println(inputString);
inputString = "";
stringComplete = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment