First conversation with ESP8266 (Station mode)

First conversation with ESP8266 (Station mode)

Hi Readers,

Today I want to talked about AT commands the ‘language’ to communicate with ESP8266 boards.

The simplest command is ‘AT’. It is like saying Hi to esp board and if it will replay with same ‘AT’ it means connection is good.

Each command must be ended with Carriage return <CR> and LineFeed <LF> in most of the language it is “\r\n” on the end of each string or command. In my serial port monitor application I have added two post ago <CR><LF> is added automatically after each command. So if you have never went across carriage return you can check it on my github source code.

Another command is ‘AT+CWMODE=1’ with parameter ‘1’. It sets ESP8266 to work in station mode which mean that it will be able to connect to any WiFi network and acts as normal device/client.

After that as we want to connect ESP8266 to our WiFi network we can query list of all near networks. As you can see on attached picture near me esp found more then 10 networks but we are interested in Fred’s Network which is my temporally home network.

 

Consola
Output from SerialPortMonitor application (avail. on github)

 

As you could see on included picture next command we need to use is ‘AT+CWJAP=”<network name>”,”<password>”. This command allows us to connect to any WiFi network when we know it’s name (and if set a password). After sending it you should get back ‘WIFI CONNECTED’ and ‘WIFI GOT IP’ response from ESP8266 module. Which mean that you have successfully connected to this network.

Now to get your IP address which provided by router you need to simply type ‘AT+CIFSR’.

 

Example:

AT

AT+RST

AT+CWMODE=1

AT+CWLAP

AT+CWJAP=”YourNetwork”,”Password”

AT+CIFSR

 

At this point you have ESP8266 connected to your router and you are ready to do more. But more about it I will describe in next post on GetToKnowTheBob blog.

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

 

Advertisements

ESP8266 prototype board

ESP8266 prototype board

Hi Readers,

Today I have done some tests with ESP8266 prototype board.

As I had lot of issues with missing parts or annoying problems with some technologies I decided to use this prototype board as main board which will work as coordinator and for first part I will use raspberry pi zero as end-device.

Prototype board is from china is cheap and easy to install.

Installation:

What you need to do you need to download and install drivers CH340 and that’s all. I have used drivers from this site http://www.arduined.eu/ch340-windows-8-driver-download/  I think this driver is directly provided by Chinese manufactures.

Board testing:

I have created SerialPortMonitor application (source code on the bottom) which will allow you to send all commands to ESP8266 prototype board you would like. As for example to test your board I would suggest to send “AT” and after that if board will response with “AT” it will mean it is working.

Serial port is hardcoded but if you like you can use Console.Read() to provide com port manually. Bear in mind that for me seria port speed set to 9600 didn’t work for me. I have used 115200 and after that was fine.

I have decided to create this basic application even there are many tools which will allow you to send AT commands to ESP8266 prototype board but I think this application is good basic base to start working on your own ESP8266 application.

SerialPortMonitor source code:

private static string indata = string.Empty;

static void Main(string[] args)
{
var indata = string.Empty;
SerialPort serialPort = new SerialPort(“COM5”);
serialPort.BaudRate = 115200;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.DataBits = 8;
serialPort.Handshake = Handshake.None;
serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

try {
serialPort.Open();
}
catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(“Application had an exception and must be closed. Press any key to continue…”);
Console.ReadLine();
return;
}

Console.WriteLine(“Write ‘end’ when you will wish to close this application.”);
Console.WriteLine(“To send command press enter (remember that \\r\\n characters will be added automatically to end of the command).\n\n”);
while (true) {
indata = Console.ReadLine();
if (!indata.StartsWith(“end”)) serialPort.WriteLine(indata + “\r\n”);
else break;
}

serialPort.Close();
}

private static string ProcessIncommingData(string data)
{
data = data.Replace(“\r”, @”\r”);
data = data.Replace(“\n”, @”\n”);
return data;
}

private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
indata += ProcessIncommingData(sp.ReadExisting());

if (indata.Contains(“OK\\r\\n”) || indata.Contains(“ERROR\\r\\n”))
{
Console.WriteLine($”<< {indata}\n”);
// DO SOMETHING WITH DATA
indata = string.Empty;
}
}

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

