--some functions
dofile("functions.lua")
lighton1=
lighton2=
lighton3=
lighton4= pin1 =
pin2 =
pin3 =
pin4 =
gpio.mode(pin1,gpio.OUTPUT)
gpio.mode(pin2,gpio.OUTPUT)
gpio.mode(pin3,gpio.OUTPUT)
gpio.mode(pin4,gpio.OUTPUT) --pin1
tmr.alarm(,,,function()
if lighton1== then
lighton1=
gpio.write(pin1,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton1=
gpio.write(pin1,gpio.HIGH)
end
end)
--pin2
tmr.alarm(,,,function()
if lighton2== then
lighton2=
gpio.write(pin2,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton2=
gpio.write(pin2,gpio.HIGH)
end
end)
--pin3
tmr.alarm(,,,function()
if lighton3== then
lighton3=
gpio.write(pin3,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton3=
gpio.write(pin3,gpio.HIGH)
end
end)
--pin4
tmr.alarm(,,,function()
if lighton4== then
lighton4=
gpio.write(pin4,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton4=
gpio.write(pin4,gpio.HIGH)
end
end)
dofile("sjson.lua")
--inti.lua
--sjson.lua
name = "lxx"
print("Hello world!")
print(name .. ",nihao!")
--functions.lua
function startup()
if file.open("init.lua") == nil then
print("init.lua deleted or renamed")
else
print("Running")
file.close("init.lua")
-- the actual application is stored in 'application.lua'
-- dofile("application.lua")
end
end -- Define WiFi station event callbacks
wifi_connect_event = function(T)
print("Connection to AP("..T.SSID..") established!")
print("Waiting for IP address...")
if disconnect_ct ~= nil then disconnect_ct = nil end
end wifi_got_ip_event = function(T)
-- Note: Having an IP address does not mean there is internet access!
-- Internet connectivity can be determined with net.dns.resolve().
print("Wifi connection is ready! IP address is: "..T.IP)
print("Startup will resume momentarily, you have 3 seconds to abort.")
print("Waiting...")
tmr.create():alarm(, tmr.ALARM_SINGLE, startup)
end wifi_disconnect_event = function(T)
if T.reason == wifi.eventmon.reason.ASSOC_LEAVE then
--the station has disassociated from a previously connected AP
return
end
-- total_tries: how many times the station will attempt to connect to the AP. Should consider AP reboot duration.
local total_tries =
print("\nWiFi connection to AP("..T.SSID..") has failed!") --There are many possible disconnect reasons, the following iterates through
--the list and returns the string corresponding to the disconnect reason.
for key,val in pairs(wifi.eventmon.reason) do
if val == T.reason then
print("Disconnect reason: "..val.."("..key..")")
break
end
end if disconnect_ct == nil then
disconnect_ct =
else
disconnect_ct = disconnect_ct +
end
if disconnect_ct < total_tries then
print("Retrying connection...(attempt "..(disconnect_ct+).." of "..total_tries..")")
else
wifi.sta.disconnect()
print("Aborting connection to AP!")
disconnect_ct = nil
end
end

ESP8266 的几个代码 加深对LUA的理解的更多相关文章

  1. 8天入门docker系列 —— 第二天 通过一个aspnetcore程序加深对容器的理解

    我们知道容器是一个打包了应用和相关依赖的盒子,那怎么去操控这个盒子呢? 这一篇我通过一个简单的aspnetcore程序来加深对盒子的理解,使用之前先 安装一下Docker的环境. 一:Docker的安 ...

  2. ESP8266开发综合篇第十四节(LUA)-8266作为TCP服务器,Android客户端连接,显示温湿度,控制继电器

    前几节先略过,我先补充上大部分人迫切的需求 编写Android TCP客户端  用Android Studio 先做一下界面 然后放一个输入对话框,因为没有显示出来这个控件.所以就手写 剩下的自己研究 ...

  3. cocos2dx 3.x c++代码打包给lua调用过程(mac)

    下载cocos2dx 框架,在应用程序->cocos->framework->cocos2d-x-3.x->tools->tolua目录下,一个ini文件对应一个py文件 ...

  4. Java中静态代码块,代码块,构造方法的理解

    直接贴代码 class A { static { System.out.println("父类静态代码区"); } { System.out.println("父类代码区 ...

  5. java面向对象(封装-继承-多态)

    框架图 理解面向对象 面向对象是相对面向过程而言 面向对象和面向过程都是一种思想 面向过程强调的是功能行为 面向对象将功能封装进对象,强调具备了功能的对象. 面向对象是基于面向过程的. 面向对象的特点 ...

  6. 适合初学者的嵌入式Linux计划

    俗话说万事开头难,刚开始的时候,你是否根本就不知如何开始,上网查资料被一堆堆新名词搞的找不到北,去图书馆看书也是找不到方向?又是arm,又是linux,又是uboot头都大了,不知道自己究竟从哪里开始 ...

  7. Python基础入门(6)- 面向对象编程

    1.初识面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本篇随笔将详细介绍Python的面向对象编程. 如果你以前没有接触过面向对象 ...

  8. 5道面试题,拿捏String底层原理!

    原创:微信公众号 码农参上,欢迎分享,转载请保留出处. String字符串是我们日常工作中常用的一个类,在面试中也是高频考点,这里Hydra精心总结了一波常见但也有点烧脑的String面试题,一共5道 ...

  9. Lua 学习笔记(七)编译、执行外部代码块

    Lua称为解释型语言的原因:Lua允许在运行源代码之前,先将源代码预编译为一种中间形式.区别解释型语言的主要特征是在于编译器是否是语言运行时库的一部分,即有能力执行动态生成的代码.因为Lua中有dof ...

随机推荐

  1. (原)ubuntu中使用conda安装tensorflow-gpu

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9834567.html 参考网址: https://www.anaconda.com/blog/dev ...

  2. 设置Linux交换分区

    Linux下可以创建两种类型的交换空间,一种是swap分区,一种是swap文件.前者适合有空闲的分区可以使用,后者适合于没有空的硬盘分区,硬盘的空间都已经分配完毕.例如:安装redhat的时候,你可以 ...

  3. spring-mybatis-data-common程序级分表操作实例

    spring-mybatis-data-common-2.0新增分表机制,在1.0基础上做了部分调整. 基于机架展示分库应用数据库分表实力创建 create table tb_example_1( i ...

  4. linux nfs共享文件

    linux文件共享可以有多种方式:samba,nfs,ftp等等 nfs在linux之间效率高些: function nfs(){ share_folder="/data1 192.168. ...

  5. 解决ScrollView嵌套RecyclerView出现item显示不全的问题

      问题:ScrollView嵌套RecyclerView时,RecyclerView的item显示不全 出现问题不要慌,耐心解决才是王道,哈哈.首先说下出现这个问题的情景吧,首先声明这个问题在23版 ...

  6. nginx与apache的参考配置

    nginx与apache是两大最主流的服务器,功能强大,但配置起来也比较麻烦,对于初学者来讲可能有些地方并不完全清楚其作用,这里搜集了一些配置的作用及其使用方法.其中nginx提供了推荐配置,而apa ...

  7. CS页面-Asp.net+Spring.Net.Framework--SNF快速开发平台3.0

    SNF快速平台有BS和CS两种,之前介绍了BS界面,下面发几张图看一下CS界面看看是什么样的 这是SNF快速开发平台的CS框架 1.有多种主页和登录页面. 2.多种页面风格 下面就先先看看页面显示的效 ...

  8. 7-6-有向图强连通分量的Kosaraju算法-图-第7章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第7章  图 - 有向图强连通分量的Kosaraju算法 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ <数据结构-C语言版>(严 ...

  9. Java 汇编代码

    https://shipilev.net/blog/2015/black-magic-method-dispatch/ https://github.com/shipilev/article-meth ...

  10. 【IOS】java 与oc之间的比较

    Cocoa是什么,Cocoa是使用OC语言编写的工具包,里面有大量的类库.结构体,其实就相当于java中的标准API.C++中的标准库.OC中没有命名空间的概念,所以使用加前缀来防止命名冲突,因此你会 ...