三种智能灯和mqtt实验
光控灯
在mind+和掌控板上实现天黑自动亮灯,天亮灭灯。
当环境光照强度大于300灯灭,否则灯亮起白色。
声控灯
在mind+和掌控板上实现声音强度到一定程度自动亮度,否则灭灯
当环境声音强度大于300亮起白色灯提示,否则保持熄灭状态。
语音识别控制灯
在mind+和掌控板上实现语音控制灯的开关
需要用到wifi模块。当对掌控模块说“开灯”,灯亮起,说“关灯”则熄灭
实现Easy IoT上mqtt消息的通讯
在mind+和掌控板上实现mind+下Easy IoT上mqtt消息的通讯
甲按A键(或触摸P)发送消息至topic1,同时监听topic0
乙监听topic1,接收到甲的消息后按A(或触摸P)回复消息给topic0甲显示
在这里插入代码片
// 主程序开始
void setup() {
mPython.begin();
myIot.setMqttCallback(msgHandles);
myIot.wifiConnect(“xiaomi”, “987654321”);
display.setCursorLine(1);
display.printLine(“正在连接网络”);
if (myIot.wifiStatus()) {
display.fillInLine(1, 0);
display.setCursorLine(1);
display.printLine(“连接成功”);
display.fillInLine(1, 0);
}
myIot.init(“iot.dfrobot.com.cn”,“Y9qNBjOMR”,"",“Yr3HfjOGRz”,topics,1883);
myIot.connect();
delay(5000);
if (myIot.connected()) {
display.setCursorLine(1);
display.printLine(“连接成功”);
delay(1000);
display.fillInLine(1, 0);
}
}
void loop() {
if ((buttonA.isPressed())) {
myIot.publish(topic_1, “hello”);
display.setCursorLine(2);
display.printLine(“发送成功”);
}
}
// 事件回调函数
void obloqMqttEventT0(String& message) {
display.setCursorLine(3);
display.printLine(message);
delay(2000);
}