Wi-Fi thermometer on the ESP8266 + DS18B20 for only $ 4

Recently, Wi-Fi modules based on the ESP8266 are gaining more and more popularity. I also decided to join the beautiful, thinking of implementing a thermometer that sends data via HTTP. So let's go.
Hardware
ESP8266
Any of the modules from ESP-01 to ESP-11 will be suitable for theproject, I had ESP-03 (cost ~ $ 3): I

especially liked:
ESP-01 - convenient for prototyping (there is a connector for a breadboard), but only 1 GPIO is displayed ;
ESP-03 - many conclusions, plus a ceramic antenna;
ESP-07 - the same as ESP-03 + screen and connector for an external antenna.
DS18B20

As an option, you can already buy with a wire and in a sealed enclosure.
3.3V
power supply A power supply of at least 200mA is required.
USB-UART
For firmware and debugging. I used a converter based on CP2102
Connection
We connect power to the ESP8266. On foot CH_PD also serve plus.
Attention! Who does not have ESP-01 modules, it is necessary to apply GPIO15 - GND; GPIO2 -3.3V. ESP-01 has already done this . RX and TX to connect USB-UART converter flash and debug code:

Connect to the DS18B20 ESP8266. If you look at the markings: left - ground, middle - signal (GPIO12 on ESP-03), if you have ESP-01, connect to GPIO0, right - power (3.3V). Between the power and the signal line, it is desirable to connect a 4.7 kΩ resistor (it works with 10 kOhm for me):

thingspeak.com
We register on thingspeak.com, create a channel, copy the 16-character key from there. It is useful to us for sending temperature data to the cloud.
NodeMCU firmware
NodeMCU is a firmware that allows you to run Lua scripts on ESP8266. Download the latest NodeMCU Flasher and run it.
Connect GPIO0 to ground. We select the desired COM port and the speed is 74880 or 115200 (as I understand it, the bootloader works on 74880 on some versions of ESP8266). We press Flash and we distort food on ESP8266. If the firmware does not start, check the correctness of the RX, TX connection by launching PuTTY at a speed of 74880. At the moment of power-up, a line like " ets Jan 8 2013, rst cause: 1, boot mode: (1,0) " should fall into the console . After the correct firmware, disable GPIO0 from the ground:

Pouring Lua scripts and launch
Download and run LuaLoader . We select the COM port and speed 9600, if there is no connection, we try to distort the power of the ESP8266 module. We check the connection by clicking on the ChipID button . The identifier of the chip should be displayed in the console.
= node.chipid()
10371968
We fill in the necessary files (UploadFile button):
1. ds18b20.lua - library for interacting with DS18B20;
2. httpsender.lua - our script that reads temperature data and sends it to thingspeak.com. Do not forget to replace YOURAPIKEY on your key.
gpio = 6 - in the case of connecting the sensor to GPIO12, in the case of GPIO0 - gpio = 3 ( table ):
gpio = 6
require('ds18b20')
ds18b20.setup(gpio)
function sendData()
t=ds18b20.read()
print("Temp:"..t.." C\n")
-- conection to thingspeak.com
print("Sending data to thingspeak.com")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=YOURAPIKEY&field1="..t.." HTTP/1.1\r\n")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
end
-- send data every 60000 ms to thing speak
tmr.alarm(0, 60000, 1, function() sendData() end )
3. init.lua - a script that initializes WiFi and launches httpsender.lua. Do not forget to register your SSID and password for WiFi:
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
--modify according your wireless router settings
wifi.sta.config("SSID","SSIDPASSWD")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("httpsender.lua")
end
Total:

Plans
This is the first experience with the ESP8266. The plans to try the following:
1. Find an alternative thingspeak. Charts want to move and scale. Maybe someone knows the analogs?
2. Humidity sensor (possibly DHT22). It seems to already be in standard libraries.
3. CO2 sensor based on the K-30 sensor.
4. Controlled dawn without additional controller, control with ESP8266. The publication Artificial Dawn inspired .
Materials used
It is based on the text of «the Low cost WIFI area temperature (the DS18B20) data logger based on ESP8266 with connectivity applications to thingspeak.com» . For some reason, the code for DS18B20 refused to work; I had to switch to the standard library ds18b20.lua .