Dhananjay Khairnar @. Powered by Blogger.

27 September 2016

ESP8266 AT firmware : 

As in previous post we have seen ESP8266 as stand alone but some time in some application we need only WiFi connectivity or simple WiFi module that can be controlled through AT commands. we can program ESP8266 for work on AT command.

1) ESP8266
3) USB to serial convertor

Step 1: 
Setup ESP8266 as given in this post.

Step 2:
 Download ESP8266 AT command firmware by AI Thinker.

Step 3:
press and hold Flash button(GPIO0 = GND) then press Reset button(RESET pin = GND)
release RESET button then Flash button now ESP8266 goes into Flash mode.

Step 4:
Extract downloaded rar file.
Step 5:
open "flash.cmd"  file and wait for complete flashing process.


Step 6: 
Setup local Server for receive data. I use TCPClientServe software which allow you to create local server and client to send and receive data over TCP
Download Here

 Enter port 6000 and start listening.

Step 7 : 
Open Serial terminal at baudrate 115200
Give Comman Sequence To send data to Server

1) AT
2) AT+CWAUTOCONN=0  ---> disable autoconnection
3) AT+CWMODE=1 ---> set station mode
4) AT+CWJAP="MyRouter","MyRouterPassword" --->connect to local WiFi router
5) AT+CIPSTA_DEF="" ---> set static IP
6) AT+CIPSTART="TCP","",6000 --->your local server IP adress
7) AT+CIPSEND=10 --> number of bytes to send
8) 12345678 ---> actual data to send

Console Output:

 Ai-Thinker Technology Co.,Ltd.











Recv 10 bytes


Published: By: DK - 04:03

Fetch and parse JSON on ESP8266 wifi module :

Use case:
 I want monitor particular json stored on server which can be modify by website from remote distance.
It can be useful where you can modify control bits from website and change GPIO status at ESP8266 side.

1) Home automation
2) Information parsing
3) Staus monitoring
4) non realtime notification

This system work on principle on monitoring files.

Feature :
  Stand alone operation of ESP8266.
  Uses JSON parsing so data extraction is very easy.

Required :
2)Arduino or any USB to serial converter with 3.3v or 5v power connection pin out.

Basic Working:
  • ESP8266 : 
It uses the local router to connect internet and fetch JSON from server using HTTP get request after every second parse it and display JSON variables on serial monitor(you can compare them and change GPIO for device control).

Shown in diagram it send GET request at server and server send back HEADER + JSON to ESP8266
HTTP request :
 client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host:" + host + "\r\n" +
                "User-Agent:Mozilla/5.0(Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0" +
                "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" +

 Server Responce:
