完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
init.lua
wifi.setmode(wifi.STAtiON) wifi.sta.config("SSID","password") 打印(wifi.sta.getip()) tmr.alarm(0, 60000, 1, function() dofile( "speak.lua") end ) speak.lua conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) conn:connect(80,' 184.106.153.149') conn:send("GET /update?key=yourKEY&field1=16 HTTP/1.1\r\n") conn:send("Host: api.thingspeak.com\r\n") conn:send( "接受:*/*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") conn: send("\r\n" ) 从 BS18B20 发送温度到 thingspeak.com speak.lua pin = 9 ow.setup(pin) count = 0 repeat count = count + 1 addr = ow.reset_search(pin) addr = ow.search(pin) tmr.wdclr() until((addr ~= nil) or (count > 100)) if (addr == nil) then print("No more addresses.") else print(addr:byte(1,8)) crc = ow.crc8( string.sub(addr,1,7)) if (crc == addr:byte(8)) then if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28))然后 print("Device is a DS18S20 family device.") --repeat ow.reset(pin) ow.select(pin, addr) ow.write(pin, 0x44, 1) tmr.delay(1000000) present = ow.reset(pin) ow.select(pin, addr) ow.write(pin,0xBE,1) print("P=".. present) data = nil data = string.char(ow.read(pin)) for i = 1, 8 do data = data .. string.char(ow.read(pin)) end print(data:byte(1, 9)) crc = ow.crc8(string.sub(data,1,8)) print("CRC="..crc) if (crc == data:byte(9)) then t = (data:byte( 1) + 数据:字节 (2) * 256) * 625 t1 = t / 1000 t2 = t % 1000 print("Temperature= "..t1..""..t2.." Centigrade") end tmr.wdclr() --until false else print("设备系列未被识别。") end else print(" CRC 无效!”) end end conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) conn:connect(80,'184.106. 153.149') conn:send("GET /update?key=Yourey&field1="..t1..""..t2.." HTTP/1.1\r\n") conn:send("Host: api.thingspeak .com\r\n") conn:send("接受: */*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") 连接:发送(“\r\n”) |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
920 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
446浏览 5评论
447浏览 4评论
417浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 23:43 , Processed in 0.804333 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号