简体   繁体   English

使用 ESP8266 连接手机

[英]Connecting Mobile with ESP8266

I am working on a Home Automation project and I want to connect an Mobile Application to ESP8266.我正在从事家庭自动化项目,我想将移动应用程序连接到 ESP8266。

  • I can Publish a message from Mobile App to AWS server which is setup as a broker.我可以将消息从移动应用程序发布到设置为代理的 AWS 服务器。 (Working) (工作)

  • I can Publish a message from AWS to Raspberry PI.我可以将消息从 AWS 发布到 Raspberry PI。 (Working) (工作)

  • I can also Publish a Mqtt message from Raspberry PI to NodeMCU / ESP8266.我还可以将 Mqtt 消息从 Raspberry PI 发布到 NodeMCU / ESP8266。 (Working). (工作)。

But the problem occurs when I am trying to set all these together.但是当我尝试将所有这些设置在一起时会出现问题。 While Publishing a message from AWS it is received by Raspberry PI but it is not reflected on the NodeMCU / ESP8266.从 AWS 发布消息时,Raspberry PI 会收到该消息,但不会反映在 NodeMCU / ESP8266 上。

Here is the code in use .这是正在使用代码

This is what I am using in my ESP8266.这就是我在 ESP8266 中使用的。 When I Publish from Raspberry PI it is working fine, even when I am connecting PI will MQTT client app on my mobile it is working.当我从 Raspberry PI 发布时,它工作正常,即使当我连接 PI 时,我的移动设备上的 MQTT 客户端应用程序也能正常工作。 But there is no reaction on ESP8266 when I publish from AWS, but the PI as able to receive the message.但是当我从 AWS 发布时,ESP8266 没有反应,但是 PI 能够接收到消息。

Your issue should be related retained flag of the message.您的问题应该与消息的保留标志相关。 Publishers can instruct the broker to deliver the last sent message to all the new subscribers.发布者可以指示代理将最后发送的消息传递给所有新订阅者。 This is done by setting the retained flag to true.这是通过将保留标志设置为真来完成的。 When the broker gets a retained message, it knows that the message has to be pushed to new subscribers.当代理收到保留的消息时,它知道必须将消息推送给新订阅者。 This feature is very useful for bringing the new subscribers up to speed with the same state as other subscribers, otherwise after message is pubblished, only the client already connected as subcribed can receive it (RasPi) and not the new subscribers (NodeMCU).此功能对于使新订阅者与其他订阅者保持相同状态的速度非常有用,否则在发布消息后,只有已连接为订阅者的客户端才能接收它(RasPi),而不能接收新订阅者(NodeMCU)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM