Saturday 26 November 2016

Internet of Things using ESP8266

Internet of Things using ESP8266

ESP8266 is the serial WiFi module which can be interfaced to the Microcontroller using UART.
In my Earlier post i have given configuration steps of wifi module you can refer it 
Wifi Module though operates at 3.3V but Tx and Rx pins operates at TTL level.ARM Cortex M3 based controller operates at CMOS level hence a level-translator is  required. CD4050 ic can be used as level translator for this Tx of Microcontroller must be given as input to CD4050 and o/p of CD4050 must be connected to Rx of esp8266.
Tx of esp8266 can be connected to Rx through 10K resistor.


Internet of Things : Connectivity of things sensors connected to controller can independently convey information to the controller based on which necessary action can be taken. If same information is transferred to a webserver which can host that data, user can have access to that data from any location over internet.



To achieve Internet of things an IOT cloud is required there are so many free IOT sites that can be used for implementing IOT. Here i will show one site https://thingspeak.com

1) Create an account in https://thingspeak.com

2)Create New Channel in Thingspeak on success it will assign a unique channel id
   provide name and description of IOT leave others fields in default mode.
3) Go to API keys: these keys are essential for updating data on server.
4) you can test by adding sample data to the created field on site
open browser and type 
https://api.thingspeak.com/update?key=API_KEY&filed1=6
replace API_KEY with actual key that you will get in your channel and press enter
if you check in your channel you can find a sample value of 6 will be added to graph1 with Date& Time.

5) Using esp8266 establish TCP connection with the thingspeak server (184.106.153.149)

List of AT command you have to pass to esp8266 using ARM Cortex M3 based controller
you can use UART program to pass commands consider uartStr ("string"); is the function to push AT commands on Tx Line of Microcontroller. Assume communication baudrate as 9600

List of commands you should pass after each command give a delay of 100 to 1000milli seconds

1) uartstr("AT\r\n"); //note \r\n are must for passing commands to esp8266
it will respond with OK

2)uartstr("AT+CWLAP\r\n"); // will list available Access points

3)uartstr("AT+CWMODE=3\r\n"); //Both SERVER and Access point

4)uartstr("AT+CIPMUX=1\r\n"); //to allow multiple connections  for communication

5)uartstr("AT+CWJAP=\"name\",\"password\"\r\n"); //connect with Internet provider access point or wifi  router, where name should be name of access point or wifi router and password should be relevant password

6)uartstr("AT+CIPSTART=4,\"TCP\",\"184.106.153.149\",80\r\n"); //for establishing TCP connection with thingspeak site
you should get response of OK Linked
7)uartstr("AT+CIPSEND=4,44\r\n"); //command to send data on channel4 of size 44bytes
as response you will get ' >' 
8)uartstr("GET /update?key=API_KEY&field1=6\r\n");//note replace API_KEY with your channel API_KEY this will update field1 with 6 

9) uartstr("AT+CIPCLOSE\r\n"); //for closing connection with server

   
    download code

No comments:

Post a Comment