Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <SPI.h>
- //#include <Ethernet.h>
- #include <ESP8266WiFi.h>
- const char* ssid = "EVERTON";
- const char* password = "qwertyui";
- // Special commands
- #define CMD_SPECIAL '<'
- #define CMD_ALIVE '['
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- //byte mac[] = {
- // 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- //IPAddress ip(192,168,1,60);
- // Initialize the Ethernet server library
- // with the IP address and port you want to use
- // (port 80 is default for HTTP):
- WiFiServer server(80);
- //EthernetServer server(80);
- //EthernetClient client;
- void setup() {
- Serial.begin(115200);
- delay(10);
- pinMode(2, OUTPUT);
- pinMode(2, LOW);
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- //Ethernet.begin(mac, ip);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- server.begin();
- Serial.println("Server started");
- Serial.println(WiFi.localIP());
- server.println("Thanks for your support");
- }
- void loop() {
- int appData;
- // ===========================================================
- // This is the point were you get data from the App
- WiFiClient client = server.available();
- if (client){
- appData = client.read();
- }
- switch(appData){
- case 'A': // Turn on pin 2
- digitalWrite(2, HIGH);
- break;
- case 'a': // turn off pin 2
- digitalWrite(2, LOW);
- break;
- case CMD_SPECIAL:
- // I hope you did not enabled accelerometer or seek bars, so this will never be called
- break;
- case CMD_ALIVE:
- // Character '[' is received every 2.5s, use
- // this event to tell the android we are still here
- server.println("Please move to example code");
- break;
- }
- // ==========================================================
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement