Click here to Skip to main content
14,035,995 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

18.7K views
16 bookmarked
Posted 5 Mar 2015
Licenced CPOL

Connecting IoT devices to an Azure web service using $3 WiFi modules

Rate this:
Please Sign up or sign in to vote.
One of the biggest problems in making simple devices into IoT devices is cost. The ESP-8266 module solves that problem.

This article is an entry in our Microsoft Azure IoT Contest. Articles in this section are not required to be full articles so care should be taken when voting.

Introduction

One of the biggest problems in making simple devices into IoT devices is cost. The ESP-8266 module solves that problem. Connecting numerous devices with Arduino, Netduino or Raspberry Pi units can easily run into hundreds of dollars. Those devices are also power hungry and adding to that the cost of cabling makes those solutions less attractive. For the minimal cost of about $3 each, the ESP-8266 modules you get the benefits of simplicity, WiFi connectivity and compact size of less than one-inch square.

ESP-8266-01 module

Background

The software stack is open source and utilizes the installable Lua programming language interpreter from NodeMCU. Utilities for uploading programs include the LuaLoader and LuaUploader applications. Lua and Python have many similarities. The ESP-8266 can be a WiFi Access Point, Client or both. This makes it ideal for IoT implementations. It has a 32bit microprocessor as well as the built-in WiFi stack. The basic model has two General Purpose I/O pins and serial data in and out. It's a 3.3 volt device so it could be run from a single 3.3v Lithium Ion battery or a pair of conventional 1.5v batteries, even rechargeable ones.

Using the code

To install the Lua interpreter and to upload programs, a 3.3v compatible USB to serial adapter is required. Most USB adapters are limited to 100ma supply current, so a 5v to 3.3v regulator or battery pack are needed in additional to the USB adapter when transmitting. Once programmed, the USB adapter is not needed. There is a file that the user creates named init.lua that the device loads automatically on boot-up or reset and can be the complete client solution. This file can also load a secondary file that contains other program code. The file init.lua is convenient to make the initial WiFi connection..

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
ip = wifi.sta.getip()

To conect to your website:

conn=net.createConnection(net.TCP) 
conn:dns("mywebsite.com",function(conn,ip) 
print(ip) 
conn:connect(80,ip)
conn:send("GET / HTTP/1.1\r\nHost: mywebsite.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") 
end) 
 
conn:on("receive",function(conn,payload)
  print (payload)  
end)

Programming to the I/O pins is quite simple in Lua. It's easy to set a pin for input or output, set its state, or leave floating. There are also several models of the ESP-8266. Some have a printed-circuit trace for the antenna, some use a chip antenna, and some an external antenna. WiFi range is very good with all models. Some of the models have more I/O pins and even analog-to-digital and pulse-width-modulation capability. A few companies make development boards with LEDs or photocell sensors.

The Azure Solution

Each ESP-8266 will send it's data over HTTP to the Azure web service which will store the data in a database. The database then can be queried for any and all data for visual status, charting or other analysis. Parameters such as on/off or light level are just a few of the many possibilities.

Other Ideas

Finally, if an Arduino based solution is still desired, the stock ESP-8266 can be used as the WiFi link with serial data exchanged with the Arduino using AT commands.

Finally

If the ESP-8266 gets stuck in an endless loop and a reset fails to fix it, the firmware can be reinstalled using the NodeMCUFlasher application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tom Corbett Space Cadet
President
United States United States
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
QuestionCode to connect to Azure Storage Pin
stardustJerry1-Jun-16 19:10
memberstardustJerry1-Jun-16 19:10 
AdminThanks for entering! Pin
Kevin Priddle19-Mar-15 9:44
professionalKevin Priddle19-Mar-15 9:44 
GeneralRe: Thanks for entering! Pin
Nelek19-Apr-15 11:59
protectorNelek19-Apr-15 11:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190424.1 | Last Updated 5 Mar 2015
Article Copyright 2015 by Tom Corbett Space Cadet
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid