Wednesday, September 30, 2015

ESP8266 or Arduino

I started off thinking of adding one of these to my ArduinoRainStation. So I started looking into writing some Arduino code to use the AT commands in the of the shelf firmware.This was going ok, apart from all of commands are required just to set the ESP8266 up and there is an overhead to send back and forth any data. Each data exchange you have to sit waiting for something like this,
+IPD,0,5: hello
which is 5 bytes of data on port 0.
then to send hello back,
AT+CIPSEND=0,5
then wait for '>' and send 'hello'
then you can go back waiting for +IPD again
and to make it a little more complicated you sometimes get,
+IPD,0,5: hello
+IPD,0,2: \r\n

Depending on which telnet client your using. The stuff that browsers spit out is much more irregular.
Also can be very big bigger than the serial buffer in a little Arduino.

At this point I started to look at native code.

There are a number routes from native SDKs to scripting in LUA. Both had a learning curve for myself. After a bit of a Google  I found something a little more in fitting with the rest of my project. esp8266 with Arduino IDE and it is just like it.

I'm not going to go into the ins and outs of installing and setting up as there are plenty of blog post. The github README.md was good enough for me to install on windows10 and Ubuntu. What I want to show how simple it is to get a simple WIFI device going. See the code at esp-AP.ino which is a copy from the library examples, WiFiAccessPoint.ino tweaked to my needs.

Like with all Arduino code there is a void setup() and void loop(). The void loop()  runs a server.handleClient(); which calls a handleRoot()  call back function when it gets a HTTP connection. This leaves me free to deal with what I want to send as my messages. No long streams of AT commands.

Next steps are:
  1. To write code to fetch sensor data from an Arduino and send to browser.
  2. Read the browser request maybe switch Led on?

No comments:

Post a Comment