Saturday, 28 February 2015

Arduino cheap WIFI solution -- ESP8266 (test and verify calling http restful endpoint )

This post will only show you how to use ESP8266 with Arduino, for more information such ESP8266 version and the detail of the pins of  ESP8266, I will post another post later.

1. you should connect arduino with your computer and write a arduino program into it. Any program will be ok.

2. you should connect ESP8266 and Arduino like this:


Note: please make sure you do write code into arduino first and then disconnect arduino with your computer and change the wire later.

Note: when you have a wire connects with your arduino, you cannot write code to arduino!!!!

3. Open serial monitor to send commands to ESP8266 and test it: (make sure you use the settings of serial monitor, you can do the same setting as my snapshot below, "Both NL & CR" and "9600 baud")

input "AT" and then use Enter key or click "Send" button:

It will response:

Input :  AT+RST

Input:  AT+CWMODE=1

Input :  AT+CWJAP="Cisco05642","ASDFZXCV"  to connect to your WIFI with SSID and password.

Input: AT+CIFSR   for checking your IP

--------Below will use ESP8266 send http request to server:

input:   AT+CIPMUX=1

link to google by:  AT+CIPSTART=4,"TCP","",80

After that, then connection was linked. According to http protocol, you should notice server your message length by :   AT+CIPSEND=4,18   (please do not include space at the beginning and the end)

Then ESP8266 will return ">", that indicate that you can send message body now:

Input : GET / HTTP/1.0      (after that you should input 2 enters)

Then you will get:

4. If you want to raptly call this link you can run blow commands:

GET / HTTP/1.0

5. for another url:

GET /api/things HTTP/1.0

28 is the length of your message.

The message you send out is "GET /api/things HTTP/1.0". The length of it is 24, but why 28?

Because, according to HTTP protocol 1.0  the message body should end up with "/r/n"


No comments:

Post a comment