HTTP/1.1 200 OK
Vary: Host,Accept-Encoding
P3P: CP="Not supported"
Set-Cookie: _xta_uid=4945816047688c1c34e113b0f9c163b0; expires=Thu, 27-Sep-2018 06:01:09 GMT; Max-Age=63072000; path=/; domain=.mobie.in; httponly
Content-Type: text/plain;charset=UTF-8
Content-Length: 530
Accept-Ranges: bytes
Date: Tue, 27 Sep 2016 06:01:17 GMT
X-Varnish: 644140890
Age: 0
Via: 1.1 varnish
X-Robots-Tag: Crawl-delay: 10

   "id": 1,
   "name": "Leanne Graham",
   "username": "Bret",
   "email": "Sincere@april.biz",
   "address": {
     "street": "Kulas Light",
     "suite": "Apt. 556",
     "city": "Gwenborough",
     "zipcode": "92998-3874",
     "geo": {
       "lat": "-37.3159",
       "lng": "81.1496"
   "phone": "1-770-736-8031 x56442",
   "website": "hildegard.org",
   "company": {
     "name": "Romaguera-Crona",
     "catchPhrase": "Multi-layered client-server neural-net",
     "bs": "harness real-time e-markets"

to separate only data and neglect header i used
    line = client.readStringUntil('\r');

this code store data in 'line'  untile received data ends with '\r' ,
we received data as  [ header + \r\n\r\n + data(json) + \r\n\r\n ]
so first instance "line" contain header, As next data received "line" override with data(json).

 this data is given to the JSON pacer along with user define structure to store in local variables.
  • Server :
          Stores the html page, json file and jsp scripts. Server gives access to the ESP8266 and remote client. Server can execute the jsp script as per remote client request to modify JSON file. this is not implemented yet.
  •  Remote Client : 
         Can access webpage that contain control panel or GUI for modify JSON file as per requirement here in this tutorial I have not implemented this.

Step 1:
Follow this post to setup ESP8266 programming environment with Arduino IDE.

Step 2 :
Register at any free web hosting site  or you can have your own domain or you can test it with your local server.
I used http://xtgem.com to host test.json file.
Register -
Create New Site - here i created "codersmagic.mobie.in"

Step 3:
Create JSON file
for create json file you can use any online json creator. Past json data in simple txt file and rename it as JSON.

Note : before save json file confirm that it don't contain any hidden '\r' in it.  '\n' is ok.

Here I used Notepad++ to replace '\r' with non-value means erase all '\r'
 save test.json file.

Step 4 :
Goto xtgem.com > login > click on your site > upload test.json file to '/' root directory
 here I alredy uploaded JSON file.
confirm that json file is accessible in web browser from URL given in right side corner link.

Step 5: 
 Downlod Arduino json parsing librabry from given url https://github.com/bblanchon/ArduinoJson . install it in Arduino IDE from Sketch > include library > Add .ZIP library...

Now upload following sketch in ESP8266.


const char* ssid     = "MyRouter";
const char* password = "MyRouterPassword";

const char* host = "codersmagic.mobie.in";
const int httpPort = 80;
char charVar[15];

struct UserData {
  int id;
  char name[32];
  char username[32];
  char email[32];
          char street[32];
          char suite[32];
          char city[32];
          char zipcode[32];
                 char lat[10];
                 char lng[10];
  char website[32];
  char company[32];

UserData userData;

void setup() {

  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

void loop() {
  String line;
  Serial.print("connecting to ");

  // Use WiFiClient class to create TCP connections
  WiFiClient client;

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");

  // We now create a URI for the request
  String url = "/test.json";

  Serial.print("Requesting URL: ");

  // This will send the request to the server.
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host:" + host + "\r\n" +
                "User-Agent:Mozilla/5.0(Windows NT 6.3; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0" +
                "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" +
  // Read all the lines of the reply from server and print them to Serial
    line = client.readStringUntil('\r');
   // Serial.print(line);
  Serial.println("----------------------JSON PARSER-------------------------");

  char* charBuf = (char*)malloc(sizeof(char)*1024);  //dynamic memory allocation avoid most of ESP watch dog exeptions
      if (parseUserData(charBuf, &userData)) {
  free(charBuf); // remember to free dynamic memory

  Serial.println("closing connection");

bool parseUserData(char* content, struct UserData* userData) {
  // Compute optimal size of the JSON buffer according to what we need to parse.
  // This is only required if you use StaticJsonBuffer.
  const size_t BUFFER_SIZE =
      JSON_OBJECT_SIZE(8)     // the root object has 8 elements
      + JSON_OBJECT_SIZE(5)   // the "address" object has 5 elements
      + JSON_OBJECT_SIZE(2)   // the "geo" object has 2 elements
      + JSON_OBJECT_SIZE(3);  // the "company" object has 3 elements

  // Allocate a temporary memory pool on the stack
  StaticJsonBuffer jsonBuffer;
  // If the memory pool is too big for the stack, use this instead:
  // DynamicJsonBuffer jsonBuffer;

  JsonObject& root = jsonBuffer.parseObject(content);

  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  //root.prettyPrintTo(Serial);   //print raw JSON data
  // Here were copy the strings we're interested in
  userData->id = root["id"];
  strcpy(userData->name, root["name"]);
  strcpy(userData->username, root["username"]);
  strcpy(userData->email, root["email"]);
  strcpy(userData->address.street, root["address"]["street"]);
  strcpy(userData->website, root["website"]);
  strcpy(userData->company, root["company"]["name"]);
  // It's not mandatory to make a copy, you could just use the pointers
  // Since, they are pointing inside the "content" buffer, so you need to make
  // sure it's still in memory when you read the string

  return true;

void printUserData(const struct UserData* userData) {
  Serial.print("id = ");
  Serial.print("Name = ");

  Serial.print("User Name = ");

  Serial.print("Email = ");

  Serial.print("Adress = ");

  Serial.print("Suite = ");
  Serial.print("City = ");

  Serial.print("Zip Code = ");
  Serial.print("website = ");
  Serial.print("Company = ");
  "id": 1,
   "name": "Leanne Graham",
   "username": "Bret",
   "email": "Sincere@april.biz",
   "address": {
     "street": "Kulas Light",
     "suite": "Apt. 556",
     "city": "Gwenborough",
     "zipcode": "92998-3874",
     "geo": {
       "lat": "-37.3159",
       "lng": "81.1496"
   "phone": "1-770-736-8031 x56442",
   "website": "hildegard.org",
   "company": {
     "name": "Romaguera-Crona",
     "catchPhrase": "Multi-layered client-server neural-net",
     "bs": "harness real-time e-markets"

 Step 6:
 See the serial log for JSON data on baud rate 115200.

Connecting to MyRouter
........WiFi connected
IP address:
connecting to codersmagic.mobie.in
Requesting URL: /test.json

----------------------JSON PARSER-------------------------

id = 1
Name = Leanne Graham
User Name = Bret
Email = Sincere@april.biz
Adress = Kulas Light
Suite = Apt. 556
City = Gwenborough
Zip Code = 92998-3874
website = hildegard.org
Company = Romaguera-Crona
closing connection

some time you get error like
----------------------JSON PARSER-------------------------
JSON parsing failed!

It is due to frequently hinting the same URL, server ignore some request you can adjust delay between two request to avoid this issue. still it is not guaranty that the HTTP response will receive for every request.

If have any question please comment below.

Published: By: DK - 00:33

26 September 2016

Testing BLD( Brushless DC) motor with arduino:

1) BLD motor link for buy in India(cost 450rs - 500rs)(Buy from Amezon)
Note: carefully buy BLD motor 1000KVA is ok for beginners. see the bullet connectors are their.
2) ESC( Electronic Speed Controller)(cost 450rs - 500rs)(Buy from Amezon).
3)Arduino UNO.
4)Power Supply or  11.1v battery (it will be ok if voltage source between 8v - 12v , 2A).
5) Connecting wires.

Step 1:
 see the part witch i used to test BLD motor 

BLD motor

Propellar( Be careful before ruining motor with propeller)( you can Buy from Amezon).
Step 2 :
Their is two method to operate BLD motor using arduino 
 i) By using library and without library
 ii) Without library

 Step 3 :
Make connection between BLD motor and ESC as given in diagram
Note  : Do not connect ESC vcc pin to Arduino. May be it will damage ESC

Step 4 : load one of the following sketch in arduino.
 here pin 10 is signal pin.

With Library : 
install servo library in Arduino IDE from library manager if not install before

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN 10

Servo motor;

void setup() {
  Serial.println("Program begin...");
  Serial.println("This program will calibrate the ESC.");


  // Wait for input
  while (!Serial.available());

  Serial.println("Now writing maximum output.");

  // Send min output
  Serial.println("Sending minimum output");


void loop() { 

for start motor open serial terminal and pass any integer value.

Without library:
 int ESCpin = 11;    // ESC signal wire connected to pin 11 on arduino
int val = 0;        //variable to store PWM value

void setup()
void loop()
 for(val = 0; val <= 255; val += 5)
   analogWrite(ESCpin, val);

Step 5 :
Now power on suply and hold motor at base tightly or you can make plywood board to fix it. don't try to run motor with propeller as it will be very dangerous to you. 

Published: By: DK - 04:15

10 September 2016

Program ESP8266 WiFi module with Arduino IDE:

The Arduino IDE software (short for Integrated Development Environment) is the foundation of what has made the Arduino platform so successful. With it, Makers can program a wide range of compatible microcontroller boards using Arduino’s relatively approachable programming language. Behind the scenes, the IDE software translates your instructions into a more complex code required for your board’s specific chip.
Aside from generally cleaning up a number of known bugs, the new update introduces a number of new tools and features.
One of the useful feature is board manager which allow use to add customized and diffrent board support in Arduino IDE.
In this tutorial we are going to add ESP8266 board in Arduino IDE and program it without and programmer simple using RX, TX pin.

Required :
1) ESP8266
2) Arduino UNO
3)connecting wires
4) Local wifi router

Step 1 :
For buy ESP8266 module here amezon link is given
Buy ESP8266 From Amezon
here I used ESP8266 12E

Step 2 : Install Arduino IDE. I used Arduino IDE v1.6.8

Step 3 : go to File > Preferences > Additional Board Manager URLs
paste this link in text field


 Step 4 : goto Tools > Board > Board Manger and search for "esp8266"
click on install button wait until board get install.


Step 5 : After successfully install board now take your arduino board remove controller. Now its only USB to UART converter with 5v and 3.3v power supply. Connect ESP8266 with Arduino board as shown in image.
as esp8266 datasheet mention it can work on 5v or 3.3v . but it affect on wifi range as 5v gives large range for module.

Step 6 :
Restar  Arduino IDE now connect arduino board with ESP8266 connection as in above diagram.
goto Tools > Board > Generic ESP8266 Module
default configuration is shown below image 

Step 7:
now install esp8266 library alredy made by developers with examples.
goto Skrtch > Include library > Manage libraries  Search for "ESP8266 webserver"
and install ESP8266WebServer library here I already installed it.

Step 8:
Goto File > Examples > ESP8266WebServer > AdvancedWebServer
made some changes in program. ssid and password.

Step 9 :
Note : ESP8266 is having 4 mode of operation 1)Genaral mode ,2) Boot mod, 3) Host mode, 4)AT command mode 
here we only deal with genaral mode and boot mode.
for load program in ESP8266 we have to go in boot mode for that Press and Hold FLASH button and then Press reset button  first release reset button then FLASH button. now your ESP8266 in boot mode

