
ESP-03 ESP8266 Serial Wifi Module
ESP-03 ESP8266 Serial Wifi Module
This tiny wifi Module is the perfect replacement for your NRF Radio! It's a great alternative to the popular NRF, because this lets you talk over Wifi using your MCU's serial UART via RS232!
We've got code examples, datasheets and schematics listed below to help you get started!
1
ESP2866 Wifi Module
115200
3.3V Power Only - do NOT attempt to use 5V because it may fry this chip!
/********************************** UPGRADE INDUSTRIES Micro License: Copyright UPGRADE INDUSTRIES This software is free to use, modify, and sell, but this notice MUST REMAIN INTACT at the top of software as it appears now. **********************************/ // Description: This software will listen for a connection // from a remove computer and print out what it receives #include <SoftwareSerial.h> #include <ByteBuffer.h> // 1. Edit these: #define SSID "SSID" #define PASS "PASSWORD" #define LISTEN_PORT 6000 // 2. Verify this: // Change this to the Serial path connecting // to your ESP8266 module #define ESP8266 Serial // Used to create dummy code that doesn't actually print class DummySerial{ public: DummySerial(int rx, int tx){} void begin(int baud){} void println(String str){} void print(String str){} void print(const __FlashStringHelper* str){} void println(const __FlashStringHelper* str){} void print(int num){} void println(int num){} void print(const char* str){} void println(const char* str){} }; // 3. Check this // You have to define alternative debug serial // if you need to monitor this program with a terminal SoftwareSerial SoftSerial2(10, 11); // RX, TX DummySerial DummySerial(10, 11); // RX, TX - doesn't matter // because it won't // print anything // 4. Set this: - Choose whether to not print any debug or // to route to SoftwareSerial // #define DEBUG SoftSerial2 #define DEBUG DummySerial //Connect to accept point and setup MUX mod boolean connectWiFi() { //set mode to connect to an AP ESP8266.println("AT+CWMODE=1"); delay(1000); if(ESP8266.find("OK")) { DEBUG.println("OK, Set Mode."); } else { DEBUG.println("Can not set mode."); return false; } //Setup connection command String cmd="AT+CWJAP=\""; cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; DEBUG.println(cmd); ESP8266.println(cmd); delay(2000); if(ESP8266.find("OK")) { DEBUG.println("OK, Connected to WiFi."); } else { DEBUG.println("Can not connect to the WiFi."); return false; } return true; } boolean enableMultiConnect(){ ESP8266.println("AT+CIPMUX=1"); return ESP8266.find("OK"); } void printMyIp(){ ESP8266.println("AT+CIFSR"); while (ESP8266.available()){ DEBUG.write(ESP8266.read()); } } //Create a connection to send data to something. boolean connect(int connection, String type, String ip, int port){ String cmd = "AT+CIPSTART="; cmd += String(connection); cmd += ",\""; cmd += type; cmd += "\",\""; cmd += ip; cmd += "\","; cmd += String(port); DEBUG.print(F("Telling device to connect on connection [")); DEBUG.print(connection); DEBUG.print(F("] to address [")); DEBUG.print(ip); DEBUG.print(F("]\n")); DEBUG.print(F("] on port [")); DEBUG.print(port); DEBUG.print(F("]\n")); delay(1000); ESP8266.println(cmd); DEBUG.println(cmd); if(ESP8266.find("OK")) { DEBUG.println("...connected"); } else{ DEBUG.println(F("Could not create connection.")); return false; } return true; } //setup server to listen on a specific port for both UDP and TCP boolean listen(int connection, int port){ String cmd = "AT+CIPSERVER="; cmd += String(connection); cmd += ","; cmd += String(port); DEBUG.print(F("Telling server to listen on connection [")); DEBUG.print(connection); DEBUG.print(F("] on port [")); DEBUG.print(port); DEBUG.print(F("]\n")); DEBUG.println(cmd); ESP8266.println(cmd); delay(1000); for(int i=0;i<5;i++) { if(ESP8266.find("OK")) { return true; } else { DEBUG.println("Could not setup server to listen."); } delay(25); } return false; } boolean sendData(int connection, String data){ String cmd = "AT+SEND="; cmd += String(connection); cmd += ","; cmd += String(data.length()); DEBUG.print(F("Sending data to connection [")); DEBUG.print(connection); DEBUG.print(F("]")); DEBUG.println(cmd); ESP8266.println(cmd); delay(100); if(ESP8266.find(">")) { DEBUG.println("...sending"); } else { DEBUG.println("Could not send data"); return false; } DEBUG.println(data); ESP8266.println(data); delay(1000); if(ESP8266.find("OK")) { DEBUG.println("...sent"); } else { DEBUG.println("Could not send data."); ESP8266.print("AT+CIPCLOSE="); ESP8266.println(String(connection)); return false; } return true; } boolean resetESP8266(){ //test if the module is ready ESP8266.println("AT+RST"); delay(1000); if(ESP8266.find("ready")) { DEBUG.println("Module is ready"); return true; } else { DEBUG.println("Module had no response. Reset and try again.."); return false; } } void ATPing(){ ESP8266.println("AT"); } void setup() { // Open DEBUG communications and wait for port to open: ESP8266.begin(115200); DEBUG.begin(9600); DEBUG.println("UPGRADE INDUSTRIES Wifi Server Demo"); //connect to the wifi (try several times) boolean connected=false; for(int i=0;i<5;i++) { if(resetESP8266()) { delay(1000); if(connectWiFi()) { // all good connected = true; break; } delay(2000); } else { //error DEBUG.println("Couldn't connect to access point."); } } if(connected){ //Setup mode for multiple connections enableMultiConnect(); delay(1000); printMyIp(); delay(1000); if(listen(1, LISTEN_PORT)) { delay(1000); }else{ // ERROR - coundn't listen to port DEBUG.println("Couldn't listen to port."); while(1); } }else{ //ERROR - Not connected DEBUG.println("Not connected."); } ATPing(); } void loop() { if(ESP8266.find("OK")){ // Uncomment to print out results while(ESP8266.available()){ DEBUG.write(ESP8266.read()); } } else { } delay(100); }