0
\$\begingroup\$

I have just started studying about IoT a few days ago, and now I'm trying to work with the wifi module ESP8266. I want to do something like this: I send a cmd from Android device to a server, which have some php code to handle my GET or POST data. Then, it will send some data, like json or something, to the ESP8266, and to a micro controller like AVR via UART to handle the changes. And sometime the MCU can send some data to server, and server will noti the android (a reverse process). I have understood how to send data from wifi module to an URL with Get and Post method (not fully, but maybe enough). I just dont understand how to send message from server to the module! Does the module need to send request to server and get the respone again and again in a loop?! I am a newbie so please give me a clear and answer! Thanks and sorry for bad English =)

\$\endgroup\$
  • 1
    \$\begingroup\$ The MQTT protocol is much better suited for your use case than HTTP. There are lots of tutorials on the net on how to connect an ESP8266 with a android phone using MQTT. \$\endgroup\$ – wailashi Jun 19 '16 at 9:33
  • \$\begingroup\$ First time heard about MQTT! I will try out! Thanks :D \$\endgroup\$ – Lông Nguyễn Jun 19 '16 at 13:32
2
\$\begingroup\$

In general servers do not push data to devices for several reasons. The most obvious reason is that the devices are behind routers which effectively hide them from the Internet.

Does the module need to send request to server and get the respone again and again in a loop?

Yes, that is the usual method. The device just needs regular Internet access and routers are usually configured to allow outbound HTTP traffic.


As this isn't an electrical design question it will probably be migrated to one of the other SE sites.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your answer :D I will try getting data with a loop. Not sure how much power it will take? \$\endgroup\$ – Lông Nguyễn Jun 19 '16 at 13:31
0
\$\begingroup\$

You could set up a MQTT broker (available both to the server and the ESP, so you would have figure out the networking and security).

The ESP would subscribe to a particular topic. On the server side you could use phpMQTT to connect to the broker and publish an event. The broker would then notify the ESP.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.