Step 10 : Upload program from Arduino IDE.

Step 11: For testing Web server open serial terminal at 115200 baud rate and get IP adress of server. outout of serial terminal like
Connected to MYtestWifi
IP address:
MDNS responder started
HTTP server started

Step 12 : goto your browser and hit IP address ( it may vary from your router configuration ) you will see the web page stored in your ESP8266 module.
 Here we use simple HTML page but you can use CSS and java script too as they are executed at client site.
The best place to ask questions related to this core is ESP8266 community forum: http://www.esp8266.com/arduino.
Published: By: DK - 00:38

9 September 2016

How to install Kali Linux on Raspberry PI:

Required :
1) Raspberry Pi
2) minimum 8GB memory card
3) USB cable
4) HDMI cable
5) HDMI Monitor
6) High speed internet

Step 1:
Download Kali Linux image for ARM from official site or below given link and Extract Kali kali-2.1.2-rpi2.img.xz file.

Image NameSizeVersion
RaspberryPi 2 / 31166M
RaspberryPi w/TFT880M

Step 2:
Download Win32 DiskImager software from source forge or given link https://sourceforge.net/projects/win32diskimager/ and install it.
Step 3:
put your memory card in card reader and connect it to compute here my drive is I: . Open Win32 DiskImager and select kali-2.1.2-rpi2.img file then select proper drive later for memory card if by mistake you choose hard disk partition it will wipe out that partition.
Click on write button. Wait until complete whole process don't remove card reader from USB port it will corrupt your memory card.

Step 4: after successful write message remove card reader safely and put SD card into raspberry pi.
Step 5: connect HDMI cable,Mouse,key board and then power cable to Raspberry PI .
Step 6: Wait until it will boot after inter login user as "root" and password as "toor"


Published: By: DK - 02:52