|
在网上买的esp8266-01s模块和继电器模块,usb转ttl家里本来就有的,买了5块01s和三个继电器模块,用arduino刷的都是一样的blinker程序 只有一个01s模块能连上路由器和手机,其他的都不能连上路由器,手机上也是显示离线,但是程序是刷成功了,用本地io2接gnd继电器是会动作的,就是连不上网,我不懂这些编程,希望各位大神能指教一下,下面是我在网上找的程序和arduino显示的数据,大神帮忙看一下哪里不对。
[md]#define BLINKER_WIFI //官方wifi协议库
#define BLINKER_ESP_SMARTCONFIG // 进行配网
#define BLINKER_MIOT_LIGHT //小爱灯类库
#define BLINKER_PRINT Serial //串口协议库
#include <Blinker.h> //官方库
char auth[] = "1b14cdad6e26"; //设备key号
//char ssid[] = "TPlink"; //wifi名称
//char pswd[] = "12345678"; //wifi密码
bool oState = false;
int kg=0;//继电器输出
int kg2=2;//本地轻触开关,io2与gnd接时动作
//*******新建组件对象
BlinkerButton Button1("a1"); //设置app按键的键名
BlinkerButton Button2("a2");
BlinkerButton Button3("a3");
//*******app上按下按键即会执行该函数app里按键有2种模式3钟不同样式,下面写出所有的开关状态。
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state)
{
BLINKER_LOG("app操作了!: ", state); //串口打印
if (digitalRead(kg)==LOW) { //如果state是on状态
BLINKER_LOG("亮灯!"); //串口打印
}
else if (digitalRead(kg)==HIGH) { //如果state是off状态
BLINKER_LOG("灭灯!"); //串口打印
}
}
void button2_callback(const String & state)
{
digitalWrite(kg,LOW); //如果state是on状态
BLINKER_LOG("get button state:on", state);
Button1.color("#0000FF"); //设置app按键是蓝色
Button1.text("亮");
Button1.print("On"); //反馈回按键状态是开
}
void button3_callback(const String & state) //点灯app内控制按键触发
{
digitalWrite(kg,HIGH); //如果state是off状态
BLINKER_LOG("get button state:off", state);
Button1.color("#000000"); //设置app按键是黑色
Button1.text("灭");
Button1.print("off"); //反馈回按键状态是关
}
//*******如果天猫有对设备进行操作就执行下面
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state); //串口打印
if (state == BLINKER_CMD_ON){
digitalWrite(kg,LOW);
BlinkerMIOT.powerState("on");
BLINKER_LOG("亮灯!");
Button1.color("#0000FF"); //设置app按键是蓝色
Button1.text("亮");
Button1.print("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF){
digitalWrite(kg,HIGH);
BlinkerMIOT.powerState("off");
BLINKER_LOG("灭灯!");
Button1.color("#000000"); //设置app按键是黑色
Button1.text("灭");
Button1.print("off");
BlinkerMIOT.print();
oState = false;
}
}
void miotQuery(int32_t queryCode)
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
}
}
//*******app定时向设备发送心跳包, 设备收到心跳包后会返回设备当前状态30s~60s一次
void heartbeat()
{
BLINKER_LOG("状态同步!");
if (digitalRead(kg)==LOW)
{
Button1.print("on");
Button1.color("#0000FF"); //设置app按键是蓝色
Button1.text("亮");
}
else
{
Button1.print("off");
Button1.color("#000000"); //设置app按键是黑色
Button1.text("灭");
}
}
///如果本地开关有动作执行下面手动模式
void sdms(){
if (digitalRead(kg)==HIGH&&digitalRead(kg2)==LOW) { //
Blinker.delay(150); //延时150ms不能太少标准按键成功率
if (digitalRead(kg2)==HIGH){
BLINKER_LOG("亮灯!"); //串口打印
digitalWrite(kg,LOW);
Button1.color("#0000FF"); //设置app按键是蓝色
Button1.text("亮");
Button1.print("on");
}
}
if (digitalRead(kg)==LOW&&digitalRead(kg2)==LOW) {
Blinker.delay(150);
if (digitalRead(kg2)==HIGH){
BLINKER_LOG("灭灯!"); //串口打印
digitalWrite(kg, HIGH);
Button1.color("#000000"); //设置app按键是黑色
Button1.text("灭");
Button1.print("off");
}
}
}
void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(kg, OUTPUT);
digitalWrite(kg, LOW); //默认上电是开 LOW 时的是接通继电器。
pinMode(kg2,INPUT_PULLUP); //输入上拉
// 初始化blinker
Blinker.begin(auth);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);//app上操作必须的注册回调函数关联按键名“Button1”和判断程序“button1_callback"
BlinkerMIOT.attachPowerState(miotPowerState);
Blinker.attachHeartbeat(heartbeat); //app定时向设备发送心跳包, 设备收到心跳包后会返回设备当前状态进行语音操作和app操作同步。
}
void loop() {
sdms();//本地开关手动模式函数
Blinker.run();
}[/md]
下面是arduino显示的数据
Executable segment sizes:
IROM : 500216 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 28948 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1376 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 8172 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 30032 ) - zeroed variables (global, static) in RAM/HEAP
项目使用了 538712 字节,占用了 (56%) 程序存储空间。最大为 958448 字节。
全局变量使用了39580字节,(48%)的动态内存,余留42340字节局部变量。最大为81920字节。
esptool.py v2.8
Serial port COM3
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: f4:cf:a2:72:48:44
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 1MB
Compressed 542864 bytes to 383235...
Writing at 0x00000000... (4 %)
Writing at 0x00004000... (8 %)
Writing at 0x00008000... (12 %)
Writing at 0x0000c000... (16 %)
Writing at 0x00010000... (20 %)
Writing at 0x00014000... (25 %)
Writing at 0x00018000... (29 %)
Writing at 0x0001c000... (33 %)
Writing at 0x00020000... (37 %)
Writing at 0x00024000... (41 %)
Writing at 0x00028000... (45 %)
Writing at 0x0002c000... (50 %)
Writing at 0x00030000... (54 %)
Writing at 0x00034000... (58 %)
Writing at 0x00038000... (62 %)
Writing at 0x0003c000... (66 %)
Writing at 0x00040000... (70 %)
Writing at 0x00044000... (75 %)
Writing at 0x00048000... (79 %)
Writing at 0x0004c000... (83 %)
Writing at 0x00050000... (87 %)
Writing at 0x00054000... (91 %)
Writing at 0x00058000... (95 %)
Writing at 0x0005c000... (100 %)
Wrote 542864 bytes (383235 compressed) at 0x00000000 in 33.7 seconds (effective 128.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
就只有一个模块能连上网手机也显示在线,其他的都连不上网,程序是一样的啊,实在想不通啊 |
|