WiFi Serial Connection
ESP8266
d. bodnar revised
07-08-15
http://192.168.1.29/gpio/1 http://192.168.1.29/gpio/0
I have been experimenting with a small (about 1" x 1/2") board that provides WiFi access to the internet and can be used to send data via a serial port.
The output of the unit is currently being hosted by www.thingspeak.com, a free web service that can be used to graphically display such data.
The current test data (just the temperature on my workbench or something I am
currently working on) can be see here:
https://thingspeak.com/channels/19064
This graph shows the same data:
My latest experimentation involves reading temperature and ambient light level. This data is also on thingspeak here:
https://thingspeak.com/channels/18994
These boards are available on eBay - just search for esp8266. The cost, with delivery, should be less than $5.00.
I currently have the units I received working well with an Arduino Pro Mini. I am using a board that I designed for model railroad DCC work as a test platform. The test unit is shown here:
http://www.dx.com/p/crius-ftdi-basic-breakout-5v-usb-to-ttl-6-pin-module-for-mwc-multiwii-lite-se-228307#.VHEQuMlNfzo -- serial adapter
resistor needed
May need AT+CWMODE=3 before connecting to WiFi
AT+CWJAP="main","password" +CR+LF - connect to access point
AT+CWLAP - show access points
+CWLAP:(1,"3VC01",-90,"00:1f:90:e7:0a:de",1)
+CWLAP:(1,"main",-52,"00:1f:90:b3:63:10",6)
+CWLAP:(3,"XD8Y3",-93,"f8:e4:fb:14:ec:0d",6)
+CWLAP:(1,"One",-71,"00:90:4c:c0:00:03",4)
+CWLAP:(1,"Two",-59,"30:46:9a:9a:b9:48",11)
AT+CIFSR - get IP address
9600 - n81 - add CR/LF to each entry
From:http://www.instructables.com/id/Using-the-ESP8266-module/step6/Running-a-simple-webserver-in-BASIC/
If you are using a terminal program connected to your 8266 module, take note of the following commands..
AT+CIPMUX=1
AT+CIPSERVER=1,80
These two commands set up the magic to make the module automatically answer a request from another computer or device. In my case, I've configured the module to answer web requests on port 80.
On Serial/USB gizmo
WHITE TO TX
GREEN TO RX
OnESP8266
white to rxd (yellow on image below)
green to txd (green on image below)



#include<stdlib.h>
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define SSID "main"
#define PASS "abcdeabcde"
#define IP "184.106.153.149" // thingspeak.com
String GET = "GET /update?key=VPPK6NPY1OWYNERI&field1=";
SoftwareSerial monitor(10, 11); // RX, TX
int RsetWiFi = 12; //reset pin on WiFi module
void setup()
{
pinMode(RsetWiFi, OUTPUT);
digitalWrite(RsetWiFi, HIGH);
delay(1000);
monitor.begin(9600);
Serial.begin(9600);
sensors.begin();
sendDebug("AT");
delay(3000);
if(Serial.find("OK")){
monitor.println("RECEIVED: OK");
connectWiFi();
}
}
void loop(){
digitalWrite(RsetWiFi, LOW); //reset WiFi unit
delay(1000);
digitalWrite(RsetWiFi, HIGH); // complete reset
delay (3000);
sendDebug("AT");
delay(3000);
if(Serial.find("OK")){
monitor.println("RECEIVED 2nd: OK");
connectWiFi();
}
// sendDebug("AT+RST");
delay(3000);
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
tempC = DallasTemperature::toFahrenheit(tempC);
//monitor.println(tempC);
char buffer[10];
String tempF = dtostrf(tempC, 4, 1, buffer);
updateTemp(tempF);
// sendDebug("fahrenheit");
// sendDebug(tempF);
delay(6000); //was 60000
}
void updateTemp(String tenmpF){
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
delay(2000);
// if(Serial.find("Error")){
// monitor.print("RECEIVED: Error");
// return;
// }
cmd = GET;
cmd += tenmpF;
cmd += "\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">")){
monitor.print(">");
monitor.print(cmd);
Serial.print(cmd);
}
else{
sendDebug("AT+CIPCLOSE");
}
if(Serial.find("OK")){
monitor.println("RECEIVED: OK");
}
else{
monitor.println("RECEIVED: Error");
}
}
void sendDebug(String cmd){
monitor.print("SEND: ");
monitor.println(cmd);
Serial.println(cmd);
}
boolean connectWiFi(){
Serial.println("AT+CWMODE=1");
delay(2000);
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
sendDebug(cmd);
delay(5000);
if(Serial.find("OK")){
monitor.println("RECEIVED: OK");
return true;
}
else{
monitor.println("RECEIVED: Error");
return false;
}
}
|