ESP8266

ESP8266

Hi Readers,

I have started using ESP8266 and I would like to share it with you.

So let’s begin. Connection of ESP8266 to Raspberry Pi is very easy as you can see on attached picture:

drawing
ESP8266 to Raspberry Pi

As you can see CH_PD is powered down so you need to connect 3.3V to it to power it up as your ESP8266 wont start.

After that you can start communication with esp module as first what you can do you can send ‘AT’ command which is like saying hi to module which after that if will replay with also ‘AT’ it will mean that connection has succeed.

I have wrote simple application in nodejs which you can use to test it you can find it in my github repository at:

https://github.com/rbrus/gettoknowthebob/blob/master/node.js/Coordinator/coordinator.js

or you can find it here:

console.log(“– Begin”);
var list = [“AT\r\n”,”AT\r\n”,”AT\r\n”,”AT\r\n”];
var start = 0;
var allData;
var SerialPort = require(‘serialport’).SerialPort;

var serialPort = new SerialPort(‘/dev/ttyAMA0’, {
baudrate: 115200,
dataBits: 8,
parity: ‘none’,
stopBits: 1,
flowControl: false
});

serialPort.open( function(error)
{
if(error)
{
console.log(‘failed to open: ‘ + error);
}
else
{
console.log(‘open serialport’);

serialPort.on(‘data’, function(data)
{
console.log(“data received: ” + data);
if(data == ‘AT+CWLAP\r\n’)
{
start = 1;
}
if(start == 1)
{
if(data.endsWith(‘OK\r\n’))
{
console.log(allData);
}
allData += data;
}
});

for (var i = 0; i < 3; i++ )
{
serialPort.write(list[i], function(err, results)
{
console.log(‘err ‘ + err);
console.log(‘results ‘ + results);
});
}
}
});
console.log(“– End”);

During next couple weeks I will be adding more information, trick and tips how to use ESP8266.

IMG_20160327_164000
Picture of my raspberry pi and ESP8266 module

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

Arduino and delivery of ESP8266

Arduino and delivery of ESP8266

Hi Readers,

Yesterday I had a new delivery at my doorstep. I have received NodeMCU with ESP8266 and two ESP8266 modules:

wifi20serial20transceiver20module
ESP8266 module
esp8266-nodemcu-developer-kit
Mcu ESP8266

Unfortunately I haven’t received external power supply which I ordered. So I am still waiting with my tests Arduino + ESP8266 as we need external power supply for ESP8266 module if we want to connect it wwith Arduino nano.

So what are ESP8266 modules?

As there is many really a lot of description around internet I will quote sparkfun as they have one of best:

The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino device and get about as much WiFi-ability as a WiFi Shield offers (and that’s just out of the box)! The ESP8266 module is an extremely cost effective board with a huge, and ever growing, community.

This module has a powerful enough on-board processing and storage capability that allows it to be integrated with the sensors and other application specific devices through its GPIOs with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, including the front-end module, is designed to occupy minimal PCB area. The ESP8266 supports APSD for VoIP applications and Bluetooth co-existance interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.

https://www.sparkfun.com/products/13678

In next couple weeks I will share with you experience I will have with ESP8266 module and prototype board.

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

What next?

What next?

Good morning readers!

I have just received copy of Arduino nano.Why I said copy as I have received Arduino nano clone from china. And I need to say it works and pretty well. Genuine Arduino nano cost about 30-35$ where Chinese clone cost about 2-5$. There is no 100% guarantee as it will work but I have read that 99% of them are fine. So I am inviting you to order one or another clone instead of paying more them 30$ (within shipment).

Okay so what next. If nothing will change for Get To Know The Bob project I have decided to use Raspberry PI 2 (Raspbian) + Arduino clone (three). Also I have forgotten to tell you. Except Raspberry Pi and arduino nano I have three Raspberry Pi Zero boards so if I will have I will also try to use them as another three end-devices.

Now as I have all devices I needed. I can start testing ESP8266 modules which another three I have received on Thursday. I did some tests with it week ago but I had only one module so I wasn’t able to connect with it to anything.

