├── Eagle-CAD ├── README.md └── #ESP8266.lbr ├── ESP-01-board ├── esp01-test.jpg ├── esp01-test-pcb.png └── esp01-test-sch.png ├── Thermometer-DS18B20-Thingspeak ├── esp8266-ds18b20-2_bb.png ├── init.lua ├── README.md └── ds1820.lua ├── Thingspeak-Tweet ├── README.md └── tweet.lua ├── Thermometer-DHT11-Thingspeak ├── README.md ├── init.lua └── dht11.lua └── README.md /Eagle-CAD/README.md: -------------------------------------------------------------------------------- 1 | Eagle-CAD 2 | ========= 3 | 4 | Eagle library, currently only ESP-01, ESP-03 5 | -------------------------------------------------------------------------------- /ESP-01-board/esp01-test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/HEAD/ESP-01-board/esp01-test.jpg -------------------------------------------------------------------------------- /ESP-01-board/esp01-test-pcb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/HEAD/ESP-01-board/esp01-test-pcb.png -------------------------------------------------------------------------------- /ESP-01-board/esp01-test-sch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/HEAD/ESP-01-board/esp01-test-sch.png -------------------------------------------------------------------------------- /Thermometer-DS18B20-Thingspeak/esp8266-ds18b20-2_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/HEAD/Thermometer-DS18B20-Thingspeak/esp8266-ds18b20-2_bb.png -------------------------------------------------------------------------------- /Thingspeak-Tweet/README.md: -------------------------------------------------------------------------------- 1 | Thingspeak-Tweet 2 | ================ 3 | Example how to send tweet directly from ESP8266 with nodeMCU firmware. 4 | 5 | The code using Thingspeak.com API to send tweet beacouse is not easy implement OAuth directly in ESP8266. 6 | 7 | Link your twitter account in thingspeak.com and change you thingtweetAPIKey. 8 | 9 | 10 | -------------------------------------------------------------------------------- /Thermometer-DHT11-Thingspeak/README.md: -------------------------------------------------------------------------------- 1 | Measure temperature and humidity with cheap DHT11 sensor and post data to thingspeak.com 2 | ========================================================================== 3 | 4 | init.lua - set up WIFI station and wait for ip then do ds1820.lua 5 | 6 | dht11.lua - get data from DHT11 sensor and post them to Thinkspeak.com 7 | 8 | 9 | 10 | Please remember change your thingspeak API key and WIFI settings... 11 | -------------------------------------------------------------------------------- /Thermometer-DS18B20-Thingspeak/init.lua: -------------------------------------------------------------------------------- 1 | --init.lua 2 | print("Setting up WIFI...") 3 | wifi.setmode(wifi.STATION) 4 | --modify according your wireless router settings 5 | wifi.sta.config("SSID","PASSWORD") 6 | wifi.sta.connect() 7 | tmr.alarm(1, 1000, 1, function() 8 | if wifi.sta.getip()== nil then 9 | print("IP unavaiable, Waiting...") 10 | else 11 | tmr.stop(1) 12 | print("Config done, IP is "..wifi.sta.getip()) 13 | dofile("ds1820.lua") 14 | end 15 | end) 16 | 17 | -------------------------------------------------------------------------------- /Thermometer-DHT11-Thingspeak/init.lua: -------------------------------------------------------------------------------- 1 | --init.lua 2 | print("Setting up WIFI...") 3 | wifi.setmode(wifi.STATION) 4 | --modify according your wireless router settings 5 | wifi.sta.config("SSID","PASSWORD") 6 | wifi.sta.connect() 7 | tmr.alarm(1, 1000, 1, function() 8 | if wifi.sta.getip()== nil then 9 | print("IP unavaiable, Waiting...") 10 | else 11 | tmr.stop(1) 12 | print("Config done, IP is "..wifi.sta.getip()) 13 | dofile("dht11.lua") 14 | end 15 | end) 16 | 17 | 18 | -------------------------------------------------------------------------------- /Thermometer-DS18B20-Thingspeak/README.md: -------------------------------------------------------------------------------- 1 | Measure temperature with DS18B20 sensor and post data to thingspeak.com 2 | ========================================================================== 3 | 4 | init.lua - set up WIFI station and wait for ip then do ds1820.lua 5 | 6 | ds1820.lua - get data from DS18B20 sensor and post them to Thinkspeak.com 7 | 8 | 9 | Please remember change your thingspeak API key and WIFI settings... 10 | 11 | ![Schematic](https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/master/Thermometer-DS18B20-Thingspeak/esp8266-ds18b20-2_bb.png) 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ESP8266-LUA 2 | =========== 3 | 4 | LUA scripts for ESP8266 with NodeMCU firmware 5 | 6 | **Thermometer-DS18B20-Thingspeak** - measure temperature with DS18B20 sensor and post data to thingspeak.com 7 | 8 | **Thermometer-DHT11-Thingspeak** - measure temperature and humidity with cheap DHT11 sensor and post data to thingspeak.com 9 | 10 | **Thingspeak-Tweet** - example ho to send tweet using thingspeak.com API. 11 | 12 | **Eagle-CAD** - Eagle library, currently only ESP-01, ESP-03 13 | 14 | **ESP-01-board** - Universal board for ESP-01 (contains EAGLE files) 15 | 16 | ![ESP-01-board](https://raw.githubusercontent.com/ok1cdj/ESP8266-LUA/master/ESP-01-board/esp01-test.jpg) 17 | 18 | -------------------------------------------------------------------------------- /Thingspeak-Tweet/tweet.lua: -------------------------------------------------------------------------------- 1 | -- Example how to send tweet directly from ESP8266 with nodeMCU fw 2 | -- 2015 ok1cdj 3 | thingtweetAPIKey = "XXXXXXXX" 4 | status = "First tweet from #ESP8266.. @ok1cdj" 5 | 6 | function urlencode(str) 7 | if (str) then 8 | str = string.gsub (str, "\n", "\r\n") 9 | str = string.gsub (str, "([^%w ])", 10 | function (c) return string.format ("%%%02X", string.byte(c)) end) 11 | str = string.gsub (str, " ", "+") 12 | end 13 | return str 14 | end 15 | 16 | print("Sending tweet...") 17 | conn=net.createConnection(net.TCP, 0) 18 | conn:on("receive", function(conn, payload) print(payload) end) 19 | conn:connect(80,'184.106.153.149') 20 | conn:send("GET /apps/thingtweet/1/statuses/update?key="..thingtweetAPIKey.."&status="..urlencode(status).." HTTP/1.1\r\n") 21 | conn:send("Host: api.thingspeak.com\r\n") 22 | conn:send("Accept: */*\r\n") 23 | conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") 24 | conn:send("\r\n") 25 | conn:on("disconnection", function(conn) 26 | print("Got disconnection...") 27 | end) 28 | 29 | -------------------------------------------------------------------------------- /Thermometer-DS18B20-Thingspeak/ds1820.lua: -------------------------------------------------------------------------------- 1 | -- Measure temperature and post data to thingspeak.com 2 | -- 2014 OK1CDJ 3 | --- Tem sensor DS18B20 is conntected to GPIO0 4 | --- 2015.01.21 sza2 temperature value concatenation bug correction 5 | 6 | pin = 3 7 | ow.setup(pin) 8 | 9 | counter=0 10 | lasttemp=-999 11 | 12 | function bxor(a,b) 13 | local r = 0 14 | for i = 0, 31 do 15 | if ( a % 2 + b % 2 == 1 ) then 16 | r = r + 2^i 17 | end 18 | a = a / 2 19 | b = b / 2 20 | end 21 | return r 22 | end 23 | 24 | --- Get temperature from DS18B20 25 | function getTemp() 26 | addr = ow.reset_search(pin) 27 | repeat 28 | tmr.wdclr() 29 | 30 | if (addr ~= nil) then 31 | crc = ow.crc8(string.sub(addr,1,7)) 32 | if (crc == addr:byte(8)) then 33 | if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then 34 | ow.reset(pin) 35 | ow.select(pin, addr) 36 | ow.write(pin, 0x44, 1) 37 | tmr.delay(1000000) 38 | present = ow.reset(pin) 39 | ow.select(pin, addr) 40 | ow.write(pin,0xBE, 1) 41 | data = nil 42 | data = string.char(ow.read(pin)) 43 | for i = 1, 8 do 44 | data = data .. string.char(ow.read(pin)) 45 | end 46 | crc = ow.crc8(string.sub(data,1,8)) 47 | if (crc == data:byte(9)) then 48 | t = (data:byte(1) + data:byte(2) * 256) 49 | if (t > 32768) then 50 | t = (bxor(t, 0xffff)) + 1 51 | t = (-1) * t 52 | end 53 | t = t * 625 54 | lasttemp = t 55 | print("Last temp: " .. lasttemp) 56 | end 57 | tmr.wdclr() 58 | end 59 | end 60 | end 61 | addr = ow.search(pin) 62 | until(addr == nil) 63 | end 64 | 65 | --- Get temp and send data to thingspeak.com 66 | function sendData() 67 | getTemp() 68 | t1 = lasttemp / 10000 69 | t2 = (lasttemp >= 0 and lasttemp % 10000) or (10000 - lasttemp % 10000) 70 | print("Temp:"..t1 .. "."..string.format("%04d", t2).." C\n") 71 | -- conection to thingspeak.com 72 | print("Sending data to thingspeak.com") 73 | conn=net.createConnection(net.TCP, 0) 74 | conn:on("receive", function(conn, payload) print(payload) end) 75 | -- api.thingspeak.com 184.106.153.149 76 | conn:connect(80,'184.106.153.149') 77 | conn:send("GET /update?key=YOURKEY&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1\r\n") 78 | conn:send("Host: api.thingspeak.com\r\n") 79 | conn:send("Accept: */*\r\n") 80 | conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") 81 | conn:send("\r\n") 82 | conn:on("sent",function(conn) 83 | print("Closing connection") 84 | conn:close() 85 | end) 86 | conn:on("disconnection", function(conn) 87 | print("Got disconnection...") 88 | end) 89 | end 90 | 91 | -- send data every X ms to thing speak 92 | tmr.alarm(0, 60000, 1, function() sendData() end ) 93 | -------------------------------------------------------------------------------- /Thermometer-DHT11-Thingspeak/dht11.lua: -------------------------------------------------------------------------------- 1 | -- Measure temperature, humidity and post data to thingspeak.com 2 | -- 2014 OK1CDJ 3 | -- DHT11 code is from esp8266.com 4 | ---Sensor DHT11 is conntected to GPIO0 5 | pin = 3 6 | -- GPIO0 = 3 GPIO2 = 4 7 | 8 | Humidity = 0 9 | HumidityDec=0 10 | Temperature = 0 11 | TemperatureDec=0 12 | Checksum = 0 13 | ChecksumTest=0 14 | 15 | 16 | function getTemp() 17 | Humidity = 0 18 | HumidityDec=0 19 | Temperature = 0 20 | TemperatureDec=0 21 | Checksum = 0 22 | ChecksumTest=0 23 | 24 | --Data stream acquisition timing is critical. There's 25 | --barely enough speed to work with to make this happen. 26 | --Pre-allocate vars used in loop. 27 | 28 | bitStream = {} 29 | for j = 1, 40, 1 do 30 | bitStream[j]=0 31 | end 32 | bitlength=0 33 | 34 | gpio.mode(pin, gpio.OUTPUT) 35 | gpio.write(pin, gpio.LOW) 36 | tmr.delay(20000) 37 | --Use Markus Gritsch trick to speed up read/write on GPIO 38 | gpio_read=gpio.read 39 | gpio_write=gpio.write 40 | 41 | gpio.mode(pin, gpio.INPUT) 42 | 43 | --bus will always let up eventually, don't bother with timeout 44 | while (gpio_read(pin)==0 ) do end 45 | 46 | c=0 47 | while (gpio_read(pin)==1 and c<100) do c=c+1 end 48 | 49 | --bus will always let up eventually, don't bother with timeout 50 | while (gpio_read(pin)==0 ) do end 51 | 52 | c=0 53 | while (gpio_read(pin)==1 and c<100) do c=c+1 end 54 | 55 | --acquisition loop 56 | for j = 1, 40, 1 do 57 | while (gpio_read(pin)==1 and bitlength<10 ) do 58 | bitlength=bitlength+1 59 | end 60 | bitStream[j]=bitlength 61 | bitlength=0 62 | --bus will always let up eventually, don't bother with timeout 63 | while (gpio_read(pin)==0) do end 64 | end 65 | 66 | --DHT data acquired, process. 67 | 68 | for i = 1, 8, 1 do 69 | if (bitStream[i+0] > 2) then 70 | Humidity = Humidity+2^(8-i) 71 | end 72 | end 73 | for i = 1, 8, 1 do 74 | if (bitStream[i+8] > 2) then 75 | HumidityDec = HumidityDec+2^(8-i) 76 | end 77 | end 78 | for i = 1, 8, 1 do 79 | if (bitStream[i+16] > 2) then 80 | Temperature = Temperature+2^(8-i) 81 | end 82 | end 83 | for i = 1, 8, 1 do 84 | if (bitStream[i+24] > 2) then 85 | TemperatureDec = TemperatureDec+2^(8-i) 86 | end 87 | end 88 | for i = 1, 8, 1 do 89 | if (bitStream[i+32] > 2) then 90 | Checksum = Checksum+2^(8-i) 91 | end 92 | end 93 | ChecksumTest=(Humidity+HumidityDec+Temperature+TemperatureDec) % 0xFF 94 | 95 | print ("Temperature: "..Temperature.."."..TemperatureDec) 96 | print ("Humidity: "..Humidity.."."..HumidityDec) 97 | print ("ChecksumReceived: "..Checksum) 98 | print ("ChecksumTest: "..ChecksumTest) 99 | end 100 | 101 | --- Get temp and send data to thingspeak.com 102 | function sendData() 103 | getTemp() 104 | -- conection to thingspeak.com 105 | print("Sending data to thingspeak.com") 106 | conn=net.createConnection(net.TCP, 0) 107 | conn:on("receive", function(conn, payload) print(payload) end) 108 | -- api.thingspeak.com 184.106.153.149 109 | conn:connect(80,'184.106.153.149') 110 | conn:send("GET /update?key=XXXXXXXXXX&field1="..Temperature.."."..TemperatureDec.."&field2="..Humidity.."."..HumidityDec.." HTTP/1.1\r\n") 111 | conn:send("Host: api.thingspeak.com\r\n") 112 | conn:send("Accept: */*\r\n") 113 | conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") 114 | conn:send("\r\n") 115 | conn:on("sent",function(conn) 116 | print("Closing connection") 117 | conn:close() 118 | end) 119 | conn:on("disconnection", function(conn) 120 | print("Got disconnection...") 121 | end) 122 | end 123 | -- send data every X ms to thing speak 124 | tmr.alarm(2, 60000, 1, function() sendData() end ) 125 | -------------------------------------------------------------------------------- /Eagle-CAD/#ESP8266.lbr: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | ESP8266 - ESP-01 Module 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | ESP8266 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | ESP8266 144 | 145 | 146 | 147 | 148 | ESP8266 - ESP-01 Module 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | ESP8266 - ESP-03 Module 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | --------------------------------------------------------------------------------