Introduction: Internet of Things ESP8266 Basic Code Adruino to Update Data
Dear all,
Internet of thing (IoT) is now a revolution, listen all objects via wifi connection.
I also read this new on newspaper, and then I buy module ESP8266 to test.
Starting to play this module I also search all document on web,I face with some problem and cost a few hours for this test.
I post this code with purpose to help someone touch IoT with the shortest time.
It is very simple,very basic and so clear ...send open command and don't check respone.
Here is this
// Hardware ESP8266 module and one of many kinds Adruino board (support 3.3V)
// ESP8266 -- Adruino Board
// VCC--3.3V
// GND--GND
// RX--TX
// TX--RX
// CH_PD--3.3V
// NOTE: when you download firmware open thish connection :)
void setup() {
// put your setup code here, to run once:
delay(3000);
Serial.begin(9600);
}
void loop() {
int iData=0;
String cmd="";
Serial.println("AT");delay(1000);
Serial.println("AT+RST");delay(5000);// reset esp
Serial.println("AT+CWMODE=0");delay(1000);// Mode=0
Serial.println("AT+CWLAP");delay(8000);// search all wifi network around
Serial.println("AT+CWJAP=\"TamNguyenE11_WIFI\",\"12345678\"");delay(8000);// connect your wifi
Serial.println("AT+CWJAP?");delay(3000);// check now available Connection
iData=100;// initial Data
while(1) {
Serial.println("AT+RST");delay(5000);// reset esp8266
Serial.println("AT+CIFSR");delay(1000);// check now IP
Serial.println("AT+CIPMODE=0");delay(500);//Mode=0
Serial.println("AT+CIPMUX=1");delay(500);// MUX=1
Serial.println("AT+CIPSTART=0,\"TCP\",\"api.thingspeak.com\",80");
delay(2000);// connect to api.thingspeak.com
// You creat account on thingspeak.com and then You create chanel, get "key" and field1 is a chart which you want to update data
cmd="GET http://api.thingspeak.com/update?key=B8E3YIP8XI89...
cmd+=String(iData);
iData++;
if(iData>130) iData=100; // test send data from 100-130 to your chanel on thingspeak.com
cmd+=" HTTP/1.0\r\n\r\n";
Serial.print("AT+CIPSEND=0,");
Serial.println(cmd.length());delay(500);
Serial.print(cmd);
delay(3000);
Serial.println("AT+CIPCLOSE");delay(500);// close connection
}
}
// Good luck