I had some time during last weekend. I have cleaned up all small apps I have created to this day. Whole source code I am pushing to my git repo. If you are interested in it please check my repository. List of applications:

  1. Coordinator application (Raspbian OS in C++)
  2. Enddevice application (node.js + javascript) // I have pushed it to my GIT but as I wrote in my previous post on my blog I will not use node.js anymore.
  3. Endevice application (Arduino)
  4. Basic monitor of incoming data from serial port (Win + C#) // This console app I will use to test my Arduino as it doesn’t have HDMI or any other video output. I will try to debug it by sending back through USB cable information I will need.

 

Okay. So now I have my basic software and devices. I think this is best moment to start testing ESP8266 modules and to try connect them with each other.

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

 

World without problems would be boring.

World without problems would be boring.

Hi,

This time I would like to share with you journey I had with node.js installation and javascript all problems I have experienced. On the end of post I will add short summary of what I decided to do after experienced problems.

So I have spend whole last weekend, the only two days I have to work on the project I spend by installing couple version of operating system and node.js. But I have end-up with many problems so let’s go through all of them one by one hopefully they will be also useful for you.

The first. I have installed raspbian version from early February. I don’t know why but it had some problems during node.js installation (unfortunately I don’t have logs to show as I have lost them) . Probably I was missing one or another library or simply I had stale libraries. So I have update whole apt tree apt-get update | apt-get upgrade but it didn’t help. I was unable to install any of node.js versions I’ve had. The hardest thing is the real problem could be somewhere else. The reason for that is not so mature node.js as a whole system (an idea). I have found X number of possible ‘best’ solution how to install node.js what version I should install also even on node.js website there are at list two or three ways to install node.js on linux. And which libraries we should have and how we should install it.

Solution: You can try use apt-get install node or apt-get install nodejs. I am not sure I have read it is exactly same things but apt-get install node didn’t work for me and apt-get install nodejs npm. Also as you can see I have added npm (node.js package manager) on the end of command line. Which I didn’t understand and I didn’t have time to try understand it but when I was install nodejs without npm it wasn’t working. Clear madness. Okay, so before install nodejs I have downloaded latest raspbian (which was released on the end of February). And it worked. Nodejs was installed.

Another problem was and will be with not again so mature libraries. E.g. I was trying to install ESP8266 library which need old serial port which of course I had latest one which didn’t worked. So I have old one but again now it was too old.

Last thing javascript. Overall I like javascript I used it when I have done website for my mum or when I have developed basic software for Philips Pronto. But after couple hours with node.js and javascript I have decided that for me writing application for that type of project in javascript is not ideal. You can check my git repository to check my small example JS file).

Later I have also tried ubuntu mate and Windows IoT. But raspbian seems to be the best choice.

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

 

Let’s begin.

Let’s begin.

This is my second day of coding but let’s talk about whole weekend and things I have done.

Yesterday I spend most of the time installation different operating *nix systems on my raspberry ii within trying to install node.js with all extensions. What I have found out it is not easy to get node.js working. There is lot of versions of node.js packages and extensions what worst on each website there is many working solution but only one helped me. I have downloaded lot of different node.js versions before I have found one which was working.

Another problem you could experience will be npm version or other extensions. Unfortunately npm compiler sometimes is too old and doesn’t recognize new types (e.g. uint8) used in source code of latest extensions. Also there are libraries which was developed basing on already stale extensions. So if you want to use them you need to find right version of extension and hopefully it will not crash another library.

But on the end I have done it and I have found working combo of each tool with February version of Raspbian. And I have created first working version of node.js application which simply sends hello command to ESP6288. Last thing which worried me. There is ESP6288 extension for node.js but I haven’t manage to run it. I have solve couple problems but still it doesn’t work.

So what are my first feelings. Preparing whole environment for node.js took me almost two days. Of course it was weekend and we had lot of other stuff to do during week we are just to busy to do all things but I think good 8 hours I have spend on everything including installation of couple different OS.

As for a conclusion about different OS I would say that raspbian is best one for me. Ubuntu mate takes too much processor power, lite versions doesn’t includes some of packages you will need. I have also tried windows 10 IoT. An as everyday C# developer I could say that I felt there like in home but it has it’s limitation. As for example it has problem with reading temperature signal from DS18B20 and you need converter for it (google).

